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

Skip to content

Commit b6b1670

Browse files
committed
Add readability to anonymous literals.
1 parent 4ca21ef commit b6b1670

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/grammar.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ impl EBNFParser {
618618

619619
match self.cur_parsing {
620620
Item::RULE => {
621-
let new_name = self.new_nonterminal("__ANONYMOUS_LITERAL");
621+
let new_name = self.new_nonterminal(&*format!("__ANONYMOUS_LITERAL_{pattern}"));
622622
self.grammar.symbol_set.push(new_name.clone());
623623
self.grammar
624624
.terminals
@@ -677,7 +677,7 @@ impl EBNFParser {
677677

678678
match self.cur_parsing {
679679
Item::RULE => {
680-
let new_name = self.new_nonterminal("__ANONYMOUS_LITERAL");
680+
let new_name = self.new_nonterminal(&*format!("__ANONYMOUS_LITERAL_{pattern}"));
681681
self.grammar.symbol_set.push(new_name.clone());
682682
self.grammar
683683
.terminals
@@ -981,15 +981,15 @@ mod tests {
981981
};
982982
let expected_grammar = Grammar {
983983
symbol_set: vec![
984-
"__ANONYMOUS_LITERAL_1".to_string(),
985-
"__ANONYMOUS_LITERAL_2".to_string(),
984+
"__ANONYMOUS_LITERAL_C_1".to_string(),
985+
"__ANONYMOUS_LITERAL_D_2".to_string(),
986986
"c".to_string(),
987987
"s".to_string(),
988988
"$".to_string(),
989989
],
990990
terminals: vec![
991-
Terminal::new("__ANONYMOUS_LITERAL_1", "C", 0),
992-
Terminal::new("__ANONYMOUS_LITERAL_2", "D", 0),
991+
Terminal::new("__ANONYMOUS_LITERAL_C_1", "C", 0),
992+
Terminal::new("__ANONYMOUS_LITERAL_D_2", "D", 0),
993993
Terminal::new("$", "", 0),
994994
],
995995
start_symbol: "s".to_string(),
@@ -1000,11 +1000,11 @@ mod tests {
10001000
},
10011001
Production {
10021002
lhs: "c".to_string(),
1003-
rhs: vec!["__ANONYMOUS_LITERAL_1".to_string(), "c".to_string()],
1003+
rhs: vec!["__ANONYMOUS_LITERAL_C_1".to_string(), "c".to_string()],
10041004
},
10051005
Production {
10061006
lhs: "c".to_string(),
1007-
rhs: vec!["__ANONYMOUS_LITERAL_2".to_string()],
1007+
rhs: vec!["__ANONYMOUS_LITERAL_D_2".to_string()],
10081008
},
10091009
],
10101010
ignore_terminals: vec![],

0 commit comments

Comments
 (0)