[muscript] Enhance string lexing
This commit is contained in:
parent
340e93d6d4
commit
4f6c87b525
|
@ -39,7 +39,7 @@ public class Lexer {
|
|||
else if (isAlpha(c)) identifier();
|
||||
else {
|
||||
switch (c) {
|
||||
case '\'', '"' -> string();
|
||||
case '\'', '"' -> string(c);
|
||||
|
||||
case '=' -> {if (match('=')) createToken(Token.EqualEqual); else unexpected();}
|
||||
case '!' -> createToken(match('=') ? Token.BangEqual : Token.Bang);
|
||||
|
@ -70,8 +70,8 @@ public class Lexer {
|
|||
}
|
||||
}
|
||||
|
||||
private void string() {
|
||||
while (!isAtEnd() && peek() != '"' && peek() != '\'') {
|
||||
private void string(char stringChar) {
|
||||
while (!isAtEnd() && peek() != stringChar) {
|
||||
if (peek() == '\n') line++;
|
||||
advance();
|
||||
}
|
||||
|
|
|
@ -12,5 +12,7 @@ public class CallableTest {
|
|||
assertEquals(18, number("object.subfunc(0, object.subfunc(1, 2, 3), 4)"));
|
||||
assertTrue(bool("repeatArgs().repeatArgs().boolean"));
|
||||
assertEquals(32, number("function(object.subfunc(0, 1), 5)"));
|
||||
assertEquals("<=1.16.5\"", string("object2.stringfunc('<=1.16.5\"')"));
|
||||
assertEquals("minecraft", string("object2.stringfunc('minecraft', '<=1.16.5')"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,8 @@ public class MuTestUtil {
|
|||
"valuename", of("subvalue"),
|
||||
"sub", of(Map.of(
|
||||
"val", of(10)
|
||||
))
|
||||
)),
|
||||
"stringfunc", of(v -> of(v.get(0).asString().getValue()))
|
||||
)),
|
||||
"list", of(of(true), of(2), of("3")),
|
||||
"function", of(v -> of(Math.pow(v.get(0).asNumber().getValue(), v.get(1).asNumber().getValue()))),
|
||||
|
|
Loading…
Reference in New Issue