Skip to content

Commit

Permalink
(fix) json string literal rule
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 committed Mar 26, 2021
1 parent a8392df commit de39b97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ literal = { string_literal |
null_literal = @{ "null" ~ !symbol_char }
boolean_literal = @{ ("true"|"false") ~ !symbol_char }
number_literal = @{ "-"? ~ ASCII_DIGIT+ ~ "."? ~ ASCII_DIGIT* ~ ("E" ~ "-"? ~ ASCII_DIGIT+)? }
string_literal = @{ ("\"" ~ (!"\"" ~ ("\\\"" | ANY))* ~ "\"") | ("'" ~ (!"'" ~ ("\\'" | ANY))* ~ "'") }
json_char = {
!("\"" | "\\") ~ ANY
| "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}
string_inner = @{ json_char* }
string_literal = ${ "\"" ~ string_inner ~ "\"" }
array_literal = { "[" ~ literal? ~ ("," ~ literal)* ~ "]" }
object_literal = { "{" ~ (string_literal ~ ":" ~ literal)?
~ ("," ~ string_literal ~ ":" ~ literal)* ~ "}" }
Expand Down
3 changes: 1 addition & 2 deletions src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ mod test {
let s = vec![
"\"json string\"",
"\"quot: \\\"\"",
"'json string'",
"'quot: \\''",
"[]",
"[\"hello\"]",
"[1,2,3,4,true]",
Expand Down Expand Up @@ -174,6 +172,7 @@ mod test {
"{{exp 1}}",
"{{exp \"literal\"}}",
"{{exp \"literal with space\"}}",
r#"{{exp "literal with escape \\\\"}}"#,
"{{exp ref}}",
"{{exp (sub)}}",
"{{exp (sub 123)}}",
Expand Down

0 comments on commit de39b97

Please sign in to comment.