-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Basic scaffolding for metadeta * Implemented new_metadata.pset and new_parser.rs * Added new_parser and test cases * Enabled debugger to debug any .futil file * Clippy complaints * Adjusted code to PR suggestions and added some comments
- Loading branch information
1 parent
9f55a12
commit 1a4050d
Showing
9 changed files
with
181 additions
and
49 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
WHITE_SPACE = _{ " " | "\t" | NEWLINE } | ||
dot = _{ "." } | ||
colon = _{ ":" } | ||
ident_syms = _{ "_" | "-" | "'" } | ||
num = @{ ASCII_DIGIT+ } | ||
group_name = @{ (ASCII_ALPHA | ASCII_DIGIT | ident_syms | dot)+ } | ||
path = @{ (ASCII_ALPHA | ASCII_DIGIT | ident_syms | dot | "/")+ } | ||
|
||
entry = { group_name ~ colon ~ WHITE_SPACE ~ path ~ WHITE_SPACE ~ num ~ (",")* ~ WHITE_SPACE* } | ||
|
||
metadata = { | ||
SOI ~ entry* ~ EOI | ||
} |
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,101 @@ | ||
use super::source::structures::{GroupContents, NewSourceMap}; | ||
use crate::errors::InterpreterResult; | ||
use pest_consume::{match_nodes, Error, Parser}; | ||
use std::collections::HashMap; | ||
type ParseResult<T> = std::result::Result<T, Error<Rule>>; | ||
type Node<'i> = pest_consume::Node<'i, Rule, ()>; | ||
|
||
// include the grammar file so that Cargo knows to rebuild this file on grammar changes | ||
const _GRAMMAR: &str = include_str!("new_metadata.pest"); | ||
|
||
#[derive(Parser)] | ||
#[grammar = "debugger/new_metadata.pest"] | ||
pub struct MetadataParser; | ||
|
||
#[pest_consume::parser] | ||
impl MetadataParser { | ||
fn EOI(_input: Node) -> ParseResult<()> { | ||
Ok(()) | ||
} | ||
pub fn num(input: Node) -> ParseResult<u64> { | ||
input | ||
.as_str() | ||
.parse::<u64>() | ||
.map_err(|_| input.error("Expected number")) | ||
} | ||
fn group_name(input: Node) -> ParseResult<String> { | ||
Ok(input.as_str().to_string()) | ||
} | ||
|
||
fn path(input: Node) -> ParseResult<String> { | ||
Ok(input.as_str().to_string()) | ||
} | ||
|
||
fn entry(input: Node) -> ParseResult<(String, GroupContents)> { | ||
Ok(match_nodes!(input.into_children(); | ||
[group_name(g), path(p),num(n)] => (g,GroupContents {path:p, line: n}) | ||
)) | ||
} | ||
|
||
fn metadata(input: Node) -> ParseResult<NewSourceMap> { | ||
Ok(match_nodes!(input.into_children(); | ||
[entry(e).., EOI(_)] => { | ||
let map: HashMap<String, GroupContents> = e.collect(); | ||
map.into() | ||
} | ||
)) | ||
} | ||
} | ||
|
||
pub fn parse_metadata(input_str: &str) -> InterpreterResult<NewSourceMap> { | ||
let inputs = MetadataParser::parse(Rule::metadata, input_str)?; | ||
let input = inputs.single()?; | ||
Ok(MetadataParser::metadata(input)?) | ||
} | ||
|
||
// Meta is expected as the following format, this is an example for reg_seq.futil | ||
|
||
// metadata #{ | ||
// wr_reg0: /path/to/file 10 | ||
// wr_reg1: /path/to/file 15 | ||
// }# | ||
|
||
#[cfg(test)] | ||
#[test] | ||
fn one_entry() { | ||
let entry = parse_metadata("hello: your/mom 5").unwrap(); | ||
dbg!(&entry); | ||
let tup = entry.lookup(String::from("hello")); | ||
assert_eq!( | ||
tup.unwrap().clone(), | ||
GroupContents { | ||
path: String::from("your/mom"), | ||
line: 5 | ||
} | ||
) | ||
} | ||
|
||
#[test] | ||
fn mult_entires() { | ||
let entry = parse_metadata( | ||
"wr_reg0: calyx/interp/test/control/reg_seq.futil 10, | ||
wr_reg1: calyx/interp/test/control/reg_seq.futil 15", | ||
) | ||
.unwrap(); | ||
let tup = entry.lookup(String::from("wr_reg0")); | ||
let tup2 = entry.lookup(String::from("wr_reg1")); | ||
assert_eq!( | ||
tup.unwrap().clone(), | ||
GroupContents { | ||
path: String::from("calyx/interp/test/control/reg_seq.futil"), | ||
line: 10 | ||
} | ||
); | ||
assert_eq!( | ||
tup2.unwrap().clone(), | ||
GroupContents { | ||
path: String::from("calyx/interp/test/control/reg_seq.futil"), | ||
line: 15 | ||
} | ||
) | ||
} |
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,27 +1,25 @@ | ||
WHITESPACE = _{ " " | "\t" } | ||
dot = _{"."} | ||
dot = _{ "." } | ||
ident_syms = _{ "_" | "-" | "'" } | ||
quote = _{"\""} | ||
num = @{ASCII_DIGIT+} | ||
quote = _{ "\"" } | ||
num = @{ ASCII_DIGIT+ } | ||
|
||
id_string = @{ ("_" | ASCII_ALPHA)+ ~ (ident_syms | ASCII_ALPHA | ASCII_DIGIT | "::" |".")* } | ||
id_string = @{ ("_" | ASCII_ALPHA)+ ~ (ident_syms | ASCII_ALPHA | ASCII_DIGIT | "::" | ".")* } | ||
|
||
named_tag = { "(" ~ num ~ "," ~ id_string ~ ")" } | ||
|
||
tag = { named_tag | num } | ||
|
||
escaped_newline = @{ "\\" ~ NEWLINE } | ||
string_char = ${ !(NEWLINE | EOI) ~ ANY } | ||
source_char = { escaped_newline | string_char } | ||
string_char = ${ !(NEWLINE | EOI) ~ ANY } | ||
source_char = { escaped_newline | string_char } | ||
|
||
inner_position_string = ${ source_char* } | ||
inner_position_string = ${ source_char* } | ||
|
||
position_string = { inner_position_string ~ (NEWLINE | &EOI) } | ||
|
||
entry = { tag ~ ":" ~ position_string} | ||
entry = { tag ~ ":" ~ position_string } | ||
|
||
metadata = { | ||
SOI ~ | ||
entry+ ~ | ||
EOI | ||
SOI ~ entry+ ~ EOI | ||
} |
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