From b2d1d965dee8cc2c1e063067d53a3c8e28a46d6c Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sat, 24 Dec 2022 10:04:42 +0000 Subject: Adds the character range mapping syntax Ranges of characters can be mapped with [] For example, capitalisation of a letter: [a-z=A-Z] Caesar cipher shift of 1: [a-zA-Z=b-zaB-ZA] --- main/subexstate.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'main/subexstate.go') diff --git a/main/subexstate.go b/main/subexstate.go index 00b9e75..880be38 100644 --- a/main/subexstate.go +++ b/main/subexstate.go @@ -123,3 +123,23 @@ func (state SubexCopyAnyState) eat(store Store, char rune) []SubexBranch { func (state SubexCopyAnyState) accepting(store Store) []string { return nil } + +type SubexRangeState struct { + parts map[rune]rune + next SubexState +} +func (state SubexRangeState) eat(store Store, char rune) []SubexBranch { + out, exists := state.parts[char] + if !exists { + return nil + } else { + return []SubexBranch{{ + state: state.next, + output: string(out), + store: store, + }} + } +} +func (state SubexRangeState) accepting(store Store) []string { + return nil +} -- cgit v1.2.3