Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STIL - ignore include statements, in-line loop comments #209

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rust/origen_metal/src/stil/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ pub fn from_file(path: &Path) -> OrigenResult<Node<STIL>> {
Ok(ast)
}

pub fn from_file_ignore_includes(path: &Path) -> OrigenResult<Node<STIL>> {
let ast = parser::parse_file(path)?;
Ok(ast)
}

/// Parse the given STIL file, using the given load path to resolve any include statements
/// that are encountered.
/// Include files can optionally be renamed using the `rename` argument, which
Expand Down
8 changes: 7 additions & 1 deletion rust/origen_metal/src/stil/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,14 +900,20 @@ pub fn to_ast(mut pair: Pair<Rule>, source_file: Option<&str>) -> Result<AST<STI
);
pairs.push(p);
}
Rule::loop_statement => {
Rule::loop_statement | Rule::loop_statement_with_comment => {
let mut p = pair.into_inner();
ids.push(ast.push_and_open(node!(
STIL::Loop,
p.next().unwrap().as_str().parse().unwrap()
)));
pairs.push(p);
}
Rule::loop_comment => {
let cmt = pair.as_str().to_string();
let cmt = cmt.trim();
let cmt = cmt.replace("\n", "");
ast.push(node!(STIL::Comment, cmt))
}
Rule::match_loop => {
let mut p = pair.into_inner();
let timeout = p.next().unwrap();
Expand Down
6 changes: 4 additions & 2 deletions rust/origen_metal/src/stil/stil.pest
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ scan_inversion_val = { ("0" | "1") }
pattern_block = { "Pattern" ~ name ~ "{" ~ (label? ~ time_unit)? ~ pattern_statement* ~ "}" }
label = { (string | name) ~ ":" }
time_unit = { "TimeUnit" ~ time_expr ~ EOS }
pattern_statement = { label | vector_with_comment | vector | waveform_statement | condition | call | macro_statement | loop_statement |
match_loop | goto | breakpoint | iddq | stop_statement | scan_chain_statement | annotation }
pattern_statement = !{ label | vector_with_comment | vector | waveform_statement | condition | call | macro_statement |loop_statement_with_comment |
ginty marked this conversation as resolved.
Show resolved Hide resolved
loop_statement | match_loop | goto | breakpoint | iddq | stop_statement | scan_chain_statement | annotation }

vector = { "V" ~ "ector"? ~ "{" ~ (cyclized_data | non_cyclized_data)* ~ "}" }
vector_with_comment = ${ "V" ~ "ector"? ~ (space | N)* ~ "{" ~ ((space | N)* ~ (cyclized_data | non_cyclized_data))* ~ (space | N)* ~ "}" ~ vector_comment }
Expand All @@ -302,6 +302,8 @@ call = { ("Call" ~ name ~ "{" ~ (cyclized_data | non_cyclized_data)* ~ "}") | ("
macro_statement = { ("Macro" ~ name ~ "{" ~ (cyclized_data | non_cyclized_data)* ~ "}") | ("Macro" ~ name ~ EOS) }

loop_statement = { "Loop" ~ integer ~ "{" ~ pattern_statement* ~ "}" }
loop_statement_with_comment = ${ "Loop" ~ (space | N)* ~ integer ~ (space | N)* ~ "{" ~ ((space | N)* ~ pattern_statement)* ~ (space | N)* ~ "}" ~ loop_comment }
loop_comment = @{ space* ~ "//" ~ (!N ~ ANY)* ~ N }

match_loop = { "MatchLoop" ~ (integer | infinite) ~ "{" ~ pattern_statement+ ~ "}" }
infinite = { "Infinite" }
Expand Down
Loading