diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-07-22 20:30:23 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-07-22 20:30:23 +0900 |
commit | 0baa69676ca83dbb4fe7241478a6ecf6c85418a9 (patch) | |
tree | f337b96c1d2c4742647b9e4570d34788014333d3 /spec/lexer.go | |
parent | Write a description file (diff) | |
download | cotia-0baa69676ca83dbb4fe7241478a6ecf6c85418a9.tar.gz cotia-0baa69676ca83dbb4fe7241478a6ecf6c85418a9.tar.xz |
Add literal pattern syntax and change tree structure syntax
- Literal patterns don't interpret the special characters of regular expressions.
In other words, 'abc|def' matches only `abc|def`, not `abc` or `def`.
- Change tree structure syntax from '(...) to #(...).
Diffstat (limited to 'spec/lexer.go')
-rw-r--r-- | spec/lexer.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/spec/lexer.go b/spec/lexer.go index 1f8805a..1f50a27 100644 --- a/spec/lexer.go +++ b/spec/lexer.go @@ -210,9 +210,25 @@ func (l *lexer) lexAndSkipWSs() (*token, error) { Row: l.row, } case "terminal_close": - return newTerminalPatternToken(b.String(), newPosition(l.row)), nil + pat := b.String() + if pat == "" { + return nil, &verr.SpecError{ + Cause: synErrEmptyPattern, + Row: l.row, + } + } + return newTerminalPatternToken(pat, newPosition(l.row)), nil + } + } + case "literal_pattern": + pat := strings.Trim(tok.Text(), "'") + if pat == "" { + return nil, &verr.SpecError{ + Cause: synErrEmptyPattern, + Row: l.row, } } + return newTerminalPatternToken(mlspec.EscapePattern(pat), newPosition(l.row)), nil case "colon": return newSymbolToken(tokenKindColon, newPosition(l.row)), nil case "or": |