mirror of
https://github.com/irmen/prog8.git
synced 2025-01-10 20:30:23 +00:00
allow "x not in array" as equivalent to "not x in array"
update antlr parsing lib
This commit is contained in:
parent
ded9ada9bc
commit
1860f66de5
10
.idea/libraries/antlr_antlr4.xml
generated
10
.idea/libraries/antlr_antlr4.xml
generated
@ -1,17 +1,17 @@
|
||||
<component name="libraryTable">
|
||||
<library name="antlr.antlr4" type="repository">
|
||||
<properties maven-id="org.antlr:antlr4:4.10.1">
|
||||
<properties maven-id="org.antlr:antlr4:4.11.1">
|
||||
<exclude>
|
||||
<dependency maven-id="com.ibm.icu:icu4j" />
|
||||
</exclude>
|
||||
</properties>
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr4/4.10.1/antlr4-4.10.1.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr4-runtime/4.10.1/antlr4-runtime-4.10.1.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr4/4.11.1/antlr4-4.11.1.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr4-runtime/4.11.1/antlr4-runtime-4.11.1.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr-runtime/3.5.3/antlr-runtime-3.5.3.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/antlr/ST4/4.3.3/ST4-4.3.3.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/antlr/ST4/4.3.4/ST4-4.3.4.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/abego/treelayout/org.abego.treelayout.core/1.0.3/org.abego.treelayout.core-1.0.3.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/javax.json/1.0.4/javax.json-1.0.4.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/glassfish/javax.json/1.1.4/javax.json-1.1.4.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
|
@ -34,7 +34,7 @@ dependencies {
|
||||
implementation project(':codeGenIntermediate')
|
||||
implementation project(':codeGenExperimental')
|
||||
implementation project(':virtualmachine')
|
||||
implementation 'org.antlr:antlr4-runtime:4.10.1'
|
||||
implementation 'org.antlr:antlr4-runtime:4.11.1'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||
// implementation "org.jetbrains.kotlin:kotlin-reflect"
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.4'
|
||||
|
@ -1 +1 @@
|
||||
8.8
|
||||
8.8.1
|
||||
|
@ -145,6 +145,11 @@ class AstPreprocessor(val program: Program,
|
||||
val containment = ContainmentCheck(expr.left, expr.right, expr.position)
|
||||
return listOf(IAstModification.ReplaceNode(expr, containment, parent))
|
||||
}
|
||||
if(expr.operator=="not in") {
|
||||
val containment = ContainmentCheck(expr.left, expr.right, expr.position)
|
||||
val notContainment = PrefixExpression("not", containment, expr.position)
|
||||
return listOf(IAstModification.ReplaceNode(expr, notContainment, parent))
|
||||
}
|
||||
return noModifications
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,9 @@ package prog8tests.ast
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
import io.kotest.matchers.types.instanceOf
|
||||
import prog8.ast.IFunctionCall
|
||||
import prog8.ast.expressions.BinaryExpression
|
||||
import prog8.ast.expressions.IdentifierReference
|
||||
import prog8.ast.expressions.StringLiteral
|
||||
import prog8.ast.expressions.*
|
||||
import prog8.ast.statements.Assignment
|
||||
import prog8.ast.statements.InlineAssembly
|
||||
import prog8.ast.statements.VarDecl
|
||||
@ -179,5 +178,28 @@ main {
|
||||
val stmts = result.program.entrypoint.statements
|
||||
stmts.size shouldBe 9
|
||||
}
|
||||
|
||||
test("alternative notation for negative containment check") {
|
||||
val src="""
|
||||
main {
|
||||
sub start() {
|
||||
ubyte[] array=[1,2,3]
|
||||
cx16.r0L = not (3 in array)
|
||||
cx16.r1L = 3 not in array
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), optimize=false, src, writeAssembly=false)!!
|
||||
val stmts = result.program.entrypoint.statements
|
||||
stmts.size shouldBe 3
|
||||
val value1 = (stmts[1] as Assignment).value as BinaryExpression
|
||||
val value2 = (stmts[2] as Assignment).value as BinaryExpression
|
||||
value1.operator shouldBe "=="
|
||||
value1.left shouldBe instanceOf<ContainmentCheck>()
|
||||
(value1.right as NumericLiteral).number shouldBe 0.0
|
||||
value2.operator shouldBe "=="
|
||||
value2.left shouldBe instanceOf<ContainmentCheck>()
|
||||
(value2.right as NumericLiteral).number shouldBe 0.0
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -24,7 +24,7 @@ compileTestKotlin {
|
||||
dependencies {
|
||||
implementation project(':codeCore')
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||
implementation 'org.antlr:antlr4-runtime:4.10.1'
|
||||
implementation 'org.antlr:antlr4-runtime:4.11.1'
|
||||
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.16"
|
||||
implementation project(':parser')
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ TODO
|
||||
|
||||
For next release
|
||||
^^^^^^^^^^^^^^^^
|
||||
- allow "xx not in array" and rewrite it into "not xx in array"
|
||||
- make sure bool value is always 0 or 1 (all casts should convert), then:
|
||||
- rewrite bool=bool^1 into bool=not bool
|
||||
- should solve: bool bb = not bb -> larger code than bool bb ^= 1
|
||||
|
@ -170,6 +170,7 @@ expression :
|
||||
| left = expression EOL? bop = ('==' | '!=') EOL? right = expression
|
||||
| rangefrom = expression rto = ('to'|'downto') rangeto = expression ('step' rangestep = expression)? // can't create separate rule due to mutual left-recursion
|
||||
| left = expression EOL? bop = 'in' EOL? right = expression
|
||||
| left = expression EOL? bop = 'not in' EOL? right = expression
|
||||
| prefix = 'not' expression
|
||||
| left = expression EOL? bop = 'and' EOL? right = expression
|
||||
| left = expression EOL? bop = 'or' EOL? right = expression
|
||||
|
@ -10,8 +10,8 @@ java {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
antlr 'org.antlr:antlr4:4.10.1'
|
||||
implementation 'org.antlr:antlr4-runtime:4.10.1'
|
||||
antlr 'org.antlr:antlr4:4.11.1'
|
||||
implementation 'org.antlr:antlr4-runtime:4.11.1'
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
|
Loading…
x
Reference in New Issue
Block a user