<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main/parse.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-04-19 16:54:53 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-04-19 16:54:53 +0100
commit8a9d6ef5970eea2a42ff9eb537f2a3f5e56aec2c (patch)
treea1bc5863695ecf49cadb133bbdce14a1259e22a6 /main/parse.go
parent1830133215449ebd32751aca7deb9b66663563bd (diff)
downloadstred-go-8a9d6ef5970eea2a42ff9eb537f2a3f5e56aec2c.tar
Upgrades the substitute command to also act as a filter
Substitute now captures the command after it and only runs it if the substitution is a success
Diffstat (limited to 'main/parse.go')
-rw-r--r--main/parse.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/main/parse.go b/main/parse.go
index bf2f0ac..aed87cc 100644
--- a/main/parse.go
+++ b/main/parse.go
@@ -234,7 +234,18 @@ func (p *parser) parseBasicCommand(commandChar rune) Command {
return AppendNextCommand{}
case 's':
subex := p.parseSubex()
- return SubstituteCommand {subex: subex}
+ var next Command
+ token := p.peek()
+ switch token.typ {
+ case TokenEOF, TokenRBrace:
+ next = NoopCommand{}
+ default:
+ next = p.parseCommand()
+ }
+ return SubstituteCommand {
+ subex: subex,
+ next: next,
+ }
case 'i':
items := p.parseLiterals()
return PrintLiteralsCommand {items: items}