From 8cf10efe3b5a1bcc70bc6e5590ee63fd5eb00c5b Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Wed, 19 Jul 2023 11:57:59 +0100 Subject: Huge refactor to a more value based system, doing away with terminals. Also introduces unit testing --- main/parse.go | 54 +++--------------------------------------------------- 1 file changed, 3 insertions(+), 51 deletions(-) (limited to 'main/parse.go') 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!?!?") -- cgit v1.2.3