Skip to content

Commit 78fcdce

Browse files
committed
Working on error output
1 parent 31c64db commit 78fcdce

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

lrlex/src/lib/ctbuilder.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ where
545545
.collect::<HashMap<_, _>>();
546546
closure_lexerdef.set_rule_ids(&owned_map);
547547
yacc_header.mark_used(&"test_files".to_string());
548+
let grammar = rtpb.grammar();
548549
let test_glob = yacc_header.get("test_files");
549550
let mut err_str = None;
550551
let add_error_line = |err_str: &mut Option<String>, line| {
@@ -575,13 +576,15 @@ where
575576
let l: LRNonStreamingLexer<LexerTypesT> =
576577
closure_lexerdef.lexer(&input);
577578
let errs = rtpb.parse_map(&l, &|_| (), &|_, _| ()).1;
578-
if errs.len() > 1 {
579+
if !errs.is_empty() {
579580
add_error_line(&mut err_str, format!("While parsing {}:", path.display()));
580581
for e in errs {
581-
add_error_line(&mut err_str, format!("\t{}", e));
582+
let e_pp = e.pp(&l, &|t| grammar.token_epp(t));
583+
let e_lines = e_pp.split("\n");
584+
for e in e_lines {
585+
add_error_line(&mut err_str, format!("\t{}", e));
586+
}
582587
}
583-
} else if !errs.is_empty() {
584-
add_error_line(&mut err_str, format!("parsing {}: {}", path.display(), errs[0]));
585588
}
586589
}
587590
}

lrpar/cttests/src/grmtools_section.test

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
grammar: |
2-
%grmtools{yacckind: Grmtools}
2+
%grmtools{
3+
yacckind: Grmtools,
4+
recoverer: RecoveryKind::CPCTPlus,
5+
test_files: ["*.input_grmtools_section"]
6+
}
37
%token MAGIC IDENT NUM STRING
48
%epp MAGIC "%grmtools"
59
%%
@@ -164,3 +168,6 @@ lexer: |
164168
: ':'
165169
\"(\\.|[^"\\])*\" 'STRING'
166170
\p{Pattern_White_Space} ;
171+
extra_files:
172+
test.input_grmtools_section: |
173+
%grmtools{yacckind: Grmtools, !b, !a}

lrpar/src/lib/parser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,10 @@ where
10371037
param,
10381038
)
10391039
}
1040+
1041+
pub fn grammar(&self) -> &YaccGrammar<StorageT> {
1042+
self.grm
1043+
}
10401044
}
10411045

10421046
/// After a parse error is encountered, the parser attempts to find a way of recovering. Each entry

nimbleparse/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl fmt::Display for NimbleparseError {
495495
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
496496
match self {
497497
Self::Source { src_path, errs } => {
498-
writeln!(f, "While parsing: {}", src_path.display())?;
498+
writeln!(f, "While parsing {}:", src_path.display())?;
499499
for e in errs {
500500
writeln!(f, "{}", e)?
501501
}

0 commit comments

Comments
 (0)