From a769f496ecba60a73d74c445f5894ce52be800ee Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Sat, 28 Aug 2021 00:18:19 +0900 Subject: Add an #alias directive to define a user-friendly name of a terminal --- spec/lexer.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'spec/lexer.go') diff --git a/spec/lexer.go b/spec/lexer.go index 258faae..d513d7d 100644 --- a/spec/lexer.go +++ b/spec/lexer.go @@ -21,11 +21,12 @@ const ( tokenKindKWFragment = tokenKind("fragment") tokenKindID = tokenKind("id") tokenKindTerminalPattern = tokenKind("terminal pattern") + tokenKindStringLiteral = tokenKind("string") tokenKindColon = tokenKind(":") tokenKindOr = tokenKind("|") tokenKindSemicolon = tokenKind(";") tokenKindDirectiveMarker = tokenKind("#") - tokenKindTreeNodeOpen = tokenKind("'(") + tokenKindTreeNodeOpen = tokenKind("#(") tokenKindTreeNodeClose = tokenKind(")") tokenKindPosition = tokenKind("$") tokenKindExpantion = tokenKind("...") @@ -77,6 +78,14 @@ func newTerminalPatternToken(text string, pos Position) *token { } } +func newStringLiteralToken(text string, pos Position) *token { + return &token{ + kind: tokenKindStringLiteral, + text: text, + pos: pos, + } +} + func newPositionToken(num int, pos Position) *token { return &token{ kind: tokenKindPosition, @@ -234,7 +243,7 @@ func (l *lexer) lexAndSkipWSs() (*token, error) { Col: tok.Col + 1, } } - return newTerminalPatternToken(mlspec.EscapePattern(pat), newPosition(tok.Row+1, tok.Col+1)), nil + return newStringLiteralToken(pat, newPosition(tok.Row+1, tok.Col+1)), nil case "colon": return newSymbolToken(tokenKindColon, newPosition(tok.Row+1, tok.Col+1)), nil case "or": -- cgit v1.2.3