Slightly improved routing handling to prevent repeition in code for string parsing.
This commit is contained in:
parent
4556520582
commit
e2e4fbd901
|
@ -8,19 +8,15 @@ import "github.com/mmakaay/toml/parsekit"
|
||||||
// * Basic strings are surrounded by quotation marks.
|
// * Basic strings are surrounded by quotation marks.
|
||||||
func stateStringValue(p *parsekit.P) {
|
func stateStringValue(p *parsekit.P) {
|
||||||
switch {
|
switch {
|
||||||
case p.SkipMatching(doubleQuote3):
|
case p.After(doubleQuote3).Ignore():
|
||||||
p.RouteTo(stateMultiLineBasicString)
|
p.RouteTo(stateMultiLineBasicString)
|
||||||
case p.SkipMatching(doubleQuote):
|
case p.After(doubleQuote).Ignore():
|
||||||
p.RouteTo(parseString).ThenTo(basicStringSpecifics)
|
p.RouteTo(startBasicString)
|
||||||
default:
|
default:
|
||||||
p.UnexpectedInput("a string value")
|
p.UnexpectedInput("a string value")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func stateMultiLineBasicString(p *parsekit.P) {
|
|
||||||
p.EmitError("Not yet implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
// For convenience, some popular characters have a compact escape sequence.
|
// For convenience, some popular characters have a compact escape sequence.
|
||||||
//
|
//
|
||||||
// \b - backspace (U+0008)
|
// \b - backspace (U+0008)
|
||||||
|
@ -54,6 +50,10 @@ func parseString(p *parsekit.P) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func startBasicString(p *parsekit.P) {
|
||||||
|
p.RouteTo(parseString).ThenTo(basicStringSpecifics)
|
||||||
|
}
|
||||||
|
|
||||||
// Specific handling of input for basic strings.
|
// Specific handling of input for basic strings.
|
||||||
// * A double quote ends the string
|
// * A double quote ends the string
|
||||||
// * No additional \escape sequences are allowed. What the spec say about this:
|
// * No additional \escape sequences are allowed. What the spec say about this:
|
||||||
|
@ -70,6 +70,10 @@ func basicStringSpecifics(p *parsekit.P) {
|
||||||
case p.After(backslash).Backup():
|
case p.After(backslash).Backup():
|
||||||
p.EmitError("Invalid escape sequence")
|
p.EmitError("Invalid escape sequence")
|
||||||
default:
|
default:
|
||||||
p.RouteTo(parseString).ThenTo(basicStringSpecifics)
|
p.RouteTo(startBasicString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stateMultiLineBasicString(p *parsekit.P) {
|
||||||
|
p.EmitError("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue