<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main/lex.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-04-19 15:19:42 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-04-19 15:19:42 +0100
commitdae74317d84471f6a859117fcbba1cf546be8ea1 (patch)
treedb8516ba8a5a208d16aaa0e6da439541dd496b94 /main/lex.go
parent10f847acc7087317b0fbe20b7cf3307a0fafab8a (diff)
downloadstred-go-dae74317d84471f6a859117fcbba1cf546be8ea1.tar
Adds parsing substitute commands, though executing them currently does nothing
Diffstat (limited to 'main/lex.go')
-rw-r--r--main/lex.go27
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) {