lang: Allow matching underscores in some of the identifier's

This allows matching underscores in some of the identifier's, but not
when they're the last character.

This caused me to suffer a bit of pain tracking down a bug which turned
out to be in the lexer. It started with a failing test that I wrote in:

974c2498c4

and which followed with a fix in:

52682f463a

Glad that's fixed!
This commit is contained in:
James Shubin
2018-09-22 10:37:29 -04:00
parent a26620da38
commit 57ce3fa587
4 changed files with 135 additions and 26 deletions

View File

@@ -241,6 +241,34 @@ func TestLexParse0(t *testing.T) {
//exp: ???, // FIXME: add the expected AST
})
}
{
values = append(values, test{
name: "maps 1",
code: `
# make sure the "str:" part doesn't match a single ident
$strmap map{str: int} = {
"key1" => 42,
"key2" => -13,
}
`,
fail: false,
//exp: ???, // FIXME: add the expected AST
})
}
{
values = append(values, test{
name: "maps 2",
code: `
$mapstrintlist map{str: []int} = {
"key1" => [42, 44,],
"key2" => [],
"key3" => [-13,],
}
`,
fail: false,
//exp: ???, // FIXME: add the expected AST
})
}
{
values = append(values, test{
name: "maps and lists",
@@ -1268,6 +1296,52 @@ func TestLexParse0(t *testing.T) {
fail: true,
})
}
{
exp := &StmtProg{
Prog: []interfaces.Stmt{
&StmtClass{
Name: "x",
Args: []*Arg{},
Body: &StmtProg{
Prog: []interfaces.Stmt{},
},
},
&StmtClass{
Name: "y1",
Args: []*Arg{},
Body: &StmtProg{
Prog: []interfaces.Stmt{},
},
},
&StmtInclude{
Name: "z",
Args: nil,
},
},
}
values = append(values, test{
name: "simple class with args 0",
code: `
class x() {
}
class y1() {
}
include z
`,
fail: false,
exp: exp,
})
}
{
values = append(values, test{
name: "simple class underscore failure",
code: `
class x_() {
}
`,
fail: true,
})
}
{
exp := &StmtProg{
Prog: []interfaces.Stmt{