lang: parser: Lexer should allow in keyword as a variable name

We move it downwards to allow this case. Whether we want to allow this
long-term or not is to be decided.
This commit is contained in:
James Shubin
2023-11-04 14:35:24 -04:00
parent 96093984e4
commit 233625db20
2 changed files with 21 additions and 5 deletions

View File

@@ -0,0 +1,16 @@
-- main.mcl --
import "fmt"
$map = 55
$fn = func($in) { # in is a special keyword
13
}
test fmt.printf("%d", $fn(0)) {}
func fn($in) { # in is a special keyword
42 + $map
}
test fmt.printf("%d", $fn(0)) {}
test fmt.printf("%d", fn(0)) {}
-- OUTPUT --
Vertex: test[13]
Vertex: test[97]

View File

@@ -139,11 +139,6 @@
lval.str = yylex.Text() lval.str = yylex.Text()
return NOT return NOT
} }
/in/ {
yylex.pos(lval) // our pos
lval.str = yylex.Text()
return IN
}
/\->/ { /\->/ {
yylex.pos(lval) // our pos yylex.pos(lval) // our pos
lval.str = yylex.Text() lval.str = yylex.Text()
@@ -306,6 +301,11 @@
lval.str = yylex.Text() lval.str = yylex.Text()
return IDENTIFIER return IDENTIFIER
} }
/in/ {
yylex.pos(lval) // our pos
lval.str = yylex.Text()
return IN
}
/[A-Z]([a-z0-9_]*[a-z0-9]+)?/ /[A-Z]([a-z0-9_]*[a-z0-9]+)?/
{ {
yylex.pos(lval) // our pos yylex.pos(lval) // our pos