Fix bug for unquoted keyword as true/false with comment
diff --git a/encoding/json5/scanner.go b/encoding/json5/scanner.go
index 1991fcf..1e445a9 100644
--- a/encoding/json5/scanner.go
+++ b/encoding/json5/scanner.go
@@ -244,6 +244,52 @@
return s.error(c, "looking for beginning of value")
}
+func stateBeginValueFromComment(s *scanner, c int) int {
+ if c <= ' ' && isSpace(rune(c)) {
+ return scanSkipSpace
+ }
+ if isIdentifier(c) {
+ s.step = stateInStringKey
+ return scanBeginLiteral
+ }
+ switch c {
+ case '{':
+ s.step = stateBeginStringOrEmpty
+ s.pushParseState(parseObjectKey)
+ return scanBeginObject
+ case '[':
+ s.step = stateBeginValueOrEmpty
+ s.pushParseState(parseArrayValue)
+ return scanBeginArray
+ case '"':
+ s.step = stateInString
+ return scanBeginLiteral
+ case '-':
+ s.step = stateNeg
+ return scanBeginLiteral
+ case '0': // beginning of 0.123
+ s.step = state0
+ return scanBeginLiteral
+ case 't': // beginning of true
+ s.step = stateT
+ return scanBeginLiteral
+ case 'f': // beginning of false
+ s.step = stateF
+ return scanBeginLiteral
+ case 'n': // beginning of null
+ s.step = stateN
+ return scanBeginLiteral
+ case '/': // beginning of comment
+ s.step = stateInlineComment
+ return scanSkipInComment
+ }
+ if '1' <= c && c <= '9' { // beginning of 1234.5
+ s.step = state1
+ return scanBeginLiteral
+ }
+ return s.error(c, "looking for beginning of value")
+}
+
// stateBeginStringOrEmpty is the state after reading `{`.
func stateBeginStringOrEmpty(s *scanner, c int) int {
if c <= ' ' && isSpace(rune(c)) {
@@ -634,7 +680,7 @@
// stateSkipComment is the state after reading `//`
func stateSkipComment(s *scanner, c int) int {
if c == '\n' {
- s.step = stateBeginValue
+ s.step = stateBeginValueFromComment
return scanSkipInComment
}
s.step = stateSkipComment
diff --git a/example.json5 b/example.json5
index 54c0f2c..67c4438 100644
--- a/example.json5
+++ b/example.json5
@@ -3,6 +3,7 @@
{
key : "Key does not need double quote",
// json specific
- "of" : "course we can use json as json5",
+ "of" : "course we can use json as j // son5",
+ // json specific
trailing : "trailing comma is ok",
-}
+}