<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main/parse.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-07-19 11:57:59 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-07-19 11:57:59 +0100
commit8cf10efe3b5a1bcc70bc6e5590ee63fd5eb00c5b (patch)
tree7a16883c17c2bdcc49b2f9d4f333dfc76c66248f /main/parse.go
parent3c34366bdd5d817a184d6b1c901d03a16b6faa4b (diff)
downloadstred-go-8cf10efe3b5a1bcc70bc6e5590ee63fd5eb00c5b.tar
Huge refactor to a more value based system, doing away with terminals. Also introduces unit testing
Diffstat (limited to 'main/parse.go')
-rw-r--r--main/parse.go54
1 files changed, 3 insertions, 51 deletions
diff --git a/main/parse.go b/main/parse.go
index cbbfb9a..141ae7e 100644
--- a/main/parse.go
+++ b/main/parse.go
@@ -71,61 +71,13 @@ func (p *parser) parseBasicCommand(commands []Command, commandChar rune) []Comma
return append(commands, NextCommand{})
case 'N':
return append(commands, AppendNextCommand{})
- case 's', 'S', 'f', 'F', 'l', 'L', 'a', 'A':
+ case 's', 'S':
ast := p.parseSubex()
- switch commandChar {
- case 'f':
- ast = subex.SubexASTConcat {
- First: ast,
- Second: subex.SubexASTRepeat {
- Content: subex.SubexASTCopyAny{},
- Acceptable: []subex.ConvexRange{{Start: -1, End: 0}},
- },
- }
- case 'F':
- ast = subex.SubexASTConcat {
- First: subex.SubexASTStore {
- Slot: '_',
- Match: ast,
- },
- Second: subex.SubexASTRepeat {
- Content: subex.SubexASTCopyAny{},
- Acceptable: []subex.ConvexRange{{Start: -1, End: 0}},
- },
- }
- case 'l':
- ast = subex.SubexASTConcat {
- First: subex.SubexASTRepeat {
- Content: subex.SubexASTCopyAny{},
- Acceptable: []subex.ConvexRange{{Start: 0, End: -1}},
- },
- Second: ast,
- }
- case 'L':
- ast = subex.SubexASTConcat {
- First: subex.SubexASTRepeat {
- Content: subex.SubexASTCopyAny{},
- Acceptable: []subex.ConvexRange{{Start: 0, End: -1}},
- },
- Second: subex.SubexASTStore {
- Slot: '_',
- 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)
switch commandChar {
- case 's', 'a':
+ case 's':
return append(commands, SubstituteValueCommand {subex}, JumpCommand {len(commands) + 3})
- case 'S', 'f', 'F', 'l', 'L', 'A':
+ case 'S':
return append(commands, SubstitutePathCommand {subex}, JumpCommand {len(commands) + 3})
default:
panic("Unreachable!?!?")