-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rs/import: Labels must be serched as well for recovery rules
The dependency finder of a rule was alware of Identifiers used within any subexpressions. But we also need to check for labels which might have recovery rules defined with the same name and add them as dependencies as well. e.g.: // File leaf.peg @import Val from "./dependecy.peg" Main <- Val ("," Val)* // File dependency.peg Val <- Hex / Dec / Str / Bool Hex <- '0x' [a-fA-F0-9]+^LabelHex LabelHex <- (!Val .)* The importer wasn't pulling "LabelHex" into the file "leaf.peg" without this change. This also changes Comipler.compile to take the starting rule as an optional value, and if it is not present, the first rule that appears in the grammar ast will be used.
- Loading branch information
Showing
12 changed files
with
96 additions
and
11 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
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,6 @@ | ||
@import Value from "./import_gr_value.peg" | ||
|
||
Expr <- Term EOF^eof | ||
Term <- Multi (( '+' / '-' ) Multi^term_right_operand )* | ||
Multi <- Primary (( '*' / '/' ) Primary^multi_right_operand)* | ||
Primary <- Value / '(' Expr ')' |
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,6 @@ | ||
// This grammar has no dependencies | ||
Number <- Binary / Hexadecimal / Float / Decimal | ||
Float <- Decimal #('.' Decimal) | ||
Decimal <- [1-9][0-9]* / '0' | ||
Binary <- '#' [bB] [0-1]+ | ||
Hexadecimal <- '#' [xX] [a-fA-F0-9]+ |
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,3 @@ | ||
String <- SingleQuote / DoubleQuote | ||
SingleQuote <- "'" (!"'" .)* "'" | ||
DoubleQuote <- '"' (!'"' .)* '"' |
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,10 @@ | ||
@import Number from "./import_gr_number.peg" | ||
@import String from "./import_gr_string.peg" | ||
|
||
Value <- String / Number / Boolean | ||
Boolean <- 'true' / 'false' | ||
|
||
// overrides what's defined within Number | ||
Binary <- '0b' [0-1]+ | ||
Hexadecimal <- '0x' [a-fA-F0-9]+^LabelHex | ||
LabelHex <- (!' ' .)* |
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,17 @@ | ||
mod helpers; | ||
use helpers::{assert_match, compile_file, run_str}; | ||
|
||
use langlang_lib::compiler; | ||
|
||
#[test] | ||
fn test_import() { | ||
let cc = compiler::Config::default(); | ||
let program = compile_file(&cc, "./import_gr_expr.peg", None); | ||
|
||
// This test ensures that `LabelHex` is also imported as a | ||
// dependency from the `Hexadecimal` production. | ||
assert_match( | ||
"Expr[Term[Multi[Primary[Value[Number[Hexadecimal[0xError[LabelHex]]]]]]+Multi[Primary[Value[Number[Decimal[3]]]]]]]", | ||
run_str(&program, "0xG + 3"), | ||
) | ||
} |
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