Skip to content

Commit 57681b2

Browse files
yihong0618kemingy
andauthored
Fix #261 to have better YAML parse (#272)
as diff close #261 both way can solve the problem, and I think add both are better and add co-author with @kemingy cc @huacnlee --------- Signed-off-by: yihong0618 <zouzou0208@gmail.com> Co-authored-by: Keming <kemingy94@gmail.com>
1 parent 5af1bc2 commit 57681b2

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

autocorrect/grammar/yaml.pest

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
//! YAML Parser
2-
item = _{ (pair | comment | newline | other)+ }
3-
other = ${ !(pair) ~ ANY }
1+
// YAML Parser
2+
item = _{ item_content }
3+
item_content = _{ (pair | comment | newline | other)+ }
4+
other = @{ !("#" | indent ~ (string_key | simple_key) ~ ":") ~ other_content }
5+
other_content = _{ (!newline ~ ANY)+ }
46

57
/// Comment
6-
comment = ${ "#" ~ (!(NEWLINE) ~ ANY)* }
8+
comment = ${ "#" ~ comment_content }
9+
comment_content = _{ (!newline ~ ANY)* }
10+
711
indent = ${ (^" "+)? }
812
newline = ${ "\n" | "\r" }
913

@@ -12,11 +16,21 @@ pair = _{ key_part ~ string }
1216
key = ${ (string_key | simple_key) ~ (":" ~ " "?) }
1317

1418
/// String
15-
string = ${ string_value | simple_value }
16-
string_key = _{ "\"" ~ key_str* ~ "\"" }
17-
simple_key = _{ key_str* }
18-
key_str = _{ !(newline | ":" | "\"" | "'") ~ ANY }
19-
simple_value = _{ value_str* }
20-
string_value = _{ ("\"" ~ (!(newline | "\"") ~ ANY)* ~ "\"") | ("'" ~ (!(newline | "'") ~ ANY)* ~ "'") }
21-
value_str = _{ !(newline | "\"" | "'") ~ ANY }
22-
key_part = _{ indent ~ key }
19+
string = ${ string_value | simple_value }
20+
21+
string_value = @{ double_quoted | single_quoted }
22+
double_quoted = _{ "\"" ~ double_quoted_content ~ "\"" }
23+
single_quoted = _{ "'" ~ single_quoted_content ~ "'" }
24+
double_quoted_content = _{ (!(newline | "\"") ~ ANY)* }
25+
single_quoted_content = _{ (!(newline | "'") ~ ANY)* }
26+
27+
string_key = _{ "\"" ~ key_str_content ~ "\"" }
28+
simple_key = _{ key_str_content }
29+
key_str_content = _{ key_str* }
30+
key_str = _{ !(newline | ":" | "\"" | "'") ~ ANY }
31+
32+
simple_value = _{ value_str_content }
33+
value_str_content = _{ value_str* }
34+
value_str = _{ !(newline | "\"" | "'") ~ ANY }
35+
36+
key_part = ${ indent ~ key }

autocorrect/src/code/code.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<R: RuleType> RuleTypeToString for R {
2121

2222
pub fn format_pairs<R: RuleType, O: Results>(out: O, pairs: Result<Pairs<R>, Error<R>>) -> O {
2323
// Limit parse stack max depth for avoiding some complex parser will hangs indefinitely.
24-
pest::set_call_limit(Some(10_000_000usize.try_into().unwrap()));
24+
pest::set_call_limit(Some(100_000_000usize.try_into().unwrap()));
2525

2626
let mut out = out;
2727

0 commit comments

Comments
 (0)