Function parse_file

Source
pub fn parse_file(path: &str) -> Result<Units>
Expand description

Parse a given paradox file.

ยงSee

This function is generated by macros. See crate::fn_parse_file.

Examples found in repository?
examples/single_script.rs (line 7)
3fn main() {
4    let mut args = std::env::args();
5    args.next();
6    let path = args.next().expect("Missing argument: path");
7    let mut ast = parse_file(&path).unwrap();
8    use pdx_syntax::script::types::*;
9    ast.push(Unit::SingleValue(Value::Primitive(Entry::Ident(
10        "TEST".to_string(),
11    ))));
12    println!("{}", ast);
13}
More examples
Hide additional examples
examples/all_scripts.rs (line 18)
4fn parse_dir(dir: &Path) {
5    let files = std::fs::read_dir(dir).unwrap();
6    for file in files {
7        let file = file.unwrap();
8        let path = file.path();
9
10        if path.is_dir() {
11            parse_dir(&path);
12            continue;
13        }
14
15        let fname = path.to_str().unwrap();
16        if fname.ends_with(".txt") {
17            // println!("[Parsing] {}", fname);
18            let ast = parse_file(&fname);
19            if ast.is_err() {
20                println!("Parsing failed: {}", fname);
21                println!("Error: {}", ast.err().unwrap());
22            } else {
23                // println!("{:#?}", ast.ok().unwrap());
24            }
25        }
26    }
27}