ast_result

Function ast_result 

Source
pub fn ast_result(input: &str) -> Vec<Function>
Expand description

Gets the abstract syntax tree generated from the parser of zypo-rs. This function will panic is parsing fails and is intended for developers aiming to implament the parser into code generation.

Please see Function for more infomation of what this will immidiatly return.

ยงExamples

Basic function with 2 defined parameters:

use zypo_parser::{
    VarType,
    Function,
    Parameter,
    ast_result
};

fn main() {
    let input = "fun test_function(my_int: int, some_string: str) {}";
    let expected = vec![
        Function {
            ident: "test_function".to_string(),
            params: vec![
                Parameter { ident: "my_int".to_string(), ty: VarType::Int },
                Parameter { ident: "some_string".to_string(), ty: VarType::Str }
            ],
            body: vec![],
            return_type: VarType::Void
        }
    ];

    assert_eq!(ast_result(input), expected);
}