Skip to content

Commit

Permalink
allow relative path in call statements
Browse files Browse the repository at this point in the history
  • Loading branch information
kobkaz committed Dec 25, 2024
1 parent 1ec6765 commit a81f72e
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions opslang-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@ peg::parser! {
grammar ops_parser() for str {
use opslang_ast::*;
rule file_path() -> FilePath
= full_name:ident()
{ FilePath { full_name: full_name.to_owned() } }
= full_name:(file_path_section() ** (_ "/" _))
{ FilePath { full_name: full_name.join("/") } }


rule file_path_section_ident() -> &'input str
= quiet!{
e:$( [c if c.is_ascii_alphanumeric() || c == '_' || c == '-' || c == '.']+)
{? if e.chars().all(|c| c == '.') { Err("") } else { Ok(e) } }
}

rule file_path_section() -> &'input str
= file_path_section_ident()
/ ".." { ".." }
/ "." { "." }

rule variable_path() -> VariablePath
= raw:ident()
Expand Down Expand Up @@ -337,6 +349,12 @@ mod tests {
fn test_call() {
let r = ops_parser::call("call OTHER_FILE.ops");
dbg!(r.unwrap());
let r = ops_parser::call("call ./OTHER_FILE.ops");
dbg!(r.unwrap());
let r = ops_parser::call("call ../.another_dir/../x.y.z");
dbg!(r.unwrap());
let r = ops_parser::call("call x/.../fail");
assert!(r.is_err());
}
#[test]
fn test_wait() {
Expand Down

0 comments on commit a81f72e

Please sign in to comment.