forked from purpleidea/mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lang: parser: Grab entire variable names during lexing
This is inelegant, but I stronly believe that allowing dollar signs and their variable name suffixes to both be first class citizens, is a bad idea. The dollar sign should initiate a token that is exempt from any other processing. Note that it would be possible to construct a regex similar to the one for IDENTIFIER, that only matches valid variable names. But it will be complex. It seems more maintainable to just consume all allowed characters, and then check validity with some simple golang in the parser actions. Fixes purpleidea#728
- Loading branch information
Showing
4 changed files
with
38 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
-- main.mcl -- | ||
import "fmt" | ||
# unfortunately, for now `in` is a reserved keyword, see: | ||
# https://github.com/purpleidea/mgmt/issues/728 | ||
$map = 55 | ||
$fn = func($in) { # in is a special keyword | ||
# in is a special keyword, but accepted in a variable name | ||
$fn = func($in) { | ||
13 | ||
} | ||
test fmt.printf("%d", $fn(0)) {} | ||
func fn($in) { # in is a special keyword | ||
func fn($in) { | ||
42 + $map | ||
} | ||
test fmt.printf("%d", $fn(0)) {} | ||
test fmt.printf("%d", fn(0)) {} | ||
-- OUTPUT -- | ||
# err: errLexParse: parser: `syntax error: unexpected IN, expecting MAP_IDENTIFIER or IDENTIFIER` @5:2 | ||
Vertex: test[13] | ||
Vertex: test[97] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters