Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ceca09b

Browse files
committed
Make Parser::new() return Result<Parser, ()>.
This makes the API consistent with that of Lexer::new(). TODO: add meaningful error checking to constructor.
1 parent 30794c6 commit ceca09b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/parser.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ use crate::types::*;
1515

1616
impl Parser {
1717
/// Construct a new parser from a grammar.
18-
pub fn new(grammar: &Grammar) -> Parser {
18+
pub fn new(grammar: &Grammar) -> Result<Parser, ()> {
1919
let (action_table, goto_table) = tables(grammar.clone());
20-
Parser {
20+
Ok(Parser {
2121
action_table,
2222
goto_table,
2323
start_state: 0,
2424
grammar: grammar.clone(),
25-
}
25+
})
2626
}
2727

2828
/// Return all the terminals that could come after this one, regardless of
@@ -573,7 +573,9 @@ mod tests {
573573
],
574574
}],
575575
};
576-
let parser = Parser::new(&grammar);
576+
let Ok(parser) = Parser::new(&grammar) else {
577+
panic!()
578+
};
577579
assert_eq!(
578580
parser.next_terminals(&"L_PAREN".to_string()),
579581
vec!["R_PAREN".to_string()]

0 commit comments

Comments
 (0)