diff options
Diffstat (limited to 'main/lex.go')
-rw-r--r-- | main/lex.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/main/lex.go b/main/lex.go index 0daf2d1..e82c309 100644 --- a/main/lex.go +++ b/main/lex.go @@ -147,6 +147,7 @@ const ( TokenNumberLiteral // A number literal TokenPatternStringIndex // A string index in a pattern TokenPatternIntegerIndex // An integer index in a pattern + TokenSubex // A subex ) type Token struct { @@ -269,6 +270,9 @@ func lexCommand(l *lexer) stateFunc { case 'i': l.emit(TokenCommand) return lexMultipleLiterals + case 's': + l.emit(TokenCommand) + return lexSubstitution case 'S': l.emit(TokenCommand) return lexBigSubstitution @@ -280,6 +284,29 @@ func lexCommand(l *lexer) stateFunc { return l.errorf("Expected command found something else") } +func lexSubstitution(l *lexer) stateFunc { + delimiter := l.next() + if delimiter == eof { + return l.errorf("Missing subex in substitution command") + } + l.emit(TokenSubstituteDelimiter) + loop: for { + r := l.next() + switch r { + case delimiter: + l.backup() + l.emit(TokenSubex) + l.next() + l.emit(TokenSubstituteDelimiter) + break loop + case eof: + return l.errorf("Missing closing substitution delimiter") + default: + } + } + return lexCommand +} + func lexBigSubstitution(l *lexer) stateFunc { delimiter := l.next() if delimiter == eof || isAlphaNumeric(delimiter) { |