<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--subex/parse.go12
-rw-r--r--walk/walk.go21
2 files changed, 17 insertions, 16 deletions
diff --git a/subex/parse.go b/subex/parse.go
index 9e47e0b..b1d54ac 100644
--- a/subex/parse.go
+++ b/subex/parse.go
@@ -39,7 +39,7 @@ func parseTerminatorAtomLiteral(termType rune, l RuneReader) walk.Atom {
case '@':
return expectBracket(l, walk.ArrayBegin, walk.ArrayEnd)
case '~':
- return expectBracket(l, walk.StartString{}, walk.EndString{})
+ return expectBracket(l, walk.StringTerminal{}, walk.StringTerminal{})
case '#':
return expectBracket(l, walk.MapBegin, walk.MapEnd)
default:
@@ -193,6 +193,8 @@ func parseReplacement(l RuneReader) (output []OutputContent) {
for _, literal := range literals {
output = append(output, OutputAtomLiteral {literal})
}
+ case '"':
+ output = append(output, OutputAtomLiteral {walk.StringTerminal{}})
default:
output = append(output, OutputAtomLiteral{atom: walk.StringAtom(r)})
}
@@ -218,6 +220,9 @@ func parseRangeSubex(l RuneReader) map[walk.Atom]walk.Atom {
literals := parseNonStringLiteral(l)
froms = append(froms, literals...)
continue
+ } else if fromsStart == '"' {
+ froms = append(froms, walk.StringTerminal{})
+ continue
} else {
atom := parseTerminatorAtomLiteral(fromsStart, l)
if atom != nil {
@@ -252,6 +257,9 @@ func parseRangeSubex(l RuneReader) map[walk.Atom]walk.Atom {
literals := parseNonStringLiteral(l)
tos = append(tos, literals...)
continue
+ } else if tosStart == '"' {
+ tos = append(tos, walk.StringTerminal{})
+ continue
} else {
atom := parseTerminatorAtomLiteral(tosStart, l)
if atom != nil {
@@ -307,6 +315,8 @@ func parseSubex(l RuneReader, minPower int) SubexAST {
lhs = SubexASTOutput{replacement}
case '.':
lhs = SubexASTCopyAny{}
+ case '"':
+ lhs = SubexASTCopyAtom {walk.StringTerminal{}}
case '@', '#', '~':
lhs = SubexASTCopyAtom{atom: parseTerminatorAtomLiteral(r, l)}
case '`':
diff --git a/walk/walk.go b/walk/walk.go
index 72fbe11..5c1ca75 100644
--- a/walk/walk.go
+++ b/walk/walk.go
@@ -99,22 +99,19 @@ func (value ValueNumber) String() string {
}
func (value ValueNumber) atomness() {}
-type StartString struct {}
-func (value StartString) atomness() {}
-
-type EndString struct {}
-func (value EndString) atomness() {}
+type StringTerminal struct {}
+func (value StringTerminal) atomness() {}
type StringAtom rune
func (value StringAtom) atomness() {}
type ValueString string
func (value ValueString) Pieces(out chan<- Atom) {
- out<-StartString{}
+ out<-StringTerminal{}
for _, char := range value {
out<-StringAtom(char)
}
- out<-EndString{}
+ out<-StringTerminal{}
}
func (value ValueString) String() string {
return fmt.Sprintf("\"%s\"", string(value))
@@ -456,7 +453,6 @@ type CompoundError int
const (
CompoundRuneOutsideString CompoundError = iota
- CompoundEndStringOutsideString
CompoundUnknownAtom
CompoundMissingEnd
CompoundInvalidStringAtom
@@ -466,8 +462,6 @@ func (err CompoundError) Error() string {
switch err {
case CompoundRuneOutsideString:
return "Compound Error: Rune Outside String"
- case CompoundEndStringOutsideString:
- return "Compound Error: End String Outside String"
case CompoundUnknownAtom:
return "Compound Error: Unknown Atom"
case CompoundMissingEnd:
@@ -508,10 +502,7 @@ func Compound(in <-chan Atom) <-chan CompoundResult {
case StringAtom:
out<-CompoundResult{nil, CompoundRuneOutsideString}
break outer
- case EndString:
- out<-CompoundResult{nil, CompoundEndStringOutsideString}
- break outer
- case StartString:
+ case StringTerminal:
default:
out<-CompoundResult{nil, CompoundUnknownAtom}
break outer
@@ -525,7 +516,7 @@ func Compound(in <-chan Atom) <-chan CompoundResult {
break outer
}
switch v := atom.(type) {
- case EndString:
+ case StringTerminal:
break loop
case StringAtom:
builder.WriteRune(rune(v))