Backup work.
This commit is contained in:
parent
6af770a918
commit
6a4a314fee
20
comment.go
20
comment.go
|
@ -5,17 +5,15 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// A '#' hash symbol marks the rest of the line as a comment.
|
// A '#' hash symbol marks the rest of the line as a comment.
|
||||||
func startComment(p *parsekit.P) {
|
|
||||||
p.Expects("start of comment")
|
|
||||||
p.On(c.OneOrMore(a.Hash)).Skip().RouteTo(commentContents)
|
|
||||||
}
|
|
||||||
|
|
||||||
// All characters up to the end of the line are included in the comment.
|
// All characters up to the end of the line are included in the comment.
|
||||||
func commentContents(p *parsekit.P) {
|
var comment = c.Sequence(
|
||||||
p.Expects("comment contents")
|
c.Drop(c.OneOrMore(a.Hash)),
|
||||||
switch {
|
c.Trim(c.ZeroOrMore(c.Not(a.EndOfLine)), " \t"),
|
||||||
case p.On(a.EndOfLine).Skip().RouteReturn().End():
|
c.Drop(a.EndOfLine))
|
||||||
p.EmitLiteralTrim(ItemComment)
|
|
||||||
case p.On(a.AnyRune).Accept().RouteRepeat().End():
|
func startComment(p *parsekit.P) {
|
||||||
|
p.Expects("comment")
|
||||||
|
if p.On(comment).Accept().RouteReturn().End() {
|
||||||
|
p.EmitLiteral(ItemComment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,6 @@ func TestComments(t *testing.T) {
|
||||||
{"comment with escape-y chars", `# \xxx/ \u can't escape/`, `#(\xxx/ \u can't escape/)`, ""},
|
{"comment with escape-y chars", `# \xxx/ \u can't escape/`, `#(\xxx/ \u can't escape/)`, ""},
|
||||||
{"comment with multiple hashes", `#### Just Jack!`, `#(Just Jack!)`, ""},
|
{"comment with multiple hashes", `#### Just Jack!`, `#(Just Jack!)`, ""},
|
||||||
{"comment with hashes inside", `# Follow #me2`, `#(Follow #me2)`, ""},
|
{"comment with hashes inside", `# Follow #me2`, `#(Follow #me2)`, ""},
|
||||||
{"carriage returns in comment", "# \tlexe\r accepts embedded ca\r\riage \returns\r", "#(lexe\r accepts embedded ca\r\riage \returns)", ""},
|
{"carriage returns in comment", "# \tlexe\r accepts embedded ca\r\riage \returns\r\n", "#(lexe\r accepts embedded ca\r\riage \returns)", ""},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ func runStatesT(t *testing.T, c statesT) {
|
||||||
}
|
}
|
||||||
actual := strings.Join(a, "")
|
actual := strings.Join(a, "")
|
||||||
if actual != expected {
|
if actual != expected {
|
||||||
t.Errorf("[%s] Unexpected parser output:\nexpected: %s\nactual: %s\n", c.name, expected, actual)
|
t.Errorf("[%s] Unexpected parser output:\nexpected: %q\nactual: %q\n", c.name, expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,8 @@ func TestErrorFullIncludesLineAndRowPosition(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidUtf8Data(t *testing.T) {
|
func TestInvalidUTF8Data(t *testing.T) {
|
||||||
runStatesTs(t, []statesT{
|
runStatesTs(t, []statesT{
|
||||||
{"inside comment", "# \xbc", "", "invalid UTF8 character in input (expected end of file)"},
|
|
||||||
{"bare key 1", "\xbc", "", "invalid UTF8 character in input (expected end of file)"},
|
{"bare key 1", "\xbc", "", "invalid UTF8 character in input (expected end of file)"},
|
||||||
{"bare key 2", "key\xbc", "[key]", "invalid UTF8 character in input (expected a value assignment)"},
|
{"bare key 2", "key\xbc", "[key]", "invalid UTF8 character in input (expected a value assignment)"},
|
||||||
{"start of value", "key=\xbc", "[key]=", "invalid UTF8 character in input (expected a value)"},
|
{"start of value", "key=\xbc", "[key]=", "invalid UTF8 character in input (expected a value)"},
|
||||||
|
@ -35,7 +34,7 @@ func TestWhiteSpaceAndNewlines(t *testing.T) {
|
||||||
{"space", " ", "", ""},
|
{"space", " ", "", ""},
|
||||||
{"tab", "\t", "", ""},
|
{"tab", "\t", "", ""},
|
||||||
{"newline", "\n", "", ""},
|
{"newline", "\n", "", ""},
|
||||||
{"carriage return", "\r", "", ""},
|
{"all whitespace and newlines", " \t \t \r\n\n \n \t", "", ""},
|
||||||
{"all whitespace and newlines", " \t \t \r\r\n\n \n \t", "", ""},
|
{"bare carriage return", "\r", "", "unexpected character '\\r' (expected end of file)"},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ var (
|
||||||
//
|
//
|
||||||
// \b - backspace (U+0008)
|
// \b - backspace (U+0008)
|
||||||
// \t - tab (U+0009)
|
// \t - tab (U+0009)
|
||||||
// \n - linefeed (U+000A)
|
// \n - LF (U+000A)
|
||||||
// \f - form feed (U+000C)
|
// \f - form feed (U+000C)
|
||||||
// \r - carriage return (U+000D)
|
// \r - carriage return (U+000D)
|
||||||
// \" - quote (U+0022)
|
// \" - quote (U+0022)
|
||||||
|
@ -28,9 +28,9 @@ var (
|
||||||
// \UXXXXXXXX - unicode (U+XXXXXXXX)
|
// \UXXXXXXXX - unicode (U+XXXXXXXX)
|
||||||
validEscapeChar = c.AnyOf(c.Runes('b', 't', 'n', 'f', 'r'), a.DoubleQuote, a.Backslash)
|
validEscapeChar = c.AnyOf(c.Runes('b', 't', 'n', 'f', 'r'), a.DoubleQuote, a.Backslash)
|
||||||
shortEscape = c.Sequence(a.Backslash, validEscapeChar)
|
shortEscape = c.Sequence(a.Backslash, validEscapeChar)
|
||||||
shortUtf8Escape = c.Sequence(a.Backslash, c.Rune('u'), c.Repeat(4, a.HexDigit))
|
shortUTF8Escape = c.Sequence(a.Backslash, c.Rune('u'), c.Repeat(4, a.HexDigit))
|
||||||
longUtf8Escape = c.Sequence(a.Backslash, c.Rune('U'), c.Repeat(8, a.HexDigit))
|
longUTF8Escape = c.Sequence(a.Backslash, c.Rune('U'), c.Repeat(8, a.HexDigit))
|
||||||
validEscape = c.AnyOf(shortEscape, shortUtf8Escape, longUtf8Escape)
|
validEscape = c.AnyOf(shortEscape, shortUTF8Escape, longUTF8Escape)
|
||||||
)
|
)
|
||||||
|
|
||||||
func startString(p *parsekit.P) {
|
func startString(p *parsekit.P) {
|
||||||
|
@ -67,11 +67,8 @@ func basicStringSpecifics(p *parsekit.P) {
|
||||||
p.Expects("string contents")
|
p.Expects("string contents")
|
||||||
switch {
|
switch {
|
||||||
case p.On(a.DoubleQuote).Skip().End():
|
case p.On(a.DoubleQuote).Skip().End():
|
||||||
if err := p.EmitInterpreted(ItemString); err != nil { // TODO testcase?
|
p.EmitInterpreted(ItemString)
|
||||||
p.EmitError("invalid data in string: %s", err)
|
p.RouteTo(startKeyValuePair)
|
||||||
} else {
|
|
||||||
p.RouteTo(startKeyValuePair)
|
|
||||||
}
|
|
||||||
case p.On(a.Backslash).End():
|
case p.On(a.Backslash).End():
|
||||||
p.EmitError("invalid escape sequence")
|
p.EmitError("invalid escape sequence")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue