From 658900fcae610caace83a112ac0ee865108ebc92 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sun, 7 Apr 2024 15:27:36 +0100 Subject: Change output subex internals to allow structures Also add substitute register syntactic sugar --- main/parse.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'main/parse.go') diff --git a/main/parse.go b/main/parse.go index 9c7a437..3e0e80b 100644 --- a/main/parse.go +++ b/main/parse.go @@ -76,17 +76,61 @@ func (p *parser) parseBasicCommand(commands []Command, commandChar rune) []Comma case 'o': return append(commands, NoopCommand{}) case 'x': - return append(commands, SwapXRegCommand{}) + delim := p.peek() + if delim.typ != TokenSubstituteDelimiter { + return append(commands, SwapXRegCommand{}) + } + ast := p.parseSubex() + subex := subex.CompileTransducer(ast) + return append(commands, SubstituteToXRegCommand {subex}, JumpCommand {len(commands) + 3}) case 'X': - return append(commands, AppendXRegCommand{}) + delim := p.peek() + if delim.typ != TokenSubstituteDelimiter { + return append(commands, AppendXRegCommand{}) + } + ast := p.parseSubex() + subex := subex.CompileTransducer(ast) + return append(commands, SubstituteAppendXRegCommand {subex}, JumpCommand {len(commands) + 3}) case 'y': - return append(commands, SwapYRegCommand{}) + delim := p.peek() + if delim.typ != TokenSubstituteDelimiter { + return append(commands, SwapYRegCommand{}) + } + ast := p.parseSubex() + subex := subex.CompileTransducer(ast) + return append(commands, SubstituteToYRegCommand {subex}, JumpCommand {len(commands) + 3}) case 'Y': - return append(commands, AppendYRegCommand{}) + delim := p.peek() + if delim.typ != TokenSubstituteDelimiter { + return append(commands, AppendYRegCommand{}) + } + ast := p.parseSubex() + subex := subex.CompileTransducer(ast) + return append(commands, SubstituteAppendYRegCommand {subex}, JumpCommand {len(commands) + 3}) case 'z': - return append(commands, SwapZRegCommand{}) + delim := p.peek() + if delim.typ != TokenSubstituteDelimiter { + return append(commands, SwapZRegCommand{}) + } + ast := p.parseSubex() + subex := subex.CompileTransducer(ast) + return append(commands, SubstituteToZRegCommand {subex}, JumpCommand {len(commands) + 3}) case 'Z': - return append(commands, AppendZRegCommand{}) + delim := p.peek() + if delim.typ != TokenSubstituteDelimiter { + return append(commands, AppendZRegCommand{}) + } + ast := p.parseSubex() + subex := subex.CompileTransducer(ast) + return append(commands, SubstituteAppendZRegCommand {subex}, JumpCommand {len(commands) + 3}) + case 'a': + return append(commands, IsStartCommand{}, JumpCommand {len(commands) + 3}) + case 'A': + return append(commands, IsPrevStartCommand{}, JumpCommand {len(commands) + 3}) + case 'e': + return append(commands, IsEndCommand{}, JumpCommand {len(commands) + 3}) + case 'E': + return append(commands, IsNextEndCommand{}, JumpCommand {len(commands) + 3}) case ':': labelToken := p.next() if labelToken.typ != TokenLabel { -- cgit v1.2.3