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.
|
||||
func stateStringValue(p *parsekit.P) {
|
||||
switch {
|
||||
case p.SkipMatching(doubleQuote3):
|
||||
case p.After(doubleQuote3).Ignore():
|
||||
p.RouteTo(stateMultiLineBasicString)
|
||||
case p.SkipMatching(doubleQuote):
|
||||
p.RouteTo(parseString).ThenTo(basicStringSpecifics)
|
||||
case p.After(doubleQuote).Ignore():
|
||||
p.RouteTo(startBasicString)
|
||||
default:
|
||||
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.
|
||||
//
|
||||
// \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.
|
||||
// * A double quote ends the string
|
||||
// * 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():
|
||||
p.EmitError("Invalid escape sequence")
|
||||
default:
|
||||
p.RouteTo(parseString).ThenTo(basicStringSpecifics)
|
||||
p.RouteTo(startBasicString)
|
||||
}
|
||||
}
|
||||
|
||||
func stateMultiLineBasicString(p *parsekit.P) {
|
||||
p.EmitError("Not yet implemented")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue