@@ -14,26 +14,9 @@ bnf_rules!(
1414 expr :: = factor { " +" factor }
1515 factor :: = " -" primary | primary
1616 primary :: = " (" expr " )" | number
17- number :: = fn ( number_tokenizer ) // custom tokenizer with function
17+ number :: = r " \d+ " // regex
1818);
1919
20- /// Custom tokenizer for numeric literal
21- fn number_tokenizer (source : & Vec <char >, mut current_position : usize ) -> usize {
22- let mut iteration_count = 0 ;
23- loop {
24- let current_char = match source . get (current_position ) {
25- Some (ch ) => ch . clone (),
26- _ => break
27- };
28- if ! current_char . is_numeric () {
29- break ;
30- }
31- iteration_count += 1 ;
32- current_position += 1 ;
33- }
34- return iteration_count ; // 0 means 'rejected', other means 'accepted' and 'length of token'.
35- }
36-
3720pub fn parse () {
3821
3922 // A function named "parse_source" is automatically generated.
@@ -45,7 +28,7 @@ pub fn parse() {
4528
4629### Usage
4730``` toml
48- bnf_rules = " 0.1.4 "
31+ bnf_rules = " 0.1.5 "
4932```
5033
5134### Extended BNF
@@ -54,6 +37,7 @@ bnf_rules = "0.1.4"
5437| source | An entire input source. |
5538| ident | A non-terminal symbol named "ident". |
5639| "something" | A terminal symbol for text. |
40+ | r"\d+" | A terminal symbol for regex. |
5741| fn (function_name) | A custom tokenizer with user function.[ ^ 1 ] |
5842| { pattern } | Zero or more repetitions of "pattern". |
5943| \[ pattern \] | "pattern" or null. |
@@ -64,4 +48,4 @@ bnf_rules = "0.1.4"
6448
6549> Example 1: https://github.com/bea4dev/bnf_rules/blob/master/src/lib.rs
6650
67- > Example 2: https://github.com/bea4dev/catla/blob/master/catla_parser/src/grammar.rs
51+ > Example 2: https://github.com/bea4dev/catla/blob/master/catla_parser/src/grammar.rs
0 commit comments