Skip to content

Commit

Permalink
download JAR if not present
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed May 8, 2023
1 parent 45d71c1 commit 3f91cc2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 56 deletions.
11 changes: 10 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import de.undercouch.gradle.tasks.download.Download

plugins {
kotlin("jvm") version "1.8.21"
id("com.github.ben-manes.versions") version "0.46.0"
Expand Down Expand Up @@ -160,7 +162,6 @@ dependencies {
implementation("org.antlr:antlr4:4.12.0")

implementation("org.jetbrains.kotlin:kotlin-compiler:1.8.21")
// Download JAR from: https://github.com/Kotlin/grammar-tools/releases/download/v0.1-43/kotlin-grammar-tools-0.1-43.jar
implementation(files("libs/kotlin-grammar-tools-0.1-43.jar"))
}

Expand Down Expand Up @@ -219,6 +220,7 @@ tasks {

compileKotlin {
kotlinOptions.jvmTarget = "17"
dependsOn("downloadKotlinGrammarTools")
}

shadowJar {
Expand All @@ -230,4 +232,11 @@ tasks {
isZip64 = true
archiveFileName = "${project.name}-fat-${project.version}.jar"
}

register<Download>("downloadKotlinGrammarTools") {
val version = "0.1-43"
src("https://github.com/Kotlin/grammar-tools/releases/download/v$version/kotlin-grammar-tools-$version.jar")
dest("$rootDir/libs/kotlin-grammar-tools-$version.jar")
overwrite(false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.io.File

fun main() {
"""StringUtils.splitByCharacterTypeCamelCase(token).joinToString(" ") { old ->""".trimIndent()
.lexAsKotlin().joinToString(" ").let { println(it) }
.lexAsKotlin().joinToString(" ").let { println(it) }
"""listOf(getDirectHyponyms(sense), getDirectHypernyms(sense))) &&&"""
.lexAsKotlin().joinToString(" ").let { println(it) }
// fetchKotlinExamples()
Expand All @@ -26,65 +26,39 @@ fun fetchKotlinExamples() =
.filter { it.isValidKotlin() }
.map { it.coarsenAsKotlin() }.toList()
.filter { str -> dropKeywords.none { it in str } && str.split(" ").size in 10..40 }
.distinct()
.forEach { println(it) }
.distinct().forEach { println(it) }

val kotlinCFG = """
START -> statement
S -> DECLARATION | EXPRESSION
statement -> declaration
statement -> expression
statement -> control_flow
statement -> function_call
statement -> assignment
statement -> return_statement
DECLARATION -> VAL_DECLARATION | FUN_DECLARATION
declaration -> val_declaration | var_declaration | function_declaration
VAL_DECLARATION -> val ID = EXPRESSION
FUN_DECLARATION -> fun GENERIC? ID . ID () TYPE? = EXPRESSION
val_declaration -> val w : type | val w : type = expression | val w = expression
var_declaration -> var w : type | var w : type = expression | var w = expression
TYPE -> : ID < * >
type -> basic_type | nullable_type
basic_type -> Int | Float | Double | String | Boolean | Char | Long | Short | Any | Unit
nullable_type -> basic_type ?
GENERIC -> < ID >
function_declaration -> fun w ( parameters ) : type = expression
parameters -> parameter | parameter , parameters
parameter -> w : type
EXPRESSION -> ATOMIC_EXPRESSION | COMPLEX_EXPRESSION | BRACKETED_EXPRESSION | BLOCK_EXPRESSION
expression -> binary_expr | unary_expr | paren_expr | w | literal | lambda_expr
binary_expr -> expression binary_op expression
binary_op -> + | - | * | / | % | && | || | == | != | > | < | >= | <= | ?: | . | ?. | ?:? | .? | ..
unary_expr -> unary_op expression
unary_op -> ! | -
ATOMIC_EXPRESSION -> ID | ID . ID | ID . ID ()
paren_expr -> ( expression )
COMPLEX_EXPRESSION -> ATOMIC_EXPRESSION OPERATOR ATOMIC_EXPRESSION | ATOMIC_EXPRESSION OPERATOR EXPRESSION
literal -> int_literal | float_literal | double_literal | string_literal | boolean_literal | char_literal
int_literal -> int
float_literal -> float
double_literal -> double
string_literal -> string
boolean_literal -> true | false
char_literal -> char
BRACKETED_EXPRESSION -> ( EXPRESSION ) | [ EXPRESSION ] | ID ( ARGUMENTS? ) | ID < ARGUMENTS > ( )
lambda_expr -> { lambda_parameters -> lambda_body }
lambda_parameters -> w | w , lambda_parameters
lambda_body -> expression
BLOCK_EXPRESSION -> { CONTENTS }
control_flow -> if_expr | when_expr
if_expr -> if paren_expr expression | if paren_expr expression else expression
when_expr -> when paren_expr { when_cases }
when_cases -> when_case | when_case when_cases
when_case -> expression -> expression | else -> expression
CONTENTS -> CONTENTS CONTENT | CONTENT
CONTENT -> EXPRESSION | ID -> EXPRESSION
function_call -> w ( function_args )
function_args -> expression | expression , function_args
ARGUMENTS -> ARGUMENTS , ARGUMENT | ARGUMENT
ARGUMENT -> ID | EXPRESSION
assignment -> w assignment_op expression
assignment_op -> = | += | -= | *= | /= | %=
OPERATOR -> + | - | * | / | ..
return_statement -> return expression
ID -> w | it
""".trimIndent().parseCFG()

val dropKeywords = setOf("import", "package", "//", "\"", "data", "_")
Expand Down Expand Up @@ -218,7 +192,6 @@ val coarsenedKotlinLines = """
val w : w < w . w > = w ( )
val w = w . w ( ) - w
override fun w ( ) : w = w * w . w + if ( w ) w else w
val w = w < w && w ! ! [ w ] == '-'
val w = w ! ! . w ( w , w ) . w ( )
val w : w < w > = w ( )
var w : w < w > = w ( )
Expand Down Expand Up @@ -458,7 +431,6 @@ val coarsenedKotlinLines = """
fun < w , w , w : w < w > , w : w > w ( w : ( w ) -> w , w : w ) : w = w ( )
val w = w ( w [ w ] . w ( ) )
private fun w ( w : w ) = w [ w ] ? : w
val w = w ( '|' , '*' , '^' )
inline fun < w > w < w > . w ( w : w ) = w ( w ) w
inline fun < w > w < w > . w ( ) = w ( ) ! ! w
fun < w > w < w > . w ( ) : w = this [ w ] ! !
Expand Down Expand Up @@ -505,7 +477,6 @@ val coarsenedKotlinLines = """
val w = w [ w ] [ w ]
val w = w + w * ( w + w * w ) + w * w
val w = w + w * ( ( w - w ) + w * w ) + w * w + w
val w = ( w ( w , w ) + w ( w , w ) + w ( w , w ) + '+' + '/' ) . w ( )
var w = this [ w ] . w ( ) w w w w w w
var w by w ( ) ; var w by w ( ) ; var w by w ( ) ; var w by w ( )
operator fun w . w ( w : w ) = w ( this , w ) { w , w -> w + w }
Expand Down Expand Up @@ -636,7 +607,6 @@ val coarsenedKotlinLines = """
fun w . w ( w : w , w : w ) : w = w ( w , w , w )
fun w . w ( ) : w = w in this
fun w . w ( w : w ) = w ( ) || w ( w )
fun w . w ( ) = w ( ) == '<' && w ( ) == '>'
fun w . w ( w : w ) : w = w ( ) && w ( w ) . w ( w ) in w . w
fun w . w ( w : w ) : w = w . w . w { w ( it ) } . w { it }
val w . w : w < w > by w { w { it . w ( ) } . w ( w ) }
Expand Down Expand Up @@ -880,24 +850,18 @@ val coarsenedKotlinLines = """
val ( w , w ) = w . w { ( w , w ) -> w . w w w . w }
val ( w , w ) = w . w . w w w . w . w
val w = it . w ( ) . w ( )
val w = w ( '(' , '{' , '[' )
val w = w ( ')' , '}' , ']' )
fun w . w ( ) : w = w ( ) . w
fun w ( w : w ) = w ( w ) . w ( )
val w = w . w { it . w . w ( ) } + w
fun w . w ( w : w ) = w ( w + w - w ( ) - w , ' ' )
val w = ( w . w ( ) + w . w ( ) ) . w { w , w -> w w w } . w ( )
val w : w < w > = w . w { w : w -> w ( w , w ) }
fun w . w ( ) = w ( ) . w { w -> w { it / w } . w ( ) }
val w = w . w * w . w
val ( w , w ) = w ( w ( w , w ) , w ( w , w ) )
val w = w . w ( w ( ) ) . w { w . w ( it ) }
val w = w ( w ( w ) )
fun w . w ( ) = w ( ) . w ( '.' )
fun w . w ( ) = w ( ) . w ( '/' )
fun w . w ( w : w ) : w = w ( w ) . w . w ( w )
fun w ( w : w ) = w ( w ) . w ( w )
fun w ( ) = w ( ) . w ( ':' )
fun w . w ( w : w , w : w = w ) = w ( w ( w ) , w )
val w = w . w { it . w } . w ( w . w { it . w } . w ( ) )
val w = w ( w ( w ) , w )
Expand Down

0 comments on commit 3f91cc2

Please sign in to comment.