<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/subexast.go
diff options
context:
space:
mode:
Diffstat (limited to 'subex/subexast.go')
-rw-r--r--subex/subexast.go27
1 files changed, 21 insertions, 6 deletions
diff --git a/subex/subexast.go b/subex/subexast.go
index 0afd3e3..c49f215 100644
--- a/subex/subexast.go
+++ b/subex/subexast.go
@@ -5,10 +5,12 @@ import (
"main/walk"
)
+// A node in the AST of a subex
type SubexAST interface {
compileWith(next SubexState) SubexState
}
+// Process the first subex, then the second, splitting the input text in two
type SubexASTConcat struct {
first, second SubexAST
}
@@ -19,6 +21,7 @@ func (ast SubexASTConcat) String() string {
return fmt.Sprintf("(%v)(%v)", ast.first, ast.second)
}
+// Processing a subex and storing the output in a slot instead of outputting it
type SubexASTStore struct {
match SubexAST
slot rune
@@ -34,6 +37,7 @@ func (ast SubexASTStore) String() string {
return fmt.Sprintf("$%c(%v)", ast.slot, ast.match)
}
+// Try to run the first subex, if it fails then backtrack and use the second
type SubexASTOr struct {
first, second SubexAST
}
@@ -44,6 +48,7 @@ func (ast SubexASTOr) compileWith(next SubexState) SubexState {
}
}
+// Run the content subex as many times as possible as the input is read in
type SubexASTMaximise struct {
content SubexAST
}
@@ -59,6 +64,7 @@ func (ast SubexASTMaximise) String() string {
return fmt.Sprintf("(%v)*", ast.content)
}
+// Run the content subex as few times as possible as the input is read in
type SubexASTMinimise struct {
content SubexAST
}
@@ -74,6 +80,7 @@ func (ast SubexASTMinimise) String() string {
return fmt.Sprintf("(%v)-", ast.content)
}
+// Run the subex as many times as possible but at least min times and at most max times
type SubexASTRepeat struct {
content SubexAST
min, max int
@@ -91,16 +98,18 @@ func (ast SubexASTRepeat) compileWith(next SubexState) SubexState {
return next
}
-type SubexASTCopyRune struct {
- datum walk.Datum
+// Read in a single specific Atom and output it unchanged
+type SubexASTCopyAtom struct {
+ atom walk.Atom
}
-func (ast SubexASTCopyRune) compileWith(next SubexState) SubexState {
- return &SubexCopyRuneState{
- rune: ast.datum,
+func (ast SubexASTCopyAtom) compileWith(next SubexState) SubexState {
+ return &SubexCopyAtomState{
+ atom: ast.atom,
next: next,
}
}
+// Read in any single Atom and output it unchanged
type SubexASTCopyAny struct {}
func (ast SubexASTCopyAny) compileWith(next SubexState) SubexState {
return &SubexCopyAnyState{next}
@@ -109,6 +118,7 @@ func (ast SubexASTCopyAny) String() string {
return "."
}
+// Output a series of Atoms without reading anything from input
type SubexASTOutput struct {
replacement []TransducerOutput
}
@@ -119,6 +129,7 @@ func (ast SubexASTOutput) compileWith(next SubexState) SubexState {
}
}
+// Try to use a subex but just skip over this if it doesn't match
type SubexASTTry struct {
content SubexAST
}
@@ -129,6 +140,7 @@ func (ast SubexASTTry) compileWith(next SubexState) SubexState {
}
}
+// Try to skip over this subex but use it should that not match
type SubexASTMaybe struct {
content SubexAST
}
@@ -139,6 +151,7 @@ func (ast SubexASTMaybe) compileWith(next SubexState) SubexState {
}
}
+// Read in a repeated subex separated by a delimiter. Greedy
type SubexASTJoin struct {
content, delimiter SubexAST
}
@@ -155,8 +168,10 @@ func (ast SubexASTJoin) compileWith(next SubexState) SubexState {
}
}
+// Run each input Atom through a map to produce an output Atom
+// Atoms not in the map cause this to not match
type SubexASTRange struct {
- parts map[walk.Datum]walk.Datum
+ parts map[walk.Atom]walk.Atom
}
func (ast SubexASTRange) compileWith(next SubexState) SubexState {
return &SubexRangeState {