From dae74317d84471f6a859117fcbba1cf546be8ea1 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Wed, 19 Apr 2023 15:19:42 +0100 Subject: Adds parsing substitute commands, though executing them currently does nothing --- main/lex.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'main/lex.go') 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) { -- cgit v1.2.3