<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-04-21 10:42:03 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-04-21 10:42:03 +0100
commita4015bc64d5174f62bc2d150c6a780b89c00a0cc (patch)
tree93d5901d3358e1070af7de90ee1c5d5669adaef1 /main
parenta55375e36b159448723807198cd2b2bbd4371c1f (diff)
downloadstred-go-a4015bc64d5174f62bc2d150c6a780b89c00a0cc.tar
Add a and A commands for global substitution
Diffstat (limited to 'main')
-rw-r--r--main/lex.go2
-rw-r--r--main/parse.go14
2 files changed, 12 insertions, 4 deletions
diff --git a/main/lex.go b/main/lex.go
index ecb0d3d..f28244d 100644
--- a/main/lex.go
+++ b/main/lex.go
@@ -179,7 +179,7 @@ func lexCommand(l *lexer) stateFunc {
case '}':
l.emit(TokenRBrace)
return lexCommand
- case 's', 'S', 'f', 'F', 'l', 'L':
+ case 's', 'S', 'f', 'F', 'l', 'L', 'a', 'A':
l.emit(TokenCommand)
return lexSubstitution
}
diff --git a/main/parse.go b/main/parse.go
index 0c534e8..d31687a 100644
--- a/main/parse.go
+++ b/main/parse.go
@@ -69,7 +69,7 @@ func (p *parser) parseBasicCommand(commandChar rune) Command {
return NextCommand{}
case 'N':
return AppendNextCommand{}
- case 's', 'S', 'f', 'F', 'l', 'L':
+ case 's', 'S', 'f', 'F', 'l', 'L', 'a', 'A':
ast := p.parseSubex()
switch commandChar {
case 'f':
@@ -110,6 +110,14 @@ func (p *parser) parseBasicCommand(commandChar rune) Command {
Match: ast,
},
}
+ case 'a', 'A':
+ ast = subex.SubexASTRepeat {
+ Acceptable: []subex.ConvexRange{{Start: -1, End: 0}},
+ Content: subex.SubexASTOr {
+ First: ast,
+ Second: subex.SubexASTCopyAny{},
+ },
+ }
}
subex := subex.CompileTransducer(ast)
var next Command
@@ -121,9 +129,9 @@ func (p *parser) parseBasicCommand(commandChar rune) Command {
next = p.parseCommand()
}
switch commandChar {
- case 's':
+ case 's', 'a':
return SubstituteValueCommand {subex, next}
- case 'S', 'f', 'F', 'l', 'L':
+ case 'S', 'f', 'F', 'l', 'L', 'A':
return SubstitutePathCommand {subex, next}
default:
panic("Unreachable!?!?")