mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
Merge remote-tracking branch 'remotes/origin/master' into issue40(EOF,EOL)
This commit is contained in:
commit
2350843d1d
@ -13,7 +13,7 @@
|
|||||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
|
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||||
<orderEntry type="library" name="unittest-libs" level="project" />
|
<orderEntry type="library" name="unittest-libs" level="project" />
|
||||||
|
@ -25,6 +25,11 @@ dependencies {
|
|||||||
implementation 'org.antlr:antlr4-runtime:4.9'
|
implementation 'org.antlr:antlr4-runtime:4.9'
|
||||||
implementation project(':parser')
|
implementation project(':parser')
|
||||||
|
|
||||||
|
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5"
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.2'
|
||||||
|
testImplementation 'org.hamcrest:hamcrest-junit:2.0.0.0'
|
||||||
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.2'
|
||||||
|
|
||||||
// antlr('org.antlr:antlr4:4.9') {
|
// antlr('org.antlr:antlr4:4.9') {
|
||||||
// exclude group: 'com.ibm.icu', module: 'icu4j'
|
// exclude group: 'com.ibm.icu', module: 'icu4j'
|
||||||
// }
|
// }
|
||||||
@ -62,6 +67,19 @@ sourceSets {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
// Enable JUnit 5 (Gradle 4.6+).
|
||||||
|
useJUnitPlatform()
|
||||||
|
|
||||||
|
// Always run tests, even when nothing changed.
|
||||||
|
dependsOn 'cleanTest'
|
||||||
|
|
||||||
|
// Show test results.
|
||||||
|
testLogging {
|
||||||
|
events "skipped", "failed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
task wrapper(type: Wrapper) {
|
task wrapper(type: Wrapper) {
|
||||||
gradleVersion = '6.7'
|
gradleVersion = '6.7'
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,13 @@
|
|||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" />
|
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||||
<orderEntry type="module" module-name="parser" />
|
<orderEntry type="module" module-name="parser" />
|
||||||
<orderEntry type="library" name="antlr-runtime-4.9" level="project" />
|
<orderEntry type="library" name="antlr-runtime-4.9" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="unittest-libs" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
72
compilerAst/test/TestAntlrParser.kt
Normal file
72
compilerAst/test/TestAntlrParser.kt
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package prog8tests
|
||||||
|
|
||||||
|
import org.antlr.v4.runtime.*
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import prog8.ast.IStringEncoding
|
||||||
|
import prog8.ast.antlr.toAst
|
||||||
|
import prog8.ast.statements.Block
|
||||||
|
import prog8.parser.*
|
||||||
|
import java.nio.file.Path
|
||||||
|
import kotlin.test.*
|
||||||
|
|
||||||
|
class TestAntlrParser {
|
||||||
|
|
||||||
|
class MyErrorListener: ConsoleErrorListener() {
|
||||||
|
override fun syntaxError(recognizer: Recognizer<*, *>?, offendingSymbol: Any?, line: Int, charPositionInLine: Int, msg: String, e: RecognitionException?) {
|
||||||
|
throw ParsingFailedError(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object TestStringEncoding: IStringEncoding {
|
||||||
|
override fun encodeString(str: String, altEncoding: Boolean): List<Short> {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun decodeString(bytes: List<Short>, altEncoding: Boolean): String {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testAntlrTree() {
|
||||||
|
// can create charstreams from many other sources as well;
|
||||||
|
val charstream = CharStreams.fromString("""
|
||||||
|
main {
|
||||||
|
sub start() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
val lexer = prog8Lexer(charstream)
|
||||||
|
val tokens = CommonTokenStream(lexer)
|
||||||
|
val parser = prog8Parser(tokens)
|
||||||
|
parser.errorHandler = BailErrorStrategy()
|
||||||
|
// parser.removeErrorListeners()
|
||||||
|
// parser.addErrorListener(MyErrorListener())
|
||||||
|
val nodes = parser.module()
|
||||||
|
val blockName = nodes.block(0).identifier().NAME().text
|
||||||
|
assertEquals(blockName, "main")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testProg8Ast() {
|
||||||
|
// can create charstreams from many other sources as well;
|
||||||
|
val charstream = CharStreams.fromString("""
|
||||||
|
main {
|
||||||
|
sub start() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
val lexer = prog8Lexer(charstream)
|
||||||
|
val tokens = CommonTokenStream(lexer)
|
||||||
|
val parser = prog8Parser(tokens)
|
||||||
|
parser.errorHandler = BailErrorStrategy()
|
||||||
|
// parser.removeErrorListeners()
|
||||||
|
// parser.addErrorListener(MyErrorListener())
|
||||||
|
|
||||||
|
val ast = parser.module().toAst("test", false, Path.of(""), TestStringEncoding)
|
||||||
|
assertIs<Block>(ast.statements.first())
|
||||||
|
assertEquals((ast.statements.first() as Block).name, "main")
|
||||||
|
}
|
||||||
|
}
|
@ -2,10 +2,10 @@
|
|||||||
<module type="JAVA_MODULE" version="4">
|
<module type="JAVA_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$/../dbusCompilerService">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/../dbusCompilerService/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
|
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||||
<orderEntry type="library" name="kotlinx-cli-jvm" level="project" />
|
<orderEntry type="library" name="kotlinx-cli-jvm" level="project" />
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
|
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||||
<orderEntry type="library" name="takes-http" level="project" />
|
<orderEntry type="library" name="takes-http" level="project" />
|
||||||
|
Loading…
Reference in New Issue
Block a user