forked from kevinmehall/rust-peg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented feature: member variables. Fixes github issue kevinmehall…
- Loading branch information
1 parent
8898f64
commit 7404fec
Showing
7 changed files
with
161 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
extern crate peg; | ||
|
||
peg::parser!(grammar foo() for str { | ||
fn asdf() {} //~ ERROR expected one of "#", "crate", "pub", "rule", "use", "}" | ||
fn asdf() {} //~ ERROR expected ":" | ||
}); | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
error: expected one of "#", "crate", "pub", "rule", "use", "}" | ||
--> $DIR/syntax_error.rs:4:5 | ||
error: expected ":" | ||
--> $DIR/syntax_error.rs:4:8 | ||
| | ||
4 | fn asdf() {} //~ ERROR expected one of "#", "crate", "pub", "rule", "use", "}" | ||
| ^^ | ||
4 | fn asdf() {} //~ ERROR expected ":" | ||
| ^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::line_counter::lines; | ||
|
||
peg::parser!( grammar line_counter() for str { | ||
line_count: u32; | ||
|
||
pub rule lines() -> u32 | ||
= line()* { __state.line_count } | ||
|
||
rule line() | ||
= (terminated_line() / unterminated_line()) { __state.line_count += 1; } | ||
|
||
rule terminated_line() | ||
= (not_eol() one_char())* eol() | ||
|
||
rule unterminated_line() | ||
= (not_eol() one_char())+ | ||
|
||
rule one_char() = [_] | ||
rule not_eol() = !eol() | ||
rule eol() = "\r\n" / "\n" | ||
rule eof() = ![_] | ||
}); | ||
|
||
fn main() { | ||
assert_eq!(lines(""), Ok(0)); | ||
|
||
assert_eq!(lines("\n"), Ok(1)); | ||
assert_eq!(lines("abc\n"), Ok(1)); | ||
assert_eq!(lines("abc"), Ok(1)); | ||
|
||
assert_eq!(lines("\n\n"), Ok(2)); | ||
assert_eq!(lines("abc\ndef\n"), Ok(2)); | ||
assert_eq!(lines("abc\ndef"), Ok(2)); | ||
assert_eq!(lines("\ndef"), Ok(2)); | ||
} |