Skip to content

Commit

Permalink
Allow :_ as variable-name #69
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaumgarten committed Aug 4, 2021
1 parent 6eaaf4c commit dcf505c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/parser/ast/tokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var keywordRegex1 = regexp.MustCompile(`(?i)^(and|or|not|abs|sqrt|sin|cos|tan|as
var keywordRegex2 = regexp.MustCompile(`(?i)^(if|then|else|end|goto)`)
var keywordRegexes = []*regexp.Regexp{keywordRegex1, keywordRegex2}

var identifierRegex = regexp.MustCompile("^:?[a-zA-Z]+[a-zA-Z0-9_]*")
var identifierRegex = regexp.MustCompile("^:[a-zA-Z0-9_]+|^[a-zA-Z]+[a-zA-Z0-9_]*")

var numberRegex = regexp.MustCompile("^[0-9]+(\\.[0-9]+)?")

Expand Down
6 changes: 6 additions & 0 deletions pkg/parser/ast/tokenizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestTokenizer(t *testing.T) {
// comment 2
:var = "another\"test"
:foo = (1+2.75)*3
:_=1
`

expected := `Line: 1, Coloumn: 1, Type: Newline
Expand Down Expand Up @@ -116,6 +117,11 @@ func TestTokenizer(t *testing.T) {
Line: 10, Coloumn: 18, Type: Number, Value: '3'
Line: 10, Coloumn: 19, Type: Newline
Line: 11, Coloumn: 1, Type: Whitespace, Value: ' '
Line: 11, Coloumn: 2, Type: ID, Value: ':_'
Line: 11, Coloumn: 4, Type: Symbol, Value: '='
Line: 11, Coloumn: 5, Type: Number, Value: '1'
Line: 11, Coloumn: 6, Type: Newline
Line: 12, Coloumn: 1, Type: Whitespace, Value: ' '
`

tk := ast.NewTokenizer()
Expand Down

0 comments on commit dcf505c

Please sign in to comment.