diff --git a/projects/dejavu-parser/build.rs b/projects/dejavu-parser/build.rs index 6986730..eb232a6 100644 --- a/projects/dejavu-parser/build.rs +++ b/projects/dejavu-parser/build.rs @@ -3,6 +3,6 @@ use yggdrasil_shared::codegen::RustCodegen; fn main() { let grammars = std::path::Path::new("grammars/").canonicalize().unwrap(); let builder = RustCodegen::default(); - builder.generate(include_str!("grammars/dejavu.ygg"), "src/dejavu").unwrap(); + builder.generate(include_str!("grammars/nexus"), "src/nexus").unwrap(); println!("cargo:rerun-if-changed={}", grammars.display()); } diff --git a/projects/dejavu-parser/grammars/dejavu.ygg b/projects/dejavu-parser/grammars/nexus similarity index 98% rename from projects/dejavu-parser/grammars/dejavu.ygg rename to projects/dejavu-parser/grammars/nexus index a95c24c..eb6a6e4 100644 --- a/projects/dejavu-parser/grammars/dejavu.ygg +++ b/projects/dejavu-parser/grammars/nexus @@ -1,4 +1,4 @@ -grammar Dejavu { +grammar Nexus { file: '*.djv' } @@ -32,10 +32,10 @@ class TEXT_WORD { // === template token === ---------------------------------------------------------------------------------------------- @style(operator) atomic class TEMPLATE_L { - '<%' SPACE_CONTROL + '<%' SPACE_CONTROL? } atomic class TEMPLATE_R { - SPACE_CONTROL '%>' + SPACE_CONTROL? '%>' } union SPACE_CONTROL { | '_' #A diff --git a/projects/dejavu-parser/Readme.md b/projects/dejavu-parser/readme.md similarity index 97% rename from projects/dejavu-parser/Readme.md rename to projects/dejavu-parser/readme.md index 2e4fa04..7ab2598 100644 --- a/projects/dejavu-parser/Readme.md +++ b/projects/dejavu-parser/readme.md @@ -1,8 +1,6 @@ Title ===== - - ```shell cargo doc --package build_by_script --no-deps --open ``` \ No newline at end of file diff --git a/projects/dejavu-parser/src/dejavu/parse_cst.rs b/projects/dejavu-parser/src/dejavu/parse_cst.rs deleted file mode 100644 index 9c86e6e..0000000 --- a/projects/dejavu-parser/src/dejavu/parse_cst.rs +++ /dev/null @@ -1,480 +0,0 @@ -use super::*; - -pub(super) fn parse_cst(input: &str, rule: DejavuRule) -> OutputResult { - state(input, |state| match rule { - DejavuRule::Root => parse_root(state), - DejavuRule::Element => parse_element(state), - DejavuRule::TextElements => parse_text_elements(state), - DejavuRule::TEMPLATE_E => parse_template_e(state), - DejavuRule::TEXT_SPACE => parse_text_space(state), - DejavuRule::TEXT_WORD => parse_text_word(state), - DejavuRule::TEMPLATE_L => parse_template_l(state), - DejavuRule::TEMPLATE_R => parse_template_r(state), - DejavuRule::SPACE_CONTROL => parse_space_control(state), - DejavuRule::KW_END => parse_kw_end(state), - DejavuRule::TemplateExport => parse_template_export(state), - DejavuRule::ExportItem => parse_export_item(state), - DejavuRule::KW_EXPORT => parse_kw_export(state), - DejavuRule::KW_CLASS => parse_kw_class(state), - DejavuRule::KW_TRAIT => parse_kw_trait(state), - DejavuRule::KW_TO => parse_kw_to(state), - DejavuRule::KW_BY => parse_kw_by(state), - DejavuRule::TemplateIf => parse_template_if(state), - DejavuRule::IfBegin => parse_if_begin(state), - DejavuRule::IfElse => parse_if_else(state), - DejavuRule::IfElseIf => parse_if_else_if(state), - DejavuRule::IfEnd => parse_if_end(state), - DejavuRule::KW_IF => parse_kw_if(state), - DejavuRule::KW_ELSE => parse_kw_else(state), - DejavuRule::Atomic => parse_atomic(state), - DejavuRule::String => parse_string(state), - DejavuRule::Number => parse_number(state), - DejavuRule::NamepathFree => parse_namepath_free(state), - DejavuRule::Namepath => parse_namepath(state), - DejavuRule::Identifier => parse_identifier(state), - DejavuRule::Boolean => parse_boolean(state), - DejavuRule::WhiteSpace => parse_white_space(state), - DejavuRule::IgnoreText => unreachable!(), - DejavuRule::IgnoreRegex => unreachable!(), - }) -} -#[inline] -fn parse_root(state: Input) -> Output { - state.rule(DejavuRule::Root, |s| s.repeat(0..4294967295, |s| parse_element(s).and_then(|s| s.tag_node("element")))) -} -#[inline] -fn parse_element(state: Input) -> Output { - state.rule(DejavuRule::Element, |s| { - Err(s) - .or_else(|s| parse_text_elements(s).and_then(|s| s.tag_node("text_elements"))) - .or_else(|s| parse_template_export(s).and_then(|s| s.tag_node("template_export"))) - .or_else(|s| parse_template_if(s).and_then(|s| s.tag_node("template_if"))) - }) -} -#[inline] -fn parse_text_elements(state: Input) -> Output { - state.rule(DejavuRule::TextElements, |s| { - Err(s) - .or_else(|s| parse_template_e(s).and_then(|s| s.tag_node("template_e"))) - .or_else(|s| parse_text_space(s).and_then(|s| s.tag_node("text_space"))) - .or_else(|s| parse_text_word(s).and_then(|s| s.tag_node("text_word"))) - }) -} -#[inline] -fn parse_template_e(state: Input) -> Output { - state.rule(DejavuRule::TEMPLATE_E, |s| s.match_string("<<%", false)) -} -#[inline] -fn parse_text_space(state: Input) -> Output { - state.rule(DejavuRule::TEXT_SPACE, |s| { - s.match_regex({ - static REGEX: OnceLock = OnceLock::new(); - REGEX.get_or_init(|| Regex::new("^(\\p{White_Space}+)").unwrap()) - }) - }) -} -#[inline] -fn parse_text_word(state: Input) -> Output { - state.rule(DejavuRule::TEXT_WORD, |s| { - s.match_regex({ - static REGEX: OnceLock = OnceLock::new(); - REGEX.get_or_init(|| Regex::new("^([^<\\p{White_Space}]+)").unwrap()) - }) - }) -} -#[inline] -fn parse_template_l(state: Input) -> Output { - state.rule(DejavuRule::TEMPLATE_L, |s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| builtin_text(s, "<%", false)) - .and_then(|s| parse_space_control(s).and_then(|s| s.tag_node("space_control"))) - }) - }) -} -#[inline] -fn parse_template_r(state: Input) -> Output { - state.rule(DejavuRule::TEMPLATE_R, |s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_space_control(s).and_then(|s| s.tag_node("space_control"))) - .and_then(|s| builtin_text(s, "%>", false)) - }) - }) -} -#[inline] -fn parse_space_control(state: Input) -> Output { - state.rule(DejavuRule::SPACE_CONTROL, |s| { - Err(s) - .or_else(|s| builtin_text(s, "_", false).and_then(|s| s.tag_node("space_control_0"))) - .or_else(|s| builtin_text(s, "-", false).and_then(|s| s.tag_node("space_control_1"))) - .or_else(|s| builtin_text(s, "~", false).and_then(|s| s.tag_node("space_control_2"))) - .or_else(|s| builtin_text(s, "=", false).and_then(|s| s.tag_node("space_control_3"))) - }) -} - -#[inline] -fn parse_kw_end(state: Input) -> Output { - state.rule(DejavuRule::KW_END, |s| s.match_string("end", false)) -} - -#[inline] -fn parse_template_export(state: Input) -> Output { - state.rule(DejavuRule::TemplateExport, |s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_template_l(s).and_then(|s| s.tag_node("template_l"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| { - s.repeat(0..4294967295, |s| parse_export_item(s).and_then(|s| s.tag_node("export_item"))) - }) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_template_r(s).and_then(|s| s.tag_node("template_r"))) - }) - .and_then(|s| s.tag_node("exports")) - }) - }) - }) -} - -#[inline] -fn parse_export_item(state: Input) -> Output { - state.rule(DejavuRule::ExportItem, |s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_kw_export(s).and_then(|s| s.tag_node("kw_export"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_identifier(s).and_then(|s| s.tag_node("identifier"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| { - s.optional(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_kw_to(s).and_then(|s| s.tag_node("kw_to"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_identifier(s).and_then(|s| s.tag_node("language"))) - }) - }) - }) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| { - s.optional(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_kw_by(s).and_then(|s| s.tag_node("kw_by"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_kw_class(s).and_then(|s| s.tag_node("kw_class"))) - }) - }) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_namepath_free(s).and_then(|s| s.tag_node("class"))) - }) - }) - }) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| { - s.optional(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_kw_by(s).and_then(|s| s.tag_node("kw_by"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_kw_trait(s).and_then(|s| s.tag_node("kw_trait"))) - }) - }) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| { - s.optional(|s| parse_namepath_free(s).and_then(|s| s.tag_node("namepath_free"))) - .and_then(|s| s.tag_node("trait")) - }) - }) - }) - }) - }) - .and_then(|s| s.tag_node("name")) - }) - }) - }) -} - -#[inline] -fn parse_kw_export(state: Input) -> Output { - state.rule(DejavuRule::KW_EXPORT, |s| s.match_string("export", false)) -} - -#[inline] -fn parse_kw_class(state: Input) -> Output { - state.rule(DejavuRule::KW_CLASS, |s| s.match_string("class", false)) -} - -#[inline] -fn parse_kw_trait(state: Input) -> Output { - state.rule(DejavuRule::KW_TRAIT, |s| s.match_string("trait", false)) -} - -#[inline] -fn parse_kw_to(state: Input) -> Output { - state.rule(DejavuRule::KW_TO, |s| s.match_string("to", false)) -} - -#[inline] -fn parse_kw_by(state: Input) -> Output { - state.rule(DejavuRule::KW_BY, |s| s.match_string("by", false)) -} -#[inline] -fn parse_template_if(state: Input) -> Output { - state.rule(DejavuRule::TemplateIf, |s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_if_begin(s).and_then(|s| s.tag_node("if_begin"))) - .and_then(|s| s.repeat(0..4294967295, |s| parse_if_else_if(s).and_then(|s| s.tag_node("if_else_if")))) - .and_then(|s| s.optional(|s| parse_if_else(s).and_then(|s| s.tag_node("if_else")))) - .and_then(|s| parse_if_end(s)) - }) - }) -} -#[inline] -fn parse_if_begin(state: Input) -> Output { - state.rule(DejavuRule::IfBegin, |s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_template_l(s).and_then(|s| s.tag_node("template_l"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_kw_if(s).and_then(|s| s.tag_node("kw_if"))) - }) - }) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_atomic(s).and_then(|s| s.tag_node("atomic"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_template_r(s).and_then(|s| s.tag_node("template_r"))) - }) - }) - .and_then(|s| { - s.repeat(0..4294967295, |s| parse_text_elements(s).and_then(|s| s.tag_node("text_elements"))) - .and_then(|s| s.tag_node("text")) - }) - }) - .and_then(|s| s.tag_node("condition")) - }) - }) - }) -} -#[inline] -fn parse_if_else(state: Input) -> Output { - state.rule(DejavuRule::IfElse, |s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_template_l(s).and_then(|s| s.tag_node("template_l"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_kw_else(s).and_then(|s| s.tag_node("kw_else"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_template_r(s).and_then(|s| s.tag_node("template_r"))) - }) - }) - .and_then(|s| { - s.repeat(0..4294967295, |s| parse_text_elements(s).and_then(|s| s.tag_node("text_elements"))) - .and_then(|s| s.tag_node("text")) - }) - }) - }) -} -#[inline] -fn parse_if_else_if(state: Input) -> Output { - state.rule(DejavuRule::IfElseIf, |s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_template_l(s).and_then(|s| s.tag_node("template_l"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_kw_else(s).and_then(|s| s.tag_node("kw_else"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_kw_if(s).and_then(|s| s.tag_node("kw_if"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_template_r(s).and_then(|s| s.tag_node("template_r"))) - }) - }) - .and_then(|s| { - s.repeat(0..4294967295, |s| parse_text_elements(s).and_then(|s| s.tag_node("text_elements"))) - .and_then(|s| s.tag_node("text")) - }) - }) - }) -} -#[inline] -fn parse_if_end(state: Input) -> Output { - state.rule(DejavuRule::IfEnd, |s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_template_l(s).and_then(|s| s.tag_node("template_l"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_kw_end(s).and_then(|s| s.tag_node("kw_end"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| s.optional(|s| parse_kw_if(s).and_then(|s| s.tag_node("kw_if")))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_template_r(s).and_then(|s| s.tag_node("template_r"))) - }) - }) -} -#[inline] -fn parse_kw_if(state: Input) -> Output { - state.rule(DejavuRule::KW_IF, |s| s.match_string("if", false)) -} -#[inline] -fn parse_kw_else(state: Input) -> Output { - state.rule(DejavuRule::KW_ELSE, |s| s.match_string("else", false)) -} -#[inline] -fn parse_atomic(state: Input) -> Output { - state.rule(DejavuRule::Atomic, |s| { - Err(s) - .or_else(|s| parse_boolean(s).and_then(|s| s.tag_node("boolean"))) - .or_else(|s| parse_identifier(s).and_then(|s| s.tag_node("identifier"))) - .or_else(|s| parse_number(s).and_then(|s| s.tag_node("number"))) - }) -} - -#[inline] -fn parse_string(state: Input) -> Output { - state.rule(DejavuRule::String, |s| { - Err(s) - .or_else(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| builtin_text(s, "\"", false)) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| builtin_text(s, "\"", false)) - }) - .and_then(|s| s.tag_node("string_0")) - }) - .or_else(|s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| builtin_text(s, "'", false)) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| builtin_text(s, "'", false)) - }) - .and_then(|s| s.tag_node("string_1")) - }) - }) -} -#[inline] -fn parse_number(state: Input) -> Output { - state.rule(DejavuRule::Number, |s| { - s.match_regex({ - static REGEX: OnceLock = OnceLock::new(); - REGEX.get_or_init(|| Regex::new("^(0|[1-9][0-9])").unwrap()) - }) - }) -} - -#[inline] -fn parse_namepath_free(state: Input) -> Output { - state.rule(DejavuRule::NamepathFree, |s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_identifier(s).and_then(|s| s.tag_node("identifier"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| { - s.repeat(0..4294967295, |s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| { - Err(s).or_else(|s| builtin_text(s, ".", false)).or_else(|s| builtin_text(s, "::", false)) - }) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_identifier(s).and_then(|s| s.tag_node("identifier"))) - }) - }) - }) - }) - }) -} - -#[inline] -fn parse_namepath(state: Input) -> Output { - state.rule(DejavuRule::Namepath, |s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| parse_identifier(s).and_then(|s| s.tag_node("identifier"))) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| { - s.repeat(0..4294967295, |s| { - s.sequence(|s| { - Ok(s) - .and_then(|s| builtin_text(s, "::", false)) - .and_then(|s| builtin_ignore(s)) - .and_then(|s| parse_identifier(s).and_then(|s| s.tag_node("identifier"))) - }) - }) - }) - }) - }) -} -#[inline] -fn parse_identifier(state: Input) -> Output { - state.rule(DejavuRule::Identifier, |s| { - s.match_regex({ - static REGEX: OnceLock = OnceLock::new(); - REGEX.get_or_init(|| Regex::new("^([_\\p{XID_start}]\\p{XID_continue}*)").unwrap()) - }) - }) -} -#[inline] -fn parse_boolean(state: Input) -> Output { - state.rule(DejavuRule::Boolean, |s| { - Err(s) - .or_else(|s| builtin_text(s, "true", false).and_then(|s| s.tag_node("boolean_0"))) - .or_else(|s| builtin_text(s, "false", false).and_then(|s| s.tag_node("boolean_1"))) - }) -} -#[inline] -fn parse_white_space(state: Input) -> Output { - state.rule(DejavuRule::WhiteSpace, |s| { - s.match_regex({ - static REGEX: OnceLock = OnceLock::new(); - REGEX.get_or_init(|| Regex::new("^(\\p{White_Space}+)").unwrap()) - }) - }) -} - -/// All rules ignored in ast mode, inline is not recommended -fn builtin_ignore(state: Input) -> Output { - state.repeat(0..u32::MAX, |s| parse_white_space(s)) -} - -fn builtin_any(state: Input) -> Output { - state.rule(DejavuRule::IgnoreText, |s| s.match_char_if(|_| true)) -} - -fn builtin_text<'i>(state: Input<'i>, text: &'static str, case: bool) -> Output<'i> { - state.rule(DejavuRule::IgnoreText, |s| s.match_string(text, case)) -} - -fn builtin_regex<'i, 'r>(state: Input<'i>, regex: &'r Regex) -> Output<'i> { - state.rule(DejavuRule::IgnoreRegex, |s| s.match_regex(regex)) -} diff --git a/projects/dejavu-parser/src/dejavu/railway.min.svg b/projects/dejavu-parser/src/dejavu/railway.min.svg deleted file mode 100644 index d64bb70..0000000 --- a/projects/dejavu-parser/src/dejavu/railway.min.svg +++ /dev/null @@ -1,1229 +0,0 @@ - - - - - - -Root - - - -* - - - - -Element - - - - - - - - - - - -Element - - - - - - -TextElements - - - - - - - - - - TemplateExport - - - - - - - - -TemplateIf - - - - - - - - - - - -TextElements - - - - - - -TEMPLATE_E - - - - - - - - - -TEXT_SPACE - - - - - - - -TEXT_WORD - - - - - - - - - - - -TEMPLATE_E - - - -<<% - - - - - - - - - -TEXT_SPACE - - - -\p{White_Space}+ - - - - - - - - - -TEXT_WORD - - - -[^<\p{White_Space}]+ - - - - - - - - - -TEMPLATE_L - - - - -<% - - - - - -SPACE_CONTROL - - - - - - - - - - - - -TEMPLATE_R - - - - - -SPACE_CONTROL - - - - - -%> - - - - - - - - - - - -SPACE_CONTROL - - - - - -_ - - - - - - - - -- - - - - - -~ - - - - - -= - - - - - - - - - - - KW_END - - - - - end - - - - - - - - - - - TemplateExport - - - - - - - TEMPLATE_L - - - - - - - IGNORED - - - - - - - * - - - - - - ExportItem - - - - - - - - IGNORED - - - - - - - TEMPLATE_R - - - - - - - - - - - - - - - - - - ExportItem - - - - - - - KW_EXPORT - - - - - - - IGNORED - - - - - - - - Identifier - - - - - - - IGNORED - - - - - - - - - - KW_TO - - - - - - - IGNORED - - - - - - - Identifier - - - - - - - - - - - IGNORED - - - - - - - - - - - KW_BY - - - - - - - IGNORED - - - - - - - KW_CLASS - - - - - - - - - - IGNORED - - - - - - - NamepathFree - - - - - - - - - - - IGNORED - - - - - - - - - - - KW_BY - - - - - - - IGNORED - - - - - - - KW_TRAIT - - - - - - - - - - IGNORED - - - - - - - - - NamepathFree - - - - - - - - - - - - - - - - - - - - - - - - - - - KW_EXPORT - - - - - export - - - - - - - - - - - KW_CLASS - - - - - class - - - - - - - - - - - KW_TRAIT - - - - - trait - - - - - - - - - - - KW_TO - - - - - to - - - - - - - - - - - KW_BY - - - - - by - - - - - - - - - - -TemplateIf - - - - - -IfBegin - - - - - -* - - - - - IfElseIf - - - - - - - - - - - IfElse - - - - - - - - -IfEnd - - - - - - - - - - - - - - -IfBegin - - - - - - -TEMPLATE_L - - - - - -IGNORED - - - - - -KW_IF - - - - - - - - -IGNORED - - - - - - - -Atomic - - - - - -IGNORED - - - - - -TEMPLATE_R - - - - - - - - - * - - - - - - TextElements - - - - - - - - - - - - - - - - - -IfElse - - - - - - -TEMPLATE_L - - - - - -IGNORED - - - - - -KW_ELSE - - - - - -IGNORED - - - - - -TEMPLATE_R - - - - - - - - - - - * - - - - - - TextElements - - - - - - - - - - - - - - -IfElseIf - - - - - - -TEMPLATE_L - - - - - -IGNORED - - - - - -KW_ELSE - - - - - -IGNORED - - - - - -KW_IF - - - - - -IGNORED - - - - - -TEMPLATE_R - - - - - - - - - - - - - * - - - - - - TextElements - - - - - - - - - - - - - - -IfEnd - - - - - -TEMPLATE_L - - - - - -IGNORED - - - - - -KW_END - - - - - -IGNORED - - - - - - - -KW_IF - - - - - - -IGNORED - - - - - -TEMPLATE_R - - - - - - - - - - - - - - - - - -KW_IF - - - -if - - - - - - - - - -KW_ELSE - - - -else - - - - - - - - - -Atomic - - - - - - -Boolean - - - - - - - - - -Identifier - - - - - - - -Number - - - - - - - - - - - - String - - - - - - - - " - - - - - - IGNORED - - - - - - " - - - - - - - - - - - - ' - - - - - - IGNORED - - - - - - ' - - - - - - - - - - - - - - -Number - - - -0|[1-9][0-9] - - - - - - - - - - NamepathFree - - - - - - - Identifier - - - - - - - IGNORED - - - - - - * - - - - - - - - . - - - - - - - - :: - - - - - - - IGNORED - - - - - - - Identifier - - - - - - - - - - - - - - - - - - - Namepath - - - - - - -Identifier - - - - - - IGNORED - - - - - - * - - - - - - :: - - - - - - IGNORED - - - - - - - Identifier - - - - - - - - - - - - - - - - - - - Identifier - - - - - [_\p{XID_start}]\p{XID_continue}* - - - - - - - - - - - Boolean - - - - - - -true - - - - - - -false - - - - - - - - - - -WhiteSpace - - - -\p{White_Space}+ - - - - - - - - \ No newline at end of file diff --git a/projects/dejavu-parser/src/dejavu/railway.svg b/projects/dejavu-parser/src/dejavu/railway.svg deleted file mode 100644 index df5dcbc..0000000 --- a/projects/dejavu-parser/src/dejavu/railway.svg +++ /dev/null @@ -1,1291 +0,0 @@ - - - - - - -Root - - - -* - - - - -Element - - - - - - - - - - - -Element - - - - - - -TextElements - - - - - - - - - - TemplateExport - - - - - - - - -TemplateIf - - - - - - - - - - - -TextElements - - - - - - -TEMPLATE_E - - - - - - - - - -TEXT_SPACE - - - - - - - -TEXT_WORD - - - - - - - - - - - -TEMPLATE_E - - - -<<% - - - - - - - - - -TEXT_SPACE - - - -\p{White_Space}+ - - - - - - - - - -TEXT_WORD - - - -[^<\p{White_Space}]+ - - - - - - - - - -TEMPLATE_L - - - - -<% - - - - - -SPACE_CONTROL - - - - - - - - - - - - -TEMPLATE_R - - - - - -SPACE_CONTROL - - - - - -%> - - - - - - - - - - - -SPACE_CONTROL - - - - - -_ - - - - - - - - -- - - - - - -~ - - - - - -= - - - - - - - - - - - KW_END - - - - - end - - - - - - - - - - - TemplateExport - - - - - - - TEMPLATE_L - - - - - - - IGNORED - - - - - - - * - - - - - - ExportItem - - - - - - - - IGNORED - - - - - - - TEMPLATE_R - - - - - - - - - - - - - - - - - - ExportItem - - - - - - - KW_EXPORT - - - - - - - IGNORED - - - - - - - - Identifier - - - - - - - IGNORED - - - - - - - - - - KW_TO - - - - - - - IGNORED - - - - - - - Identifier - - - - - - - - - - - IGNORED - - - - - - - - - - - KW_BY - - - - - - - IGNORED - - - - - - - KW_CLASS - - - - - - - - - - IGNORED - - - - - - - NamepathFree - - - - - - - - - - - IGNORED - - - - - - - - - - - KW_BY - - - - - - - IGNORED - - - - - - - KW_TRAIT - - - - - - - - - - IGNORED - - - - - - - - - NamepathFree - - - - - - - - - - - - - - - - - - - - - - - - - - - KW_EXPORT - - - - - export - - - - - - - - - - - KW_CLASS - - - - - class - - - - - - - - - - - KW_TRAIT - - - - - trait - - - - - - - - - - - KW_TO - - - - - to - - - - - - - - - - - KW_BY - - - - - by - - - - - - - - - - -TemplateIf - - - - - -IfBegin - - - - - -* - - - - - IfElseIf - - - - - - - - - - - IfElse - - - - - - - - -IfEnd - - - - - - - - - - - - - - -IfBegin - - - - - - -TEMPLATE_L - - - - - -IGNORED - - - - - -KW_IF - - - - - - - - -IGNORED - - - - - - - -Atomic - - - - - -IGNORED - - - - - -TEMPLATE_R - - - - - - - - - * - - - - - - TextElements - - - - - - - - - - - - - - - - - -IfElse - - - - - - -TEMPLATE_L - - - - - -IGNORED - - - - - -KW_ELSE - - - - - -IGNORED - - - - - -TEMPLATE_R - - - - - - - - - - - * - - - - - - TextElements - - - - - - - - - - - - - - -IfElseIf - - - - - - -TEMPLATE_L - - - - - -IGNORED - - - - - -KW_ELSE - - - - - -IGNORED - - - - - -KW_IF - - - - - -IGNORED - - - - - -TEMPLATE_R - - - - - - - - - - - - - * - - - - - - TextElements - - - - - - - - - - - - - - -IfEnd - - - - - -TEMPLATE_L - - - - - -IGNORED - - - - - -KW_END - - - - - -IGNORED - - - - - - - -KW_IF - - - - - - -IGNORED - - - - - -TEMPLATE_R - - - - - - - - - - - - - - - - - -KW_IF - - - -if - - - - - - - - - -KW_ELSE - - - -else - - - - - - - - - -Atomic - - - - - - -Boolean - - - - - - - - - -Identifier - - - - - - - -Number - - - - - - - - - - - - String - - - - - - - - " - - - - - - IGNORED - - - - - - " - - - - - - - - - - - - ' - - - - - - IGNORED - - - - - - ' - - - - - - - - - - - - - - -Number - - - -0|[1-9][0-9] - - - - - - - - - - NamepathFree - - - - - - - Identifier - - - - - - - IGNORED - - - - - - * - - - - - - - - . - - - - - - - - :: - - - - - - - IGNORED - - - - - - - Identifier - - - - - - - - - - - - - - - - - - - Namepath - - - - - - -Identifier - - - - - - IGNORED - - - - - - * - - - - - - :: - - - - - - IGNORED - - - - - - - Identifier - - - - - - - - - - - - - - - - - - - Identifier - - - - - [_\p{XID_start}]\p{XID_continue}* - - - - - - - - - - - Boolean - - - - - - -true - - - - - - -false - - - - - - - - - - -WhiteSpace - - - -\p{White_Space}+ - - - - - - - - diff --git a/projects/dejavu-parser/src/lib.rs b/projects/dejavu-parser/src/lib.rs index 6dc3c36..d78b1b7 100644 --- a/projects/dejavu-parser/src/lib.rs +++ b/projects/dejavu-parser/src/lib.rs @@ -6,4 +6,6 @@ pub use yggdrasil_rt::{YggdrasilNode, YggdrasilParser}; -pub mod dejavu; +pub mod nexus; + + diff --git a/projects/dejavu-parser/src/dejavu/debug.ron b/projects/dejavu-parser/src/nexus/debug.ron similarity index 85% rename from projects/dejavu-parser/src/dejavu/debug.ron rename to projects/dejavu-parser/src/nexus/debug.ron index 3846cca..c1b8b67 100644 --- a/projects/dejavu-parser/src/dejavu/debug.ron +++ b/projects/dejavu-parser/src/nexus/debug.ron @@ -1,12 +1,12 @@ GrammarInfo { url: None, - name: YggdrasilIdentifier("Dejavu", 8..13), + name: YggdrasilIdentifier("Nexus", 8..12), extensions: [], imports: {}, exports: [], rules: { "Root": GrammarRule { - name: YggdrasilIdentifier("Root", 46..49), + name: YggdrasilIdentifier("Root", 45..48), redirect: None, document: "", derives: RuleDerive { @@ -25,11 +25,11 @@ GrammarInfo { body: UnaryExpression { base: YggdrasilExpression { tag: Some( - YggdrasilIdentifier("Element", 57..63), + YggdrasilIdentifier("Element", 56..62), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("Element", 57..63), + name: YggdrasilIdentifier("Element", 56..62), boxed: false, inline: false, }, @@ -40,10 +40,10 @@ GrammarInfo { }, }, }, - range: 34..66, + range: 33..65, }, "Element": GrammarRule { - name: YggdrasilIdentifier("Element", 75..81), + name: YggdrasilIdentifier("Element", 74..80), redirect: None, document: "", derives: RuleDerive { @@ -59,43 +59,43 @@ GrammarInfo { branches: [ YggdrasilExpression { tag: Some( - YggdrasilIdentifier("TextElements", 91..102), + YggdrasilIdentifier("TextElements", 90..101), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("TextElements", 91..102), + name: YggdrasilIdentifier("TextElements", 90..101), boxed: false, inline: false, }, }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("TemplateExport", 118..131), + YggdrasilIdentifier("TemplateExport", 117..130), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("TemplateExport", 118..131), + name: YggdrasilIdentifier("TemplateExport", 117..130), boxed: false, inline: false, }, }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("TemplateIf", 147..156), + YggdrasilIdentifier("TemplateIf", 146..155), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("TemplateIf", 147..156), + name: YggdrasilIdentifier("TemplateIf", 146..155), boxed: false, inline: false, }, }, ], }, - range: 69..166, + range: 68..165, }, "TextElements": GrammarRule { - name: YggdrasilIdentifier("TextElements", 295..306), + name: YggdrasilIdentifier("TextElements", 294..305), redirect: None, document: "", derives: RuleDerive { @@ -111,43 +111,43 @@ GrammarInfo { branches: [ YggdrasilExpression { tag: Some( - YggdrasilIdentifier("TemplateE", 316..325), + YggdrasilIdentifier("TemplateE", 315..324), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("TEMPLATE_E", 316..325), + name: YggdrasilIdentifier("TEMPLATE_E", 315..324), boxed: false, inline: false, }, }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("TextSpace", 341..350), + YggdrasilIdentifier("TextSpace", 340..349), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("TEXT_SPACE", 341..350), + name: YggdrasilIdentifier("TEXT_SPACE", 340..349), boxed: false, inline: false, }, }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("TextWord", 369..377), + YggdrasilIdentifier("TextWord", 368..376), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("TEXT_WORD", 369..377), + name: YggdrasilIdentifier("TEXT_WORD", 368..376), boxed: false, inline: false, }, }, ], }, - range: 289..390, + range: 288..389, }, "TEMPLATE_E": GrammarRule { - name: YggdrasilIdentifier("TEMPLATE_E", 414..423), + name: YggdrasilIdentifier("TEMPLATE_E", 413..422), redirect: None, document: "", derives: RuleDerive { @@ -166,14 +166,14 @@ GrammarInfo { body: YggdrasilText { text: "<<%", insensitive: false, - range: 431..435, + range: 430..434, }, }, }, - range: 393..437, + range: 392..436, }, "TEXT_SPACE": GrammarRule { - name: YggdrasilIdentifier("TEXT_SPACE", 446..455), + name: YggdrasilIdentifier("TEXT_SPACE", 445..454), redirect: None, document: "", derives: RuleDerive { @@ -191,14 +191,14 @@ GrammarInfo { remark: false, body: YggdrasilRegex { raw: "\\p{White_Space}+", - span: 463..480, + span: 462..479, }, }, }, - range: 440..482, + range: 439..481, }, "TEXT_WORD": GrammarRule { - name: YggdrasilIdentifier("TEXT_WORD", 490..498), + name: YggdrasilIdentifier("TEXT_WORD", 489..497), redirect: None, document: "", derives: RuleDerive { @@ -216,14 +216,14 @@ GrammarInfo { remark: false, body: YggdrasilRegex { raw: "[^<\\p{White_Space}]+", - span: 506..527, + span: 505..526, }, }, }, - range: 484..529, + range: 483..528, }, "TEMPLATE_L": GrammarRule { - name: YggdrasilIdentifier("TEMPLATE_L", 682..691), + name: YggdrasilIdentifier("TEMPLATE_L", 681..690), redirect: None, document: "", derives: RuleDerive { @@ -247,25 +247,34 @@ GrammarInfo { body: YggdrasilText { text: "<%", insensitive: false, - range: 699..702, + range: 698..701, }, }, YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("SPACE_CONTROL", 704..716), - ), + tag: None, remark: false, - body: RuleReference { - name: YggdrasilIdentifier("SPACE_CONTROL", 704..716), - boxed: false, - inline: false, + body: UnaryExpression { + base: YggdrasilExpression { + tag: Some( + YggdrasilIdentifier("SPACE_CONTROL", 703..715), + ), + remark: false, + body: RuleReference { + name: YggdrasilIdentifier("SPACE_CONTROL", 703..715), + boxed: false, + inline: false, + }, + }, + operators: [ + Optional, + ], }, }, ], }, }, }, - range: 652..718, + range: 651..718, }, "TEMPLATE_R": GrammarRule { name: YggdrasilIdentifier("TEMPLATE_R", 733..742), @@ -287,14 +296,23 @@ GrammarInfo { body: ConcatExpression { sequence: [ YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("SPACE_CONTROL", 750..762), - ), + tag: None, remark: false, - body: RuleReference { - name: YggdrasilIdentifier("SPACE_CONTROL", 750..762), - boxed: false, - inline: false, + body: UnaryExpression { + base: YggdrasilExpression { + tag: Some( + YggdrasilIdentifier("SPACE_CONTROL", 750..762), + ), + remark: false, + body: RuleReference { + name: YggdrasilIdentifier("SPACE_CONTROL", 750..762), + boxed: false, + inline: false, + }, + }, + operators: [ + Optional, + ], }, }, YggdrasilExpression { @@ -303,17 +321,17 @@ GrammarInfo { body: YggdrasilText { text: "%>", insensitive: false, - range: 764..767, + range: 765..768, }, }, ], }, }, }, - range: 720..769, + range: 720..770, }, "SPACE_CONTROL": GrammarRule { - name: YggdrasilIdentifier("SPACE_CONTROL", 777..789), + name: YggdrasilIdentifier("SPACE_CONTROL", 778..790), redirect: None, document: "", derives: RuleDerive { @@ -335,7 +353,7 @@ GrammarInfo { body: YggdrasilText { text: "_", insensitive: false, - range: 799..801, + range: 800..802, }, }, YggdrasilExpression { @@ -346,7 +364,7 @@ GrammarInfo { body: YggdrasilText { text: "-", insensitive: false, - range: 812..814, + range: 813..815, }, }, YggdrasilExpression { @@ -357,7 +375,7 @@ GrammarInfo { body: YggdrasilText { text: "~", insensitive: false, - range: 825..827, + range: 826..828, }, }, YggdrasilExpression { @@ -368,15 +386,15 @@ GrammarInfo { body: YggdrasilText { text: "=", insensitive: false, - range: 838..840, + range: 839..841, }, }, ], }, - range: 771..845, + range: 772..846, }, "KW_END": GrammarRule { - name: YggdrasilIdentifier("KW_END", 875..880), + name: YggdrasilIdentifier("KW_END", 876..881), redirect: None, document: "", derives: RuleDerive { @@ -395,14 +413,14 @@ GrammarInfo { body: YggdrasilText { text: "end", insensitive: false, - range: 883..887, + range: 884..888, }, }, }, - range: 875..887, + range: 876..888, }, "TemplateExport": GrammarRule { - name: YggdrasilIdentifier("TemplateExport", 1022..1035), + name: YggdrasilIdentifier("TemplateExport", 1023..1036), redirect: None, document: "", derives: RuleDerive { @@ -421,12 +439,10 @@ GrammarInfo { body: ConcatExpression { sequence: [ YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("TEMPLATE_L", 1045..1054), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("TEMPLATE_L", 1045..1054), + name: YggdrasilIdentifier("TEMPLATE_L", 1046..1055), boxed: false, inline: false, }, @@ -438,7 +454,7 @@ GrammarInfo { }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("exports", 1056..1062), + YggdrasilIdentifier("exports", 1057..1063), ), remark: false, body: ConcatExpression { @@ -448,12 +464,10 @@ GrammarInfo { remark: false, body: UnaryExpression { base: YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("ExportItem", 1064..1073), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("ExportItem", 1064..1073), + name: YggdrasilIdentifier("ExportItem", 1065..1074), boxed: false, inline: false, }, @@ -469,12 +483,10 @@ GrammarInfo { body: IGNORED, }, YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("TEMPLATE_R", 1076..1085), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("TEMPLATE_R", 1076..1085), + name: YggdrasilIdentifier("TEMPLATE_R", 1077..1086), boxed: false, inline: false, }, @@ -486,10 +498,10 @@ GrammarInfo { }, }, }, - range: 1016..1087, + range: 1017..1088, }, "ExportItem": GrammarRule { - name: YggdrasilIdentifier("ExportItem", 1095..1104), + name: YggdrasilIdentifier("ExportItem", 1096..1105), redirect: None, document: "", derives: RuleDerive { @@ -508,12 +520,10 @@ GrammarInfo { body: ConcatExpression { sequence: [ YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("KW_EXPORT", 1114..1122), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("KW_EXPORT", 1114..1122), + name: YggdrasilIdentifier("KW_EXPORT", 1115..1123), boxed: false, inline: false, }, @@ -525,18 +535,16 @@ GrammarInfo { }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("name", 1124..1127), + YggdrasilIdentifier("name", 1125..1128), ), remark: false, body: ConcatExpression { sequence: [ YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("Identifier", 1129..1138), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("Identifier", 1129..1138), + name: YggdrasilIdentifier("Identifier", 1130..1139), boxed: false, inline: false, }, @@ -556,12 +564,10 @@ GrammarInfo { body: ConcatExpression { sequence: [ YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("KW_TO", 1145..1149), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("KW_TO", 1145..1149), + name: YggdrasilIdentifier("KW_TO", 1146..1150), boxed: false, inline: false, }, @@ -573,11 +579,11 @@ GrammarInfo { }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("language", 1151..1158), + YggdrasilIdentifier("language", 1152..1159), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("Identifier", 1160..1169), + name: YggdrasilIdentifier("Identifier", 1161..1170), boxed: false, inline: false, }, @@ -610,12 +616,10 @@ GrammarInfo { body: ConcatExpression { sequence: [ YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("KW_BY", 1178..1182), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("KW_BY", 1178..1182), + name: YggdrasilIdentifier("KW_BY", 1179..1183), boxed: false, inline: false, }, @@ -626,12 +630,10 @@ GrammarInfo { body: IGNORED, }, YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("KW_CLASS", 1184..1191), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("KW_CLASS", 1184..1191), + name: YggdrasilIdentifier("KW_CLASS", 1185..1192), boxed: false, inline: false, }, @@ -646,11 +648,11 @@ GrammarInfo { }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("class", 1193..1197), + YggdrasilIdentifier("class", 1194..1198), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("NamepathFree", 1199..1210), + name: YggdrasilIdentifier("NamepathFree", 1200..1211), boxed: false, inline: false, }, @@ -683,12 +685,10 @@ GrammarInfo { body: ConcatExpression { sequence: [ YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("KW_BY", 1219..1223), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("KW_BY", 1219..1223), + name: YggdrasilIdentifier("KW_BY", 1220..1224), boxed: false, inline: false, }, @@ -699,12 +699,10 @@ GrammarInfo { body: IGNORED, }, YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("KW_TRAIT", 1225..1232), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("KW_TRAIT", 1225..1232), + name: YggdrasilIdentifier("KW_TRAIT", 1226..1233), boxed: false, inline: false, }, @@ -719,17 +717,15 @@ GrammarInfo { }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("trait", 1234..1238), + YggdrasilIdentifier("trait", 1235..1239), ), remark: false, body: UnaryExpression { base: YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("NamepathFree", 1240..1251), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("NamepathFree", 1240..1251), + name: YggdrasilIdentifier("NamepathFree", 1241..1252), boxed: false, inline: false, }, @@ -754,10 +750,10 @@ GrammarInfo { }, }, }, - range: 1089..1256, + range: 1090..1257, }, "KW_EXPORT": GrammarRule { - name: YggdrasilIdentifier("KW_EXPORT", 1286..1294), + name: YggdrasilIdentifier("KW_EXPORT", 1287..1295), redirect: None, document: "", derives: RuleDerive { @@ -776,14 +772,14 @@ GrammarInfo { body: YggdrasilText { text: "export", insensitive: false, - range: 1297..1304, + range: 1298..1305, }, }, }, - range: 1286..1304, + range: 1287..1305, }, "KW_CLASS": GrammarRule { - name: YggdrasilIdentifier("KW_CLASS", 1310..1317), + name: YggdrasilIdentifier("KW_CLASS", 1311..1318), redirect: None, document: "", derives: RuleDerive { @@ -802,14 +798,14 @@ GrammarInfo { body: YggdrasilText { text: "class", insensitive: false, - range: 1320..1326, + range: 1321..1327, }, }, }, - range: 1310..1326, + range: 1311..1327, }, "KW_TRAIT": GrammarRule { - name: YggdrasilIdentifier("KW_TRAIT", 1332..1339), + name: YggdrasilIdentifier("KW_TRAIT", 1333..1340), redirect: None, document: "", derives: RuleDerive { @@ -828,14 +824,14 @@ GrammarInfo { body: YggdrasilText { text: "trait", insensitive: false, - range: 1342..1348, + range: 1343..1349, }, }, }, - range: 1332..1348, + range: 1333..1349, }, "KW_TO": GrammarRule { - name: YggdrasilIdentifier("KW_TO", 1354..1358), + name: YggdrasilIdentifier("KW_TO", 1355..1359), redirect: None, document: "", derives: RuleDerive { @@ -854,14 +850,14 @@ GrammarInfo { body: YggdrasilText { text: "to", insensitive: false, - range: 1361..1364, + range: 1362..1365, }, }, }, - range: 1354..1364, + range: 1355..1365, }, "KW_BY": GrammarRule { - name: YggdrasilIdentifier("KW_BY", 1370..1374), + name: YggdrasilIdentifier("KW_BY", 1371..1375), redirect: None, document: "", derives: RuleDerive { @@ -880,14 +876,14 @@ GrammarInfo { body: YggdrasilText { text: "by", insensitive: false, - range: 1377..1380, + range: 1378..1381, }, }, }, - range: 1370..1380, + range: 1371..1381, }, "TemplateIf": GrammarRule { - name: YggdrasilIdentifier("TemplateIf", 1518..1527), + name: YggdrasilIdentifier("TemplateIf", 1519..1528), redirect: None, document: "", derives: RuleDerive { @@ -907,11 +903,11 @@ GrammarInfo { sequence: [ YggdrasilExpression { tag: Some( - YggdrasilIdentifier("IfBegin", 1535..1541), + YggdrasilIdentifier("IfBegin", 1536..1542), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("IfBegin", 1535..1541), + name: YggdrasilIdentifier("IfBegin", 1536..1542), boxed: false, inline: false, }, @@ -922,11 +918,11 @@ GrammarInfo { body: UnaryExpression { base: YggdrasilExpression { tag: Some( - YggdrasilIdentifier("IfElseIf", 1543..1550), + YggdrasilIdentifier("IfElseIf", 1544..1551), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("IfElseIf", 1543..1550), + name: YggdrasilIdentifier("IfElseIf", 1544..1551), boxed: false, inline: false, }, @@ -942,11 +938,11 @@ GrammarInfo { body: UnaryExpression { base: YggdrasilExpression { tag: Some( - YggdrasilIdentifier("IfElse", 1553..1558), + YggdrasilIdentifier("IfElse", 1554..1559), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("IfElse", 1553..1558), + name: YggdrasilIdentifier("IfElse", 1554..1559), boxed: false, inline: false, }, @@ -960,7 +956,7 @@ GrammarInfo { tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("IfEnd", 1562..1566), + name: YggdrasilIdentifier("IfEnd", 1563..1567), boxed: false, inline: false, }, @@ -969,10 +965,10 @@ GrammarInfo { }, }, }, - range: 1505..1568, + range: 1506..1569, }, "IfBegin": GrammarRule { - name: YggdrasilIdentifier("IfBegin", 1583..1589), + name: YggdrasilIdentifier("IfBegin", 1584..1590), redirect: None, document: "", derives: RuleDerive { @@ -996,12 +992,10 @@ GrammarInfo { body: ConcatExpression { sequence: [ YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("TEMPLATE_L", 1599..1608), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("TEMPLATE_L", 1599..1608), + name: YggdrasilIdentifier("TEMPLATE_L", 1600..1609), boxed: false, inline: false, }, @@ -1012,12 +1006,10 @@ GrammarInfo { body: IGNORED, }, YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("KW_IF", 1612..1616), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("KW_IF", 1612..1616), + name: YggdrasilIdentifier("KW_IF", 1613..1617), boxed: false, inline: false, }, @@ -1032,7 +1024,7 @@ GrammarInfo { }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("condition", 1620..1628), + YggdrasilIdentifier("condition", 1621..1629), ), remark: false, body: ConcatExpression { @@ -1043,12 +1035,10 @@ GrammarInfo { body: ConcatExpression { sequence: [ YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("Atomic", 1630..1635), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("Atomic", 1630..1635), + name: YggdrasilIdentifier("Atomic", 1631..1636), boxed: false, inline: false, }, @@ -1059,12 +1049,10 @@ GrammarInfo { body: IGNORED, }, YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("TEMPLATE_R", 1639..1648), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("TEMPLATE_R", 1639..1648), + name: YggdrasilIdentifier("TEMPLATE_R", 1640..1649), boxed: false, inline: false, }, @@ -1074,17 +1062,15 @@ GrammarInfo { }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("text", 1650..1653), + YggdrasilIdentifier("text", 1651..1654), ), remark: false, body: UnaryExpression { base: YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("TextElements", 1655..1666), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("TextElements", 1655..1666), + name: YggdrasilIdentifier("TextElements", 1656..1667), boxed: false, inline: false, }, @@ -1101,10 +1087,10 @@ GrammarInfo { }, }, }, - range: 1570..1669, + range: 1571..1670, }, "IfElse": GrammarRule { - name: YggdrasilIdentifier("IfElse", 1684..1689), + name: YggdrasilIdentifier("IfElse", 1685..1690), redirect: None, document: "", derives: RuleDerive { @@ -1128,12 +1114,10 @@ GrammarInfo { body: ConcatExpression { sequence: [ YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("TEMPLATE_L", 1699..1708), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("TEMPLATE_L", 1699..1708), + name: YggdrasilIdentifier("TEMPLATE_L", 1700..1709), boxed: false, inline: false, }, @@ -1144,12 +1128,10 @@ GrammarInfo { body: IGNORED, }, YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("KW_ELSE", 1712..1718), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("KW_ELSE", 1712..1718), + name: YggdrasilIdentifier("KW_ELSE", 1713..1719), boxed: false, inline: false, }, @@ -1160,12 +1142,10 @@ GrammarInfo { body: IGNORED, }, YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("TEMPLATE_R", 1722..1731), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("TEMPLATE_R", 1722..1731), + name: YggdrasilIdentifier("TEMPLATE_R", 1723..1732), boxed: false, inline: false, }, @@ -1175,17 +1155,15 @@ GrammarInfo { }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("text", 1733..1736), + YggdrasilIdentifier("text", 1734..1737), ), remark: false, body: UnaryExpression { base: YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("TextElements", 1738..1749), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("TextElements", 1738..1749), + name: YggdrasilIdentifier("TextElements", 1739..1750), boxed: false, inline: false, }, @@ -1199,10 +1177,10 @@ GrammarInfo { }, }, }, - range: 1671..1752, + range: 1672..1753, }, "IfElseIf": GrammarRule { - name: YggdrasilIdentifier("IfElseIf", 1767..1774), + name: YggdrasilIdentifier("IfElseIf", 1768..1775), redirect: None, document: "", derives: RuleDerive { @@ -1226,12 +1204,10 @@ GrammarInfo { body: ConcatExpression { sequence: [ YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("TEMPLATE_L", 1784..1793), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("TEMPLATE_L", 1784..1793), + name: YggdrasilIdentifier("TEMPLATE_L", 1785..1794), boxed: false, inline: false, }, @@ -1242,12 +1218,10 @@ GrammarInfo { body: IGNORED, }, YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("KW_ELSE", 1797..1803), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("KW_ELSE", 1797..1803), + name: YggdrasilIdentifier("KW_ELSE", 1798..1804), boxed: false, inline: false, }, @@ -1258,12 +1232,10 @@ GrammarInfo { body: IGNORED, }, YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("KW_IF", 1807..1811), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("KW_IF", 1807..1811), + name: YggdrasilIdentifier("KW_IF", 1808..1812), boxed: false, inline: false, }, @@ -1274,12 +1246,10 @@ GrammarInfo { body: IGNORED, }, YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("TEMPLATE_R", 1815..1824), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("TEMPLATE_R", 1815..1824), + name: YggdrasilIdentifier("TEMPLATE_R", 1816..1825), boxed: false, inline: false, }, @@ -1289,17 +1259,15 @@ GrammarInfo { }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("text", 1826..1829), + YggdrasilIdentifier("text", 1827..1830), ), remark: false, body: UnaryExpression { base: YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("TextElements", 1831..1842), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("TextElements", 1831..1842), + name: YggdrasilIdentifier("TextElements", 1832..1843), boxed: false, inline: false, }, @@ -1313,10 +1281,10 @@ GrammarInfo { }, }, }, - range: 1754..1845, + range: 1755..1846, }, "IfEnd": GrammarRule { - name: YggdrasilIdentifier("IfEnd", 1860..1864), + name: YggdrasilIdentifier("IfEnd", 1861..1865), redirect: None, document: "", derives: RuleDerive { @@ -1335,12 +1303,10 @@ GrammarInfo { body: ConcatExpression { sequence: [ YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("TEMPLATE_L", 1874..1883), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("TEMPLATE_L", 1874..1883), + name: YggdrasilIdentifier("TEMPLATE_L", 1875..1884), boxed: false, inline: false, }, @@ -1351,12 +1317,10 @@ GrammarInfo { body: IGNORED, }, YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("KW_END", 1887..1892), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("KW_END", 1887..1892), + name: YggdrasilIdentifier("KW_END", 1888..1893), boxed: false, inline: false, }, @@ -1371,12 +1335,10 @@ GrammarInfo { remark: false, body: UnaryExpression { base: YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("KW_IF", 1896..1900), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("KW_IF", 1896..1900), + name: YggdrasilIdentifier("KW_IF", 1897..1901), boxed: false, inline: false, }, @@ -1392,12 +1354,10 @@ GrammarInfo { body: IGNORED, }, YggdrasilExpression { - tag: Some( - YggdrasilIdentifier("TEMPLATE_R", 1905..1914), - ), + tag: None, remark: false, body: RuleReference { - name: YggdrasilIdentifier("TEMPLATE_R", 1905..1914), + name: YggdrasilIdentifier("TEMPLATE_R", 1906..1915), boxed: false, inline: false, }, @@ -1406,10 +1366,10 @@ GrammarInfo { }, }, }, - range: 1847..1916, + range: 1848..1917, }, "KW_IF": GrammarRule { - name: YggdrasilIdentifier("KW_IF", 1946..1950), + name: YggdrasilIdentifier("KW_IF", 1947..1951), redirect: None, document: "", derives: RuleDerive { @@ -1428,14 +1388,14 @@ GrammarInfo { body: YggdrasilText { text: "if", insensitive: false, - range: 1953..1956, + range: 1954..1957, }, }, }, - range: 1946..1956, + range: 1947..1957, }, "KW_ELSE": GrammarRule { - name: YggdrasilIdentifier("KW_ELSE", 1962..1968), + name: YggdrasilIdentifier("KW_ELSE", 1963..1969), redirect: None, document: "", derives: RuleDerive { @@ -1454,14 +1414,14 @@ GrammarInfo { body: YggdrasilText { text: "else", insensitive: false, - range: 1971..1976, + range: 1972..1977, }, }, }, - range: 1962..1976, + range: 1963..1977, }, "Atomic": GrammarRule { - name: YggdrasilIdentifier("Atomic", 2229..2234), + name: YggdrasilIdentifier("Atomic", 2230..2235), redirect: None, document: "", derives: RuleDerive { @@ -1477,43 +1437,43 @@ GrammarInfo { branches: [ YggdrasilExpression { tag: Some( - YggdrasilIdentifier("Boolean", 2244..2250), + YggdrasilIdentifier("Boolean", 2245..2251), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("Boolean", 2244..2250), + name: YggdrasilIdentifier("Boolean", 2245..2251), boxed: false, inline: false, }, }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("Identifier", 2258..2267), + YggdrasilIdentifier("Identifier", 2259..2268), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("Identifier", 2258..2267), + name: YggdrasilIdentifier("Identifier", 2259..2268), boxed: false, inline: false, }, }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("Number", 2275..2280), + YggdrasilIdentifier("Number", 2276..2281), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("Number", 2275..2280), + name: YggdrasilIdentifier("Number", 2276..2281), boxed: false, inline: false, }, }, ], }, - range: 2223..2282, + range: 2224..2283, }, "String": GrammarRule { - name: YggdrasilIdentifier("String", 2411..2416), + name: YggdrasilIdentifier("String", 2412..2417), redirect: None, document: "", derives: RuleDerive { @@ -1540,7 +1500,7 @@ GrammarInfo { body: YggdrasilText { text: "\"", insensitive: false, - range: 2426..2428, + range: 2427..2429, }, }, YggdrasilExpression { @@ -1554,7 +1514,7 @@ GrammarInfo { body: YggdrasilText { text: "\"", insensitive: false, - range: 2430..2432, + range: 2431..2433, }, }, ], @@ -1573,7 +1533,7 @@ GrammarInfo { body: YggdrasilText { text: "'", insensitive: false, - range: 2453..2455, + range: 2454..2456, }, }, YggdrasilExpression { @@ -1587,7 +1547,7 @@ GrammarInfo { body: YggdrasilText { text: "'", insensitive: false, - range: 2457..2459, + range: 2458..2460, }, }, ], @@ -1595,10 +1555,10 @@ GrammarInfo { }, ], }, - range: 2405..2474, + range: 2406..2475, }, "Number": GrammarRule { - name: YggdrasilIdentifier("Number", 2603..2608), + name: YggdrasilIdentifier("Number", 2604..2609), redirect: None, document: "", derives: RuleDerive { @@ -1616,14 +1576,14 @@ GrammarInfo { remark: false, body: YggdrasilRegex { raw: "0|[1-9][0-9]", - span: 2616..2629, + span: 2617..2630, }, }, }, - range: 2597..2631, + range: 2598..2632, }, "NamepathFree": GrammarRule { - name: YggdrasilIdentifier("NamepathFree", 2760..2771), + name: YggdrasilIdentifier("NamepathFree", 2761..2772), redirect: None, document: "", derives: RuleDerive { @@ -1643,11 +1603,11 @@ GrammarInfo { sequence: [ YggdrasilExpression { tag: Some( - YggdrasilIdentifier("Identifier", 2791..2800), + YggdrasilIdentifier("Identifier", 2792..2801), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("Identifier", 2791..2800), + name: YggdrasilIdentifier("Identifier", 2792..2801), boxed: false, inline: false, }, @@ -1677,7 +1637,7 @@ GrammarInfo { body: YggdrasilText { text: ".", insensitive: false, - range: 2804..2806, + range: 2805..2807, }, }, YggdrasilExpression { @@ -1686,7 +1646,7 @@ GrammarInfo { body: YggdrasilText { text: "::", insensitive: false, - range: 2810..2813, + range: 2811..2814, }, }, ], @@ -1699,11 +1659,11 @@ GrammarInfo { }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("Identifier", 2816..2825), + YggdrasilIdentifier("Identifier", 2817..2826), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("Identifier", 2816..2825), + name: YggdrasilIdentifier("Identifier", 2817..2826), boxed: false, inline: false, }, @@ -1720,10 +1680,10 @@ GrammarInfo { }, }, }, - range: 2754..2829, + range: 2755..2830, }, "Namepath": GrammarRule { - name: YggdrasilIdentifier("Namepath", 2837..2844), + name: YggdrasilIdentifier("Namepath", 2838..2845), redirect: None, document: "", derives: RuleDerive { @@ -1743,11 +1703,11 @@ GrammarInfo { sequence: [ YggdrasilExpression { tag: Some( - YggdrasilIdentifier("Identifier", 2852..2861), + YggdrasilIdentifier("Identifier", 2853..2862), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("Identifier", 2852..2861), + name: YggdrasilIdentifier("Identifier", 2853..2862), boxed: false, inline: false, }, @@ -1772,7 +1732,7 @@ GrammarInfo { body: YggdrasilText { text: "::", insensitive: false, - range: 2864..2867, + range: 2865..2868, }, }, YggdrasilExpression { @@ -1782,11 +1742,11 @@ GrammarInfo { }, YggdrasilExpression { tag: Some( - YggdrasilIdentifier("Identifier", 2869..2878), + YggdrasilIdentifier("Identifier", 2870..2879), ), remark: false, body: RuleReference { - name: YggdrasilIdentifier("Identifier", 2869..2878), + name: YggdrasilIdentifier("Identifier", 2870..2879), boxed: false, inline: false, }, @@ -1803,10 +1763,10 @@ GrammarInfo { }, }, }, - range: 2831..2882, + range: 2832..2883, }, "Identifier": GrammarRule { - name: YggdrasilIdentifier("Identifier", 2890..2899), + name: YggdrasilIdentifier("Identifier", 2891..2900), redirect: None, document: "", derives: RuleDerive { @@ -1824,14 +1784,14 @@ GrammarInfo { remark: false, body: YggdrasilRegex { raw: "[_\\p{XID_start}]\\p{XID_continue}*", - span: 2907..2941, + span: 2908..2942, }, }, }, - range: 2884..2943, + range: 2885..2944, }, "Boolean": GrammarRule { - name: YggdrasilIdentifier("Boolean", 2951..2957), + name: YggdrasilIdentifier("Boolean", 2952..2958), redirect: None, document: "", derives: RuleDerive { @@ -1853,7 +1813,7 @@ GrammarInfo { body: YggdrasilText { text: "true", insensitive: false, - range: 2967..2972, + range: 2968..2973, }, }, YggdrasilExpression { @@ -1864,15 +1824,15 @@ GrammarInfo { body: YggdrasilText { text: "false", insensitive: false, - range: 2987..2993, + range: 2988..2994, }, }, ], }, - range: 2945..3002, + range: 2946..3003, }, "WhiteSpace": GrammarRule { - name: YggdrasilIdentifier("WhiteSpace", 3138..3147), + name: YggdrasilIdentifier("WhiteSpace", 3139..3148), redirect: None, document: "", derives: RuleDerive { @@ -1890,11 +1850,11 @@ GrammarInfo { remark: false, body: YggdrasilRegex { raw: "\\p{White_Space}+", - span: 3155..3172, + span: 3156..3173, }, }, }, - range: 3125..3174, + range: 3126..3175, }, }, token_sets: {}, diff --git a/projects/dejavu-parser/src/dejavu/lexer.rs b/projects/dejavu-parser/src/nexus/lexer.rs similarity index 100% rename from projects/dejavu-parser/src/dejavu/lexer.rs rename to projects/dejavu-parser/src/nexus/lexer.rs diff --git a/projects/dejavu-parser/src/dejavu/mod.rs b/projects/dejavu-parser/src/nexus/mod.rs similarity index 86% rename from projects/dejavu-parser/src/dejavu/mod.rs rename to projects/dejavu-parser/src/nexus/mod.rs index 7bb4467..06254e3 100644 --- a/projects/dejavu-parser/src/dejavu/mod.rs +++ b/projects/dejavu-parser/src/nexus/mod.rs @@ -3,24 +3,25 @@ #![allow(clippy::unnecessary_cast)] #![doc = include_str!("readme.md")] -mod parse_ast; mod parse_cst; +mod parse_ast; +use core::str::FromStr; use std::{borrow::Cow, ops::Range, sync::OnceLock}; use yggdrasil_rt::*; -type Input<'i> = Box>; -type Output<'i> = Result>, Box>>; +type Input<'i> = Box>; +type Output<'i> = Result>, Box>>; #[doc = include_str!("railway.min.svg")] #[repr(C)] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct DejavuParser {} +pub struct NexusParser {} -impl YggdrasilParser for DejavuParser { - type Rule = DejavuRule; - fn parse_cst(input: &str, rule: Self::Rule) -> OutputResult { +impl YggdrasilParser for NexusParser { + type Rule = NexusRule; + fn parse_cst(input: &str, rule: Self::Rule) -> OutputResult { self::parse_cst::parse_cst(input, rule) } } @@ -28,7 +29,7 @@ impl YggdrasilParser for DejavuParser { #[repr(u32)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub enum DejavuRule { +pub enum NexusRule { Root, Element, TextElements, @@ -67,7 +68,7 @@ pub enum DejavuRule { IgnoreRegex, } -impl YggdrasilRule for DejavuRule { +impl YggdrasilRule for NexusRule { fn is_ignore(&self) -> bool { matches!(self, Self::IgnoreText | Self::IgnoreRegex | Self::WhiteSpace) } @@ -148,13 +149,13 @@ pub struct TextWordNode { #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TemplateLNode { - pub space_control: SpaceControlNode, + pub space_control: Option, pub span: Range, } #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TemplateRNode { - pub space_control: SpaceControlNode, + pub space_control: Option, pub span: Range, } #[derive(Clone, Debug, Hash)] @@ -165,61 +166,44 @@ pub enum SpaceControlNode { SpaceControl2, SpaceControl3, } - #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct KwEndNode { pub span: Range, } - #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TemplateExportNode { - pub export_item: Vec, - pub template_l: TemplateLNode, - pub template_r: TemplateRNode, pub span: Range, } - #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ExportItemNode { - pub identifier: IdentifierNode, - pub kw_by: Vec, - pub kw_class: KwClassNode, - pub kw_export: KwExportNode, - pub kw_to: KwToNode, - pub kw_trait: KwTraitNode, - pub namepath_free: Option, pub class: NamepathFreeNode, pub language: IdentifierNode, + pub r#trait: Option, pub span: Range, } - #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct KwExportNode { pub span: Range, } - #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct KwClassNode { pub span: Range, } - #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct KwTraitNode { pub span: Range, } - #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct KwToNode { pub span: Range, } - #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct KwByNode { @@ -236,39 +220,24 @@ pub struct TemplateIfNode { #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct IfBeginNode { - pub atomic: AtomicNode, - pub kw_if: KwIfNode, - pub template_l: TemplateLNode, - pub template_r: TemplateRNode, - pub text_elements: Vec, + pub text: Vec, pub span: Range, } #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct IfElseNode { - pub kw_else: KwElseNode, - pub template_l: TemplateLNode, - pub template_r: TemplateRNode, - pub text_elements: Vec, + pub text: Vec, pub span: Range, } #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct IfElseIfNode { - pub kw_else: KwElseNode, - pub kw_if: KwIfNode, - pub template_l: TemplateLNode, - pub template_r: TemplateRNode, - pub text_elements: Vec, + pub text: Vec, pub span: Range, } #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct IfEndNode { - pub kw_end: KwEndNode, - pub kw_if: Option, - pub template_l: TemplateLNode, - pub template_r: TemplateRNode, pub span: Range, } #[derive(Clone, Debug, Hash)] @@ -288,7 +257,6 @@ pub enum AtomicNode { Identifier(IdentifierNode), Number(NumberNode), } - #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum StringNode { @@ -300,14 +268,12 @@ pub enum StringNode { pub struct NumberNode { pub span: Range, } - #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct NamepathFreeNode { pub identifier: Vec, pub span: Range, } - #[derive(Clone, Debug, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct NamepathNode { diff --git a/projects/dejavu-parser/src/dejavu/parse_ast.rs b/projects/dejavu-parser/src/nexus/parse_ast.rs similarity index 61% rename from projects/dejavu-parser/src/dejavu/parse_ast.rs rename to projects/dejavu-parser/src/nexus/parse_ast.rs index 8eed669..aa7d7f4 100644 --- a/projects/dejavu-parser/src/dejavu/parse_ast.rs +++ b/projects/dejavu-parser/src/nexus/parse_ast.rs @@ -1,7 +1,7 @@ use super::*; #[automatically_derived] impl YggdrasilNode for RootNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -14,9 +14,18 @@ impl YggdrasilNode for RootNode { }) } } + +#[automatically_derived] +impl FromStr for RootNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::Root)?) + } +} #[automatically_derived] impl YggdrasilNode for ElementNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { match self { @@ -34,12 +43,21 @@ impl YggdrasilNode for ElementNode { if let Ok(s) = pair.take_tagged_one::(Cow::Borrowed("text_elements")) { return Ok(Self::TextElements(s)); } - Err(YggdrasilError::invalid_node(DejavuRule::Element, _span)) + Err(YggdrasilError::invalid_node(NexusRule::Element, _span)) + } +} + +#[automatically_derived] +impl FromStr for ElementNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::Element)?) } } #[automatically_derived] impl YggdrasilNode for TextElementsNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { match self { @@ -57,12 +75,21 @@ impl YggdrasilNode for TextElementsNode { if let Ok(s) = pair.take_tagged_one::(Cow::Borrowed("text_word")) { return Ok(Self::TextWord(s)); } - Err(YggdrasilError::invalid_node(DejavuRule::TextElements, _span)) + Err(YggdrasilError::invalid_node(NexusRule::TextElements, _span)) + } +} + +#[automatically_derived] +impl FromStr for TextElementsNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::TextElements)?) } } #[automatically_derived] impl YggdrasilNode for TemplateENode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -72,9 +99,18 @@ impl YggdrasilNode for TemplateENode { Ok(Self { span: Range { start: _span.start() as u32, end: _span.end() as u32 } }) } } + +#[automatically_derived] +impl FromStr for TemplateENode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::TEMPLATE_E)?) + } +} #[automatically_derived] impl YggdrasilNode for TextSpaceNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -84,9 +120,18 @@ impl YggdrasilNode for TextSpaceNode { Ok(Self { span: Range { start: _span.start() as u32, end: _span.end() as u32 } }) } } + +#[automatically_derived] +impl FromStr for TextSpaceNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::TEXT_SPACE)?) + } +} #[automatically_derived] impl YggdrasilNode for TextWordNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -96,9 +141,18 @@ impl YggdrasilNode for TextWordNode { Ok(Self { span: Range { start: _span.start() as u32, end: _span.end() as u32 } }) } } + +#[automatically_derived] +impl FromStr for TextWordNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::TEXT_WORD)?) + } +} #[automatically_derived] impl YggdrasilNode for TemplateLNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -106,14 +160,23 @@ impl YggdrasilNode for TemplateLNode { fn from_pair(pair: TokenPair) -> Result> { let _span = pair.get_span(); Ok(Self { - space_control: pair.take_tagged_one::(Cow::Borrowed("space_control"))?, + space_control: pair.take_tagged_option::(Cow::Borrowed("space_control")), span: Range { start: _span.start() as u32, end: _span.end() as u32 }, }) } } + +#[automatically_derived] +impl FromStr for TemplateLNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::TEMPLATE_L)?) + } +} #[automatically_derived] impl YggdrasilNode for TemplateRNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -121,14 +184,23 @@ impl YggdrasilNode for TemplateRNode { fn from_pair(pair: TokenPair) -> Result> { let _span = pair.get_span(); Ok(Self { - space_control: pair.take_tagged_one::(Cow::Borrowed("space_control"))?, + space_control: pair.take_tagged_option::(Cow::Borrowed("space_control")), span: Range { start: _span.start() as u32, end: _span.end() as u32 }, }) } } + +#[automatically_derived] +impl FromStr for TemplateRNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::TEMPLATE_R)?) + } +} #[automatically_derived] impl YggdrasilNode for SpaceControlNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { match self { @@ -149,13 +221,21 @@ impl YggdrasilNode for SpaceControlNode { if let Some(_) = pair.find_first_tag("space_control_3") { return Ok(Self::SpaceControl3); } - Err(YggdrasilError::invalid_node(DejavuRule::SPACE_CONTROL, _span)) + Err(YggdrasilError::invalid_node(NexusRule::SPACE_CONTROL, _span)) } } +#[automatically_derived] +impl FromStr for SpaceControlNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::SPACE_CONTROL)?) + } +} #[automatically_derived] impl YggdrasilNode for KwEndNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -166,27 +246,38 @@ impl YggdrasilNode for KwEndNode { } } +#[automatically_derived] +impl FromStr for KwEndNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::KW_END)?) + } +} #[automatically_derived] impl YggdrasilNode for TemplateExportNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) } fn from_pair(pair: TokenPair) -> Result> { let _span = pair.get_span(); - Ok(Self { - export_item: pair.take_tagged_items::(Cow::Borrowed("export_item"))?, - template_l: pair.take_tagged_one::(Cow::Borrowed("template_l"))?, - template_r: pair.take_tagged_one::(Cow::Borrowed("template_r"))?, - span: Range { start: _span.start() as u32, end: _span.end() as u32 }, - }) + Ok(Self { span: Range { start: _span.start() as u32, end: _span.end() as u32 } }) } } +#[automatically_derived] +impl FromStr for TemplateExportNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::TemplateExport)?) + } +} #[automatically_derived] impl YggdrasilNode for ExportItemNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -194,23 +285,25 @@ impl YggdrasilNode for ExportItemNode { fn from_pair(pair: TokenPair) -> Result> { let _span = pair.get_span(); Ok(Self { - identifier: pair.take_tagged_one::(Cow::Borrowed("identifier"))?, - kw_by: pair.take_tagged_items::(Cow::Borrowed("kw_by"))?, - kw_class: pair.take_tagged_one::(Cow::Borrowed("kw_class"))?, - kw_export: pair.take_tagged_one::(Cow::Borrowed("kw_export"))?, - kw_to: pair.take_tagged_one::(Cow::Borrowed("kw_to"))?, - kw_trait: pair.take_tagged_one::(Cow::Borrowed("kw_trait"))?, - namepath_free: pair.take_tagged_option::(Cow::Borrowed("namepath_free")), class: pair.take_tagged_one::(Cow::Borrowed("class"))?, language: pair.take_tagged_one::(Cow::Borrowed("language"))?, + r#trait: pair.take_tagged_option::(Cow::Borrowed("trait")), span: Range { start: _span.start() as u32, end: _span.end() as u32 }, }) } } +#[automatically_derived] +impl FromStr for ExportItemNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::ExportItem)?) + } +} #[automatically_derived] impl YggdrasilNode for KwExportNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -221,9 +314,17 @@ impl YggdrasilNode for KwExportNode { } } +#[automatically_derived] +impl FromStr for KwExportNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::KW_EXPORT)?) + } +} #[automatically_derived] impl YggdrasilNode for KwClassNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -234,9 +335,17 @@ impl YggdrasilNode for KwClassNode { } } +#[automatically_derived] +impl FromStr for KwClassNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::KW_CLASS)?) + } +} #[automatically_derived] impl YggdrasilNode for KwTraitNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -247,9 +356,17 @@ impl YggdrasilNode for KwTraitNode { } } +#[automatically_derived] +impl FromStr for KwTraitNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::KW_TRAIT)?) + } +} #[automatically_derived] impl YggdrasilNode for KwToNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -260,9 +377,17 @@ impl YggdrasilNode for KwToNode { } } +#[automatically_derived] +impl FromStr for KwToNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::KW_TO)?) + } +} #[automatically_derived] impl YggdrasilNode for KwByNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -272,9 +397,18 @@ impl YggdrasilNode for KwByNode { Ok(Self { span: Range { start: _span.start() as u32, end: _span.end() as u32 } }) } } + +#[automatically_derived] +impl FromStr for KwByNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::KW_BY)?) + } +} #[automatically_derived] impl YggdrasilNode for TemplateIfNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -289,9 +423,18 @@ impl YggdrasilNode for TemplateIfNode { }) } } + +#[automatically_derived] +impl FromStr for TemplateIfNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::TemplateIf)?) + } +} #[automatically_derived] impl YggdrasilNode for IfBeginNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -299,18 +442,23 @@ impl YggdrasilNode for IfBeginNode { fn from_pair(pair: TokenPair) -> Result> { let _span = pair.get_span(); Ok(Self { - atomic: pair.take_tagged_one::(Cow::Borrowed("atomic"))?, - kw_if: pair.take_tagged_one::(Cow::Borrowed("kw_if"))?, - template_l: pair.take_tagged_one::(Cow::Borrowed("template_l"))?, - template_r: pair.take_tagged_one::(Cow::Borrowed("template_r"))?, - text_elements: pair.take_tagged_items::(Cow::Borrowed("text_elements"))?, + text: pair.take_tagged_items::(Cow::Borrowed("text"))?, span: Range { start: _span.start() as u32, end: _span.end() as u32 }, }) } } + +#[automatically_derived] +impl FromStr for IfBeginNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::IfBegin)?) + } +} #[automatically_derived] impl YggdrasilNode for IfElseNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -318,17 +466,23 @@ impl YggdrasilNode for IfElseNode { fn from_pair(pair: TokenPair) -> Result> { let _span = pair.get_span(); Ok(Self { - kw_else: pair.take_tagged_one::(Cow::Borrowed("kw_else"))?, - template_l: pair.take_tagged_one::(Cow::Borrowed("template_l"))?, - template_r: pair.take_tagged_one::(Cow::Borrowed("template_r"))?, - text_elements: pair.take_tagged_items::(Cow::Borrowed("text_elements"))?, + text: pair.take_tagged_items::(Cow::Borrowed("text"))?, span: Range { start: _span.start() as u32, end: _span.end() as u32 }, }) } } + +#[automatically_derived] +impl FromStr for IfElseNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::IfElse)?) + } +} #[automatically_derived] impl YggdrasilNode for IfElseIfNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -336,36 +490,44 @@ impl YggdrasilNode for IfElseIfNode { fn from_pair(pair: TokenPair) -> Result> { let _span = pair.get_span(); Ok(Self { - kw_else: pair.take_tagged_one::(Cow::Borrowed("kw_else"))?, - kw_if: pair.take_tagged_one::(Cow::Borrowed("kw_if"))?, - template_l: pair.take_tagged_one::(Cow::Borrowed("template_l"))?, - template_r: pair.take_tagged_one::(Cow::Borrowed("template_r"))?, - text_elements: pair.take_tagged_items::(Cow::Borrowed("text_elements"))?, + text: pair.take_tagged_items::(Cow::Borrowed("text"))?, span: Range { start: _span.start() as u32, end: _span.end() as u32 }, }) } } + +#[automatically_derived] +impl FromStr for IfElseIfNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::IfElseIf)?) + } +} #[automatically_derived] impl YggdrasilNode for IfEndNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) } fn from_pair(pair: TokenPair) -> Result> { let _span = pair.get_span(); - Ok(Self { - kw_end: pair.take_tagged_one::(Cow::Borrowed("kw_end"))?, - kw_if: pair.take_tagged_option::(Cow::Borrowed("kw_if")), - template_l: pair.take_tagged_one::(Cow::Borrowed("template_l"))?, - template_r: pair.take_tagged_one::(Cow::Borrowed("template_r"))?, - span: Range { start: _span.start() as u32, end: _span.end() as u32 }, - }) + Ok(Self { span: Range { start: _span.start() as u32, end: _span.end() as u32 } }) + } +} + +#[automatically_derived] +impl FromStr for IfEndNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::IfEnd)?) } } #[automatically_derived] impl YggdrasilNode for KwIfNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -375,9 +537,18 @@ impl YggdrasilNode for KwIfNode { Ok(Self { span: Range { start: _span.start() as u32, end: _span.end() as u32 } }) } } + +#[automatically_derived] +impl FromStr for KwIfNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::KW_IF)?) + } +} #[automatically_derived] impl YggdrasilNode for KwElseNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -387,9 +558,18 @@ impl YggdrasilNode for KwElseNode { Ok(Self { span: Range { start: _span.start() as u32, end: _span.end() as u32 } }) } } + +#[automatically_derived] +impl FromStr for KwElseNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::KW_ELSE)?) + } +} #[automatically_derived] impl YggdrasilNode for AtomicNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { match self { @@ -407,13 +587,21 @@ impl YggdrasilNode for AtomicNode { if let Ok(s) = pair.take_tagged_one::(Cow::Borrowed("number")) { return Ok(Self::Number(s)); } - Err(YggdrasilError::invalid_node(DejavuRule::Atomic, _span)) + Err(YggdrasilError::invalid_node(NexusRule::Atomic, _span)) } } +#[automatically_derived] +impl FromStr for AtomicNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::Atomic)?) + } +} #[automatically_derived] impl YggdrasilNode for StringNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { match self { @@ -428,12 +616,21 @@ impl YggdrasilNode for StringNode { if let Some(_) = pair.find_first_tag("string_1") { return Ok(Self::String1); } - Err(YggdrasilError::invalid_node(DejavuRule::String, _span)) + Err(YggdrasilError::invalid_node(NexusRule::String, _span)) + } +} + +#[automatically_derived] +impl FromStr for StringNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::String)?) } } #[automatically_derived] impl YggdrasilNode for NumberNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -443,9 +640,18 @@ impl YggdrasilNode for NumberNode { Ok(Self { span: Range { start: _span.start() as u32, end: _span.end() as u32 } }) } } + +#[automatically_derived] +impl FromStr for NumberNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::Number)?) + } +} #[automatically_derived] impl YggdrasilNode for NamepathFreeNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -459,9 +665,17 @@ impl YggdrasilNode for NamepathFreeNode { } } +#[automatically_derived] +impl FromStr for NamepathFreeNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::NamepathFree)?) + } +} #[automatically_derived] impl YggdrasilNode for NamepathNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -475,9 +689,17 @@ impl YggdrasilNode for NamepathNode { } } +#[automatically_derived] +impl FromStr for NamepathNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::Namepath)?) + } +} #[automatically_derived] impl YggdrasilNode for IdentifierNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -487,9 +709,18 @@ impl YggdrasilNode for IdentifierNode { Ok(Self { span: Range { start: _span.start() as u32, end: _span.end() as u32 } }) } } + +#[automatically_derived] +impl FromStr for IdentifierNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::Identifier)?) + } +} #[automatically_derived] impl YggdrasilNode for BooleanNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { match self { @@ -504,12 +735,21 @@ impl YggdrasilNode for BooleanNode { if let Some(_) = pair.find_first_tag("boolean_1") { return Ok(Self::Boolean1); } - Err(YggdrasilError::invalid_node(DejavuRule::Boolean, _span)) + Err(YggdrasilError::invalid_node(NexusRule::Boolean, _span)) + } +} + +#[automatically_derived] +impl FromStr for BooleanNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::Boolean)?) } } #[automatically_derived] impl YggdrasilNode for WhiteSpaceNode { - type Rule = DejavuRule; + type Rule = NexusRule; fn get_range(&self) -> Option> { Some(Range { start: self.span.start as usize, end: self.span.end as usize }) @@ -519,3 +759,12 @@ impl YggdrasilNode for WhiteSpaceNode { Ok(Self { span: Range { start: _span.start() as u32, end: _span.end() as u32 } }) } } + +#[automatically_derived] +impl FromStr for WhiteSpaceNode { + type Err = YggdrasilError; + + fn from_str(input: &str) -> Result> { + Self::from_cst(NexusParser::parse_cst(input, NexusRule::WhiteSpace)?) + } +} diff --git a/projects/dejavu-parser/src/nexus/parse_cst.rs b/projects/dejavu-parser/src/nexus/parse_cst.rs new file mode 100644 index 0000000..d08a6e0 --- /dev/null +++ b/projects/dejavu-parser/src/nexus/parse_cst.rs @@ -0,0 +1,252 @@ +use super::*; + +pub(super) fn parse_cst(input: &str, rule: NexusRule) -> OutputResult { + state(input, |state| match rule { + NexusRule::Root => parse_root(state), + NexusRule::Element => parse_element(state), + NexusRule::TextElements => parse_text_elements(state), + NexusRule::TEMPLATE_E => parse_template_e(state), + NexusRule::TEXT_SPACE => parse_text_space(state), + NexusRule::TEXT_WORD => parse_text_word(state), + NexusRule::TEMPLATE_L => parse_template_l(state), + NexusRule::TEMPLATE_R => parse_template_r(state), + NexusRule::SPACE_CONTROL => parse_space_control(state), + NexusRule::KW_END => parse_kw_end(state), + NexusRule::TemplateExport => parse_template_export(state), + NexusRule::ExportItem => parse_export_item(state), + NexusRule::KW_EXPORT => parse_kw_export(state), + NexusRule::KW_CLASS => parse_kw_class(state), + NexusRule::KW_TRAIT => parse_kw_trait(state), + NexusRule::KW_TO => parse_kw_to(state), + NexusRule::KW_BY => parse_kw_by(state), + NexusRule::TemplateIf => parse_template_if(state), + NexusRule::IfBegin => parse_if_begin(state), + NexusRule::IfElse => parse_if_else(state), + NexusRule::IfElseIf => parse_if_else_if(state), + NexusRule::IfEnd => parse_if_end(state), + NexusRule::KW_IF => parse_kw_if(state), + NexusRule::KW_ELSE => parse_kw_else(state), + NexusRule::Atomic => parse_atomic(state), + NexusRule::String => parse_string(state), + NexusRule::Number => parse_number(state), + NexusRule::NamepathFree => parse_namepath_free(state), + NexusRule::Namepath => parse_namepath(state), + NexusRule::Identifier => parse_identifier(state), + NexusRule::Boolean => parse_boolean(state), + NexusRule::WhiteSpace => parse_white_space(state), + NexusRule::IgnoreText => unreachable!(), + NexusRule::IgnoreRegex => unreachable!(), + }) +} +#[inline] +fn parse_root(state: Input) -> Output { + state.rule(NexusRule::Root, |s| { + s.repeat(0..4294967295, |s|parse_element(s).and_then(|s| s.tag_node("element"))) + }) +} +#[inline] +fn parse_element(state: Input) -> Output { + state.rule(NexusRule::Element, |s| { + Err(s).or_else(|s|parse_text_elements(s).and_then(|s| s.tag_node("text_elements"))).or_else(|s|parse_template_export(s).and_then(|s| s.tag_node("template_export"))).or_else(|s|parse_template_if(s).and_then(|s| s.tag_node("template_if"))) + }) +} +#[inline] +fn parse_text_elements(state: Input) -> Output { + state.rule(NexusRule::TextElements, |s| { + Err(s).or_else(|s|parse_template_e(s).and_then(|s| s.tag_node("template_e"))).or_else(|s|parse_text_space(s).and_then(|s| s.tag_node("text_space"))).or_else(|s|parse_text_word(s).and_then(|s| s.tag_node("text_word"))) + }) +} +#[inline] +fn parse_template_e(state: Input) -> Output { + state.rule(NexusRule::TEMPLATE_E, |s| { + s.match_string("<<%", false) + }) +} +#[inline] +fn parse_text_space(state: Input) -> Output { + state.rule(NexusRule::TEXT_SPACE, |s| { + s.match_regex({static REGEX:OnceLock=OnceLock::new();REGEX.get_or_init(|| Regex::new("^(\\p{White_Space}+)").unwrap())}) + }) +} +#[inline] +fn parse_text_word(state: Input) -> Output { + state.rule(NexusRule::TEXT_WORD, |s| { + s.match_regex({static REGEX:OnceLock=OnceLock::new();REGEX.get_or_init(|| Regex::new("^([^<\\p{White_Space}]+)").unwrap())}) + }) +} +#[inline] +fn parse_template_l(state: Input) -> Output { + state.rule(NexusRule::TEMPLATE_L, |s| { + s.sequence(|s|Ok(s).and_then(|s|builtin_text(s, "<%", false)).and_then(|s|s.optional(|s|parse_space_control(s).and_then(|s| s.tag_node("space_control"))))) + }) +} +#[inline] +fn parse_template_r(state: Input) -> Output { + state.rule(NexusRule::TEMPLATE_R, |s| { + s.sequence(|s|Ok(s).and_then(|s|s.optional(|s|parse_space_control(s).and_then(|s| s.tag_node("space_control")))).and_then(|s|builtin_text(s, "%>", false))) + }) +} +#[inline] +fn parse_space_control(state: Input) -> Output { + state.rule(NexusRule::SPACE_CONTROL, |s| { + Err(s).or_else(|s|builtin_text(s, "_", false).and_then(|s| s.tag_node("space_control_0"))).or_else(|s|builtin_text(s, "-", false).and_then(|s| s.tag_node("space_control_1"))).or_else(|s|builtin_text(s, "~", false).and_then(|s| s.tag_node("space_control_2"))).or_else(|s|builtin_text(s, "=", false).and_then(|s| s.tag_node("space_control_3"))) + }) +} +#[inline] +fn parse_kw_end(state: Input) -> Output { + state.rule(NexusRule::KW_END, |s| { + s.match_string("end", false) + }) +} +#[inline] +fn parse_template_export(state: Input) -> Output { + state.rule(NexusRule::TemplateExport, |s| { + s.sequence(|s|Ok(s).and_then(|s|parse_template_l(s)).and_then(|s|builtin_ignore(s)).and_then(|s|s.sequence(|s|Ok(s).and_then(|s|s.repeat(0..4294967295, |s|parse_export_item(s))).and_then(|s|builtin_ignore(s)).and_then(|s|parse_template_r(s))).and_then(|s| s.tag_node("exports")))) + }) +} +#[inline] +fn parse_export_item(state: Input) -> Output { + state.rule(NexusRule::ExportItem, |s| { + s.sequence(|s|Ok(s).and_then(|s|parse_kw_export(s)).and_then(|s|builtin_ignore(s)).and_then(|s|s.sequence(|s|Ok(s).and_then(|s|parse_identifier(s)).and_then(|s|builtin_ignore(s)).and_then(|s|s.optional(|s|s.sequence(|s|Ok(s).and_then(|s|parse_kw_to(s)).and_then(|s|builtin_ignore(s)).and_then(|s|parse_identifier(s).and_then(|s| s.tag_node("language")))))).and_then(|s|builtin_ignore(s)).and_then(|s|s.optional(|s|s.sequence(|s|Ok(s).and_then(|s|s.sequence(|s|Ok(s).and_then(|s|parse_kw_by(s)).and_then(|s|builtin_ignore(s)).and_then(|s|parse_kw_class(s)))).and_then(|s|builtin_ignore(s)).and_then(|s|parse_namepath_free(s).and_then(|s| s.tag_node("class")))))).and_then(|s|builtin_ignore(s)).and_then(|s|s.optional(|s|s.sequence(|s|Ok(s).and_then(|s|s.sequence(|s|Ok(s).and_then(|s|parse_kw_by(s)).and_then(|s|builtin_ignore(s)).and_then(|s|parse_kw_trait(s)))).and_then(|s|builtin_ignore(s)).and_then(|s|s.optional(|s|parse_namepath_free(s)).and_then(|s| s.tag_node("trait"))))))).and_then(|s| s.tag_node("name")))) + }) +} +#[inline] +fn parse_kw_export(state: Input) -> Output { + state.rule(NexusRule::KW_EXPORT, |s| { + s.match_string("export", false) + }) +} +#[inline] +fn parse_kw_class(state: Input) -> Output { + state.rule(NexusRule::KW_CLASS, |s| { + s.match_string("class", false) + }) +} +#[inline] +fn parse_kw_trait(state: Input) -> Output { + state.rule(NexusRule::KW_TRAIT, |s| { + s.match_string("trait", false) + }) +} +#[inline] +fn parse_kw_to(state: Input) -> Output { + state.rule(NexusRule::KW_TO, |s| { + s.match_string("to", false) + }) +} +#[inline] +fn parse_kw_by(state: Input) -> Output { + state.rule(NexusRule::KW_BY, |s| { + s.match_string("by", false) + }) +} +#[inline] +fn parse_template_if(state: Input) -> Output { + state.rule(NexusRule::TemplateIf, |s| { + s.sequence(|s|Ok(s).and_then(|s|parse_if_begin(s).and_then(|s| s.tag_node("if_begin"))).and_then(|s|s.repeat(0..4294967295, |s|parse_if_else_if(s).and_then(|s| s.tag_node("if_else_if")))).and_then(|s|s.optional(|s|parse_if_else(s).and_then(|s| s.tag_node("if_else")))).and_then(|s|parse_if_end(s))) + }) +} +#[inline] +fn parse_if_begin(state: Input) -> Output { + state.rule(NexusRule::IfBegin, |s| { + s.sequence(|s|Ok(s).and_then(|s|s.sequence(|s|Ok(s).and_then(|s|parse_template_l(s)).and_then(|s|builtin_ignore(s)).and_then(|s|parse_kw_if(s)))).and_then(|s|builtin_ignore(s)).and_then(|s|s.sequence(|s|Ok(s).and_then(|s|s.sequence(|s|Ok(s).and_then(|s|parse_atomic(s)).and_then(|s|builtin_ignore(s)).and_then(|s|parse_template_r(s)))).and_then(|s|s.repeat(0..4294967295, |s|parse_text_elements(s)).and_then(|s| s.tag_node("text")))).and_then(|s| s.tag_node("condition")))) + }) +} +#[inline] +fn parse_if_else(state: Input) -> Output { + state.rule(NexusRule::IfElse, |s| { + s.sequence(|s|Ok(s).and_then(|s|s.sequence(|s|Ok(s).and_then(|s|parse_template_l(s)).and_then(|s|builtin_ignore(s)).and_then(|s|parse_kw_else(s)).and_then(|s|builtin_ignore(s)).and_then(|s|parse_template_r(s)))).and_then(|s|s.repeat(0..4294967295, |s|parse_text_elements(s)).and_then(|s| s.tag_node("text")))) + }) +} +#[inline] +fn parse_if_else_if(state: Input) -> Output { + state.rule(NexusRule::IfElseIf, |s| { + s.sequence(|s|Ok(s).and_then(|s|s.sequence(|s|Ok(s).and_then(|s|parse_template_l(s)).and_then(|s|builtin_ignore(s)).and_then(|s|parse_kw_else(s)).and_then(|s|builtin_ignore(s)).and_then(|s|parse_kw_if(s)).and_then(|s|builtin_ignore(s)).and_then(|s|parse_template_r(s)))).and_then(|s|s.repeat(0..4294967295, |s|parse_text_elements(s)).and_then(|s| s.tag_node("text")))) + }) +} +#[inline] +fn parse_if_end(state: Input) -> Output { + state.rule(NexusRule::IfEnd, |s| { + s.sequence(|s|Ok(s).and_then(|s|parse_template_l(s)).and_then(|s|builtin_ignore(s)).and_then(|s|parse_kw_end(s)).and_then(|s|builtin_ignore(s)).and_then(|s|s.optional(|s|parse_kw_if(s))).and_then(|s|builtin_ignore(s)).and_then(|s|parse_template_r(s))) + }) +} +#[inline] +fn parse_kw_if(state: Input) -> Output { + state.rule(NexusRule::KW_IF, |s| { + s.match_string("if", false) + }) +} +#[inline] +fn parse_kw_else(state: Input) -> Output { + state.rule(NexusRule::KW_ELSE, |s| { + s.match_string("else", false) + }) +} +#[inline] +fn parse_atomic(state: Input) -> Output { + state.rule(NexusRule::Atomic, |s| { + Err(s).or_else(|s|parse_boolean(s).and_then(|s| s.tag_node("boolean"))).or_else(|s|parse_identifier(s).and_then(|s| s.tag_node("identifier"))).or_else(|s|parse_number(s).and_then(|s| s.tag_node("number"))) + }) +} +#[inline] +fn parse_string(state: Input) -> Output { + state.rule(NexusRule::String, |s| { + Err(s).or_else(|s|s.sequence(|s|Ok(s).and_then(|s|builtin_text(s, "\"", false)).and_then(|s|builtin_ignore(s)).and_then(|s|builtin_text(s, "\"", false))).and_then(|s| s.tag_node("string_0"))).or_else(|s|s.sequence(|s|Ok(s).and_then(|s|builtin_text(s, "'", false)).and_then(|s|builtin_ignore(s)).and_then(|s|builtin_text(s, "'", false))).and_then(|s| s.tag_node("string_1"))) + }) +} +#[inline] +fn parse_number(state: Input) -> Output { + state.rule(NexusRule::Number, |s| { + s.match_regex({static REGEX:OnceLock=OnceLock::new();REGEX.get_or_init(|| Regex::new("^(0|[1-9][0-9])").unwrap())}) + }) +} +#[inline] +fn parse_namepath_free(state: Input) -> Output { + state.rule(NexusRule::NamepathFree, |s| { + s.sequence(|s|Ok(s).and_then(|s|parse_identifier(s).and_then(|s| s.tag_node("identifier"))).and_then(|s|builtin_ignore(s)).and_then(|s|s.repeat(0..4294967295, |s|s.sequence(|s|Ok(s).and_then(|s|Err(s).or_else(|s|builtin_text(s, ".", false)).or_else(|s|builtin_text(s, "::", false))).and_then(|s|builtin_ignore(s)).and_then(|s|parse_identifier(s).and_then(|s| s.tag_node("identifier"))))))) + }) +} +#[inline] +fn parse_namepath(state: Input) -> Output { + state.rule(NexusRule::Namepath, |s| { + s.sequence(|s|Ok(s).and_then(|s|parse_identifier(s).and_then(|s| s.tag_node("identifier"))).and_then(|s|builtin_ignore(s)).and_then(|s|s.repeat(0..4294967295, |s|s.sequence(|s|Ok(s).and_then(|s|builtin_text(s, "::", false)).and_then(|s|builtin_ignore(s)).and_then(|s|parse_identifier(s).and_then(|s| s.tag_node("identifier"))))))) + }) +} +#[inline] +fn parse_identifier(state: Input) -> Output { + state.rule(NexusRule::Identifier, |s| { + s.match_regex({static REGEX:OnceLock=OnceLock::new();REGEX.get_or_init(|| Regex::new("^([_\\p{XID_start}]\\p{XID_continue}*)").unwrap())}) + }) +} +#[inline] +fn parse_boolean(state: Input) -> Output { + state.rule(NexusRule::Boolean, |s| { + Err(s).or_else(|s|builtin_text(s, "true", false).and_then(|s| s.tag_node("boolean_0"))).or_else(|s|builtin_text(s, "false", false).and_then(|s| s.tag_node("boolean_1"))) + }) +} +#[inline] +fn parse_white_space(state: Input) -> Output { + state.rule(NexusRule::WhiteSpace, |s| { + s.match_regex({static REGEX:OnceLock=OnceLock::new();REGEX.get_or_init(|| Regex::new("^(\\p{White_Space}+)").unwrap())}) + }) +} + +/// All rules ignored in ast mode, inline is not recommended +fn builtin_ignore(state: Input) -> Output { + state.repeat(0..u32::MAX, |s| { + parse_white_space(s) + }) + +} + +fn builtin_any(state: Input) -> Output { + state.rule(NexusRule::IgnoreText, |s| s.match_char_if(|_| true)) +} + +fn builtin_text<'i>(state: Input<'i>, text: &'static str, case: bool) -> Output<'i> { + state.rule(NexusRule::IgnoreText, |s| s.match_string(text, case)) +} + +fn builtin_regex<'i, 'r>(state: Input<'i>, regex: &'r Regex) -> Output<'i> { + state.rule(NexusRule::IgnoreRegex, |s| s.match_regex(regex)) +} \ No newline at end of file diff --git a/projects/dejavu-parser/src/nexus/railway.min.svg b/projects/dejavu-parser/src/nexus/railway.min.svg new file mode 100644 index 0000000..159499d --- /dev/null +++ b/projects/dejavu-parser/src/nexus/railway.min.svg @@ -0,0 +1,1162 @@ + + + + + + +Root + + + +* + + + + +Element + + + + + + + + + + + +Element + + + + + + +TextElements + + + + + + + + + +TemplateExport + + + + + + + +TemplateIf + + + + + + + + + + + +TextElements + + + + + + +TEMPLATE_E + + + + + + + + + +TEXT_SPACE + + + + + + + +TEXT_WORD + + + + + + + + + + + +TEMPLATE_E + + + +<<% + + + + + + + + + +TEXT_SPACE + + + +\p{White_Space}+ + + + + + + + + + +TEXT_WORD + + + +[^<\p{White_Space}]+ + + + + + + + + + +TEMPLATE_L + + + + +<% + + + + + + + +SPACE_CONTROL + + + + + + + + + + + + + +TEMPLATE_R + + + + + + + +SPACE_CONTROL + + + + + + +%> + + + + + + + + + + + +SPACE_CONTROL + + + + + +_ + + + + + + + + +- + + + + + +~ + + + + + += + + + + + + + + + + +KW_END + + + +end + + + + + + + + + +TemplateExport + + + + + +TEMPLATE_L + + + + + +IGNORED + + + + + +* + + + + +ExportItem + + + + + + +IGNORED + + + + + +TEMPLATE_R + + + + + + + + + + + + + + + + +ExportItem + + + + + +KW_EXPORT + + + + + +IGNORED + + + + + + +Identifier + + + + + +IGNORED + + + + + + + + +KW_TO + + + + + +IGNORED + + + + + +Identifier + + + + + + + + + +IGNORED + + + + + + + + + +KW_BY + + + + + +IGNORED + + + + + +KW_CLASS + + + + + + + + +IGNORED + + + + + +NamepathFree + + + + + + + + + +IGNORED + + + + + + + + + +KW_BY + + + + + +IGNORED + + + + + +KW_TRAIT + + + + + + + + +IGNORED + + + + + + + +NamepathFree + + + + + + + + + + + + + + + + + + + + + + + + + +KW_EXPORT + + + +export + + + + + + + + + +KW_CLASS + + + +class + + + + + + + + + +KW_TRAIT + + + +trait + + + + + + + + + +KW_TO + + + +to + + + + + + + + + +KW_BY + + + +by + + + + + + + + + +TemplateIf + + + + + +IfBegin + + + + + +* + + + + +IfElseIf + + + + + + + + + +IfElse + + + + + + + +IfEnd + + + + + + + + + + + + + + +IfBegin + + + + + + +TEMPLATE_L + + + + + +IGNORED + + + + + +KW_IF + + + + + + + + +IGNORED + + + + + + + +Atomic + + + + + +IGNORED + + + + + +TEMPLATE_R + + + + + + + + +* + + + + +TextElements + + + + + + + + + + + + + + + + +IfElse + + + + + + +TEMPLATE_L + + + + + +IGNORED + + + + + +KW_ELSE + + + + + +IGNORED + + + + + +TEMPLATE_R + + + + + + + + + + +* + + + + +TextElements + + + + + + + + + + + + + +IfElseIf + + + + + + +TEMPLATE_L + + + + + +IGNORED + + + + + +KW_ELSE + + + + + +IGNORED + + + + + +KW_IF + + + + + +IGNORED + + + + + +TEMPLATE_R + + + + + + + + + + + + +* + + + + +TextElements + + + + + + + + + + + + + +IfEnd + + + + + +TEMPLATE_L + + + + + +IGNORED + + + + + +KW_END + + + + + +IGNORED + + + + + + + +KW_IF + + + + + + +IGNORED + + + + + +TEMPLATE_R + + + + + + + + + + + + + + + + + +KW_IF + + + +if + + + + + + + + + +KW_ELSE + + + +else + + + + + + + + + +Atomic + + + + + + +Boolean + + + + + + + + + +Identifier + + + + + + + +Number + + + + + + + + + + + +String + + + + + + +" + + + + +IGNORED + + + + +" + + + + + + + + + + +' + + + + +IGNORED + + + + +' + + + + + + + + + + + + + +Number + + + +0|[1-9][0-9] + + + + + + + + + +NamepathFree + + + + + +Identifier + + + + + +IGNORED + + + + +* + + + + + + +. + + + + + + +:: + + + + + +IGNORED + + + + + +Identifier + + + + + + + + + + + + + + + + + +Namepath + + + + + +Identifier + + + + + +IGNORED + + + + +* + + + + +:: + + + + +IGNORED + + + + + +Identifier + + + + + + + + + + + + + + + + + +Identifier + + + +[_\p{XID_start}]\p{XID_continue}* + + + + + + + + + +Boolean + + + + + +true + + + + + + +false + + + + + + + + + + +WhiteSpace + + + +\p{White_Space}+ + + + + + + + + \ No newline at end of file diff --git a/projects/dejavu-parser/src/nexus/railway.svg b/projects/dejavu-parser/src/nexus/railway.svg new file mode 100644 index 0000000..5b7bd02 --- /dev/null +++ b/projects/dejavu-parser/src/nexus/railway.svg @@ -0,0 +1,1224 @@ + + + + + + +Root + + + +* + + + + +Element + + + + + + + + + + + +Element + + + + + + +TextElements + + + + + + + + + +TemplateExport + + + + + + + +TemplateIf + + + + + + + + + + + +TextElements + + + + + + +TEMPLATE_E + + + + + + + + + +TEXT_SPACE + + + + + + + +TEXT_WORD + + + + + + + + + + + +TEMPLATE_E + + + +<<% + + + + + + + + + +TEXT_SPACE + + + +\p{White_Space}+ + + + + + + + + + +TEXT_WORD + + + +[^<\p{White_Space}]+ + + + + + + + + + +TEMPLATE_L + + + + +<% + + + + + + + +SPACE_CONTROL + + + + + + + + + + + + + +TEMPLATE_R + + + + + + + +SPACE_CONTROL + + + + + + +%> + + + + + + + + + + + +SPACE_CONTROL + + + + + +_ + + + + + + + + +- + + + + + +~ + + + + + += + + + + + + + + + + +KW_END + + + +end + + + + + + + + + +TemplateExport + + + + + +TEMPLATE_L + + + + + +IGNORED + + + + + +* + + + + +ExportItem + + + + + + +IGNORED + + + + + +TEMPLATE_R + + + + + + + + + + + + + + + + +ExportItem + + + + + +KW_EXPORT + + + + + +IGNORED + + + + + + +Identifier + + + + + +IGNORED + + + + + + + + +KW_TO + + + + + +IGNORED + + + + + +Identifier + + + + + + + + + +IGNORED + + + + + + + + + +KW_BY + + + + + +IGNORED + + + + + +KW_CLASS + + + + + + + + +IGNORED + + + + + +NamepathFree + + + + + + + + + +IGNORED + + + + + + + + + +KW_BY + + + + + +IGNORED + + + + + +KW_TRAIT + + + + + + + + +IGNORED + + + + + + + +NamepathFree + + + + + + + + + + + + + + + + + + + + + + + + + +KW_EXPORT + + + +export + + + + + + + + + +KW_CLASS + + + +class + + + + + + + + + +KW_TRAIT + + + +trait + + + + + + + + + +KW_TO + + + +to + + + + + + + + + +KW_BY + + + +by + + + + + + + + + +TemplateIf + + + + + +IfBegin + + + + + +* + + + + +IfElseIf + + + + + + + + + +IfElse + + + + + + + +IfEnd + + + + + + + + + + + + + + +IfBegin + + + + + + +TEMPLATE_L + + + + + +IGNORED + + + + + +KW_IF + + + + + + + + +IGNORED + + + + + + + +Atomic + + + + + +IGNORED + + + + + +TEMPLATE_R + + + + + + + + +* + + + + +TextElements + + + + + + + + + + + + + + + + +IfElse + + + + + + +TEMPLATE_L + + + + + +IGNORED + + + + + +KW_ELSE + + + + + +IGNORED + + + + + +TEMPLATE_R + + + + + + + + + + +* + + + + +TextElements + + + + + + + + + + + + + +IfElseIf + + + + + + +TEMPLATE_L + + + + + +IGNORED + + + + + +KW_ELSE + + + + + +IGNORED + + + + + +KW_IF + + + + + +IGNORED + + + + + +TEMPLATE_R + + + + + + + + + + + + +* + + + + +TextElements + + + + + + + + + + + + + +IfEnd + + + + + +TEMPLATE_L + + + + + +IGNORED + + + + + +KW_END + + + + + +IGNORED + + + + + + + +KW_IF + + + + + + +IGNORED + + + + + +TEMPLATE_R + + + + + + + + + + + + + + + + + +KW_IF + + + +if + + + + + + + + + +KW_ELSE + + + +else + + + + + + + + + +Atomic + + + + + + +Boolean + + + + + + + + + +Identifier + + + + + + + +Number + + + + + + + + + + + +String + + + + + + +" + + + + +IGNORED + + + + +" + + + + + + + + + + +' + + + + +IGNORED + + + + +' + + + + + + + + + + + + + +Number + + + +0|[1-9][0-9] + + + + + + + + + +NamepathFree + + + + + +Identifier + + + + + +IGNORED + + + + +* + + + + + + +. + + + + + + +:: + + + + + +IGNORED + + + + + +Identifier + + + + + + + + + + + + + + + + + +Namepath + + + + + +Identifier + + + + + +IGNORED + + + + +* + + + + +:: + + + + +IGNORED + + + + + +Identifier + + + + + + + + + + + + + + + + + +Identifier + + + +[_\p{XID_start}]\p{XID_continue}* + + + + + + + + + +Boolean + + + + + +true + + + + + + +false + + + + + + + + + + +WhiteSpace + + + +\p{White_Space}+ + + + + + + + + diff --git a/projects/dejavu-parser/src/dejavu/readme.md b/projects/dejavu-parser/src/nexus/readme.md similarity index 63% rename from projects/dejavu-parser/src/dejavu/readme.md rename to projects/dejavu-parser/src/nexus/readme.md index 0256770..cc261b8 100644 --- a/projects/dejavu-parser/src/dejavu/readme.md +++ b/projects/dejavu-parser/src/nexus/readme.md @@ -1,3 +1,3 @@ -# DejavuParser +# NexusParser ![Railway](./railway.svg) \ No newline at end of file diff --git a/projects/dejavu-parser/tests/main.rs b/projects/dejavu-parser/tests/main.rs index 8c8f35e..180e769 100644 --- a/projects/dejavu-parser/tests/main.rs +++ b/projects/dejavu-parser/tests/main.rs @@ -1,4 +1,5 @@ -use dejavu_parser::dejavu::{DejavuParser, DejavuRule, RootNode}; +use dejavu_parser::nexus::{NexusParser, NexusRule, RootNode}; +use std::fmt::Formatter; use yggdrasil_rt::{YggdrasilNode, YggdrasilParser}; #[test] @@ -11,7 +12,7 @@ mod test_control; #[test] fn test_ascii() { - let cst = DejavuParser::parse_cst("[true, false, 1, 2, null]", DejavuRule::Root).unwrap(); + let cst = NexusParser::parse_cst("[true, false, 1, 2, null]", NexusRule::Root).unwrap(); println!("Short Form:\n{}", cst); let first = RootNode::from_cst(cst).unwrap(); println!("{:#?}", first) diff --git a/projects/dejavu-parser/tests/test_class/mod.rs b/projects/dejavu-parser/tests/test_class/mod.rs index 23917f2..f9a311b 100644 --- a/projects/dejavu-parser/tests/test_class/mod.rs +++ b/projects/dejavu-parser/tests/test_class/mod.rs @@ -1,8 +1,9 @@ use super::*; +use dejavu_parser::nexus::{NexusParser, NexusRule}; #[test] fn test_unicode() { - let cst = DejavuParser::parse_cst(include_str!("test_class.djv"), DejavuRule::Root).unwrap(); + let cst = NexusParser::parse_cst(include_str!("test_class.djv"), NexusRule::Root).unwrap(); println!("Short Form:\n{}", cst); let first = RootNode::from_cst(cst).unwrap(); println!("{:#?}", first) @@ -10,6 +11,17 @@ fn test_unicode() { #[test] fn test_unicode2() { - let cst = DejavuParser::parse_cst("<% export a to a by class a %>", DejavuRule::TemplateExport).unwrap(); - println!("Short Form:\n{}", cst); + let cst = NexusParser::parse_cst("<% export parse_template %>", NexusRule::TemplateExport).unwrap(); + println!("{}", cst); + let cst = NexusParser::parse_cst("<% export parse_template to rust %>", NexusRule::TemplateExport).unwrap(); + println!("{}", cst); + let cst = NexusParser::parse_cst("<% export parse_template by class Template %>", NexusRule::TemplateExport).unwrap(); + println!("{}", cst); + let cst = + NexusParser::parse_cst("<% export parse_template by class Template by trait %>", NexusRule::TemplateExport).unwrap(); + println!("{}", cst); + let cst = + NexusParser::parse_cst("<% export parse_template by class Template by trait TemplateExt %>", NexusRule::TemplateExport) + .unwrap(); + println!("{}", cst); } diff --git a/projects/dejavu-parser/tests/test_control/mod.rs b/projects/dejavu-parser/tests/test_control/mod.rs index 7c0bba5..4ef51f0 100644 --- a/projects/dejavu-parser/tests/test_control/mod.rs +++ b/projects/dejavu-parser/tests/test_control/mod.rs @@ -1,9 +1,8 @@ use super::*; - #[test] fn test_unicode() { - let cst = DejavuParser::parse_cst(include_str!("test_if.djv"), DejavuRule::Root).unwrap(); + let cst = NexusParser::parse_cst(include_str!("test_if.djv"), NexusRule::Root).unwrap(); println!("Short Form:\n{}", cst); let first = RootNode::from_cst(cst).unwrap(); println!("{:#?}", first) diff --git a/projects/dejavu-runtime/src/display/mod.rs b/projects/dejavu-runtime/src/display/mod.rs new file mode 100644 index 0000000..5729110 --- /dev/null +++ b/projects/dejavu-runtime/src/display/mod.rs @@ -0,0 +1,119 @@ +use core::fmt::{Display, Formatter, Write}; + +pub trait Escaper { + fn write_escaped(&self, fmt: W, string: &str) -> core::fmt::Result + where + W: Write; +} + + +#[derive(Debug)] +pub struct EscapeDisplay + where + E: Escaper, + T: Display, +{ + value: DisplayValue, + escaper: E, +} + +#[derive(Debug)] +pub struct EscapeWriter<'a, E, W> { + fmt: W, + escaper: &'a E, +} + +#[derive(Debug)] +pub struct Escaped<'a, E> + where + E: Escaper, +{ + string: &'a str, + escaper: E, +} + +impl EscapeDisplay + where + E: Escaper, + T: Display, +{ + pub fn dangerous(value: T, escaper: E) -> Self { + Self { + value: DisplayValue::Unsafe(value), + escaper, + } + } + + pub fn safe(value: T, escaper: E) -> Self { + Self { + value: DisplayValue::Safe(value), + escaper, + } + } + + #[must_use] + pub fn mark_safe(mut self) -> EscapeDisplay { + self.value = match self.value { + DisplayValue::Unsafe(t) => DisplayValue::Safe(t), + _ => self.value, + }; + self + } +} + +impl Display for EscapeDisplay + where + E: Escaper, + T: Display, +{ + fn fmt(&self, fmt: &mut Formatter<'_>) -> core::fmt::Result { + match self.value { + DisplayValue::Unsafe(ref t) => write!( + EscapeWriter { + fmt, + escaper: &self.escaper, + }, + "{t}" + ), + DisplayValue::Safe(ref t) => t.fmt(fmt), + } + } +} + +impl Write for EscapeWriter<'_, E, W> + where + W: Write, + E: Escaper, +{ + fn write_str(&mut self, s: &str) -> core::fmt::Result { + self.escaper.write_escaped(&mut self.fmt, s) + } +} + +pub fn escape(string: &str, escaper: E) -> Escaped<'_, E> + where + E: Escaper, +{ + Escaped { string, escaper } +} + + +impl Display for Escaped<'_, E> + where + E: Escaper, +{ + fn fmt(&self, fmt: &mut Formatter<'_>) -> core::fmt::Result { + self.escaper.write_escaped(fmt, self.string) + } +} + + +#[derive(Debug, PartialEq)] +enum DisplayValue + where + T: Display, +{ + Safe(T), + Unsafe(T), +} + diff --git a/projects/dejavu-runtime/src/escaper/html.rs b/projects/dejavu-runtime/src/escaper/html.rs new file mode 100644 index 0000000..747276e --- /dev/null +++ b/projects/dejavu-runtime/src/escaper/html.rs @@ -0,0 +1,36 @@ +use super::*; + +pub struct Html; + +impl Escaper for Html { + fn write_escaped(&self, mut fmt: W, string: &str) -> core::fmt::Result + where + W: Write, + { + let mut last = 0; + for (index, byte) in string.bytes().enumerate() { + const MIN_CHAR: u8 = b'"'; + const MAX_CHAR: u8 = b'>'; + const TABLE: [Option<&&str>; (MAX_CHAR - MIN_CHAR + 1) as usize] = { + let mut table = [None; (MAX_CHAR - MIN_CHAR + 1) as usize]; + table[(b'<' - MIN_CHAR) as usize] = Some(&"<"); + table[(b'>' - MIN_CHAR) as usize] = Some(&">"); + table[(b'&' - MIN_CHAR) as usize] = Some(&"&"); + table[(b'"' - MIN_CHAR) as usize] = Some(&"""); + table[(b'\'' - MIN_CHAR) as usize] = Some(&"'"); + table + }; + + let escaped = match byte { + MIN_CHAR..=MAX_CHAR => TABLE[(byte - MIN_CHAR) as usize], + _ => None, + }; + if let Some(escaped) = escaped { + fmt.write_str(&string[last..index])?; + fmt.write_str(escaped)?; + last = index + 1; + } + } + fmt.write_str(&string[last..]) + } +} \ No newline at end of file diff --git a/projects/dejavu-runtime/src/escaper/mod.rs b/projects/dejavu-runtime/src/escaper/mod.rs index e953544..9e69802 100644 --- a/projects/dejavu-runtime/src/escaper/mod.rs +++ b/projects/dejavu-runtime/src/escaper/mod.rs @@ -1,98 +1,12 @@ -use core::{ - fmt::{Display, Formatter, Result, Write}, - str, -}; +use core::fmt::Write; +use crate::Escaper; +pub use self::text::Text; +pub use self::html::Html; + + +mod text; +mod html; -pub mod utils; -/// Write escaped string -/// -/// # Arguments -/// -/// * `fmt`: -/// * `string`: -/// -/// returns: Result<(), Error> -/// -/// # Examples -/// -/// ``` -/// use dejavu_runtime::Escaper; -/// ``` -pub trait Escaper { - /// Write escaped string - /// - /// # Arguments - /// - /// * `fmt`: - /// * `string`: - /// - /// returns: Result<(), Error> - /// - /// # Examples - /// - /// ``` - /// use dejavu_runtime::Escaper; - /// ``` - fn write_escaped(&self, fmt: W, string: &str) -> Result - where - W: Write; -} -/// Write escaped string -/// -/// # Arguments -/// -/// * `fmt`: -/// * `string`: -/// -/// returns: Result<(), Error> -/// -/// # Examples -/// -/// ``` -/// use dejavu_runtime::Escaper; -/// ``` -pub struct XmlEscaper; -impl Escaper for XmlEscaper { - fn write_escaped(&self, mut fmt: W, string: &str) -> Result - where - W: Write, - { - for c in string.chars() { - match c { - '<' => fmt.write_str("<")?, - '>' => fmt.write_str(">")?, - '&' => fmt.write_str("&")?, - '"' => fmt.write_str(""")?, - '\'' => fmt.write_str("'")?, - _ => fmt.write_char(c)?, - } - } - Ok(()) - } -} -/// Write escaped string -/// -/// # Arguments -/// -/// * `fmt`: -/// * `string`: -/// -/// returns: Result<(), Error> -/// -/// # Examples -/// -/// ``` -/// use dejavu_runtime::Escaper; -/// ``` -pub struct PlainText; -impl Escaper for PlainText { - fn write_escaped(&self, mut fmt: W, string: &str) -> Result - where - W: Write, - { - fmt.write_str(string) - } -} diff --git a/projects/dejavu-runtime/src/escaper/text.rs b/projects/dejavu-runtime/src/escaper/text.rs new file mode 100644 index 0000000..8b4aa72 --- /dev/null +++ b/projects/dejavu-runtime/src/escaper/text.rs @@ -0,0 +1,12 @@ +use super::*; + +pub struct Text; + +impl Escaper for Text { + fn write_escaped(&self, mut fmt: W, string: &str) -> core::fmt::Result + where + W: Write, + { + fmt.write_str(string) + } +} diff --git a/projects/dejavu-runtime/src/escaper/utils.rs b/projects/dejavu-runtime/src/escaper/utils.rs deleted file mode 100644 index 35f0f24..0000000 --- a/projects/dejavu-runtime/src/escaper/utils.rs +++ /dev/null @@ -1,97 +0,0 @@ -use super::*; - -#[derive(Debug)] -pub struct TemplateDisplay -where - E: Escaper, - T: Display, -{ - value: DisplayValue, - escaper: E, -} - -impl TemplateDisplay -where - E: Escaper, - T: Display, -{ - pub fn new_unsafe(value: T, escaper: E) -> Self { - Self { value: DisplayValue::Unsafe(value), escaper } - } - - pub fn new_safe(value: T, escaper: E) -> Self { - Self { value: DisplayValue::Safe(value), escaper } - } - - #[must_use] - pub fn mark_safe(mut self) -> TemplateDisplay { - self.value = match self.value { - DisplayValue::Unsafe(t) => DisplayValue::Safe(t), - _ => self.value, - }; - self - } -} - -impl Display for TemplateDisplay -where - E: Escaper, - T: Display, -{ - fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { - match self.value { - DisplayValue::Unsafe(ref t) => write!(EscapeWriter { fmt, escaper: &self.escaper }, "{}", t), - DisplayValue::Safe(ref t) => t.fmt(fmt), - } - } -} - -#[derive(Debug)] -pub struct EscapeWriter<'a, E, W> { - fmt: W, - escaper: &'a E, -} - -impl Write for EscapeWriter<'_, E, W> -where - W: Write, - E: Escaper, -{ - fn write_str(&mut self, s: &str) -> Result { - self.escaper.write_escaped(&mut self.fmt, s) - } -} - -pub fn escape(string: &str, escaper: E) -> Escaped<'_, E> -where - E: Escaper, -{ - Escaped { string, escaper } -} - -#[derive(Debug)] -pub struct Escaped<'a, E> -where - E: Escaper, -{ - string: &'a str, - escaper: E, -} - -impl Display for Escaped<'_, E> -where - E: Escaper, -{ - fn fmt(&self, fmt: &mut Formatter<'_>) -> Result { - self.escaper.write_escaped(fmt, self.string) - } -} - -#[derive(Debug, PartialEq)] -enum DisplayValue -where - T: Display, -{ - Safe(T), - Unsafe(T), -} diff --git a/projects/dejavu-runtime/src/for_3rd/for_serde_json/mod.rs b/projects/dejavu-runtime/src/for_3rd/for_serde_json/mod.rs deleted file mode 100644 index e69de29..0000000 diff --git a/projects/dejavu-runtime/src/for_3rd/mod.rs b/projects/dejavu-runtime/src/for_3rd/mod.rs deleted file mode 100644 index 9cb5f26..0000000 --- a/projects/dejavu-runtime/src/for_3rd/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod for_serde_json; diff --git a/projects/dejavu-runtime/src/lib.rs b/projects/dejavu-runtime/src/lib.rs index 01c356f..3527132 100644 --- a/projects/dejavu-runtime/src/lib.rs +++ b/projects/dejavu-runtime/src/lib.rs @@ -1,15 +1,8 @@ -pub use anyhow::{Error, Result}; +#![no_std] -pub use self::{ - escaper::{ - utils::{escape, TemplateDisplay}, - Escaper, PlainText, XmlEscaper, - }, - looper::{ForLooper, Looper}, - traits::Template, -}; +mod display; +pub mod escaper; +pub mod looper; -mod escaper; -mod for_3rd; -mod looper; -mod traits; +pub use crate::display::{EscapeDisplay, Escaper}; +pub use askama_derive::Template; diff --git a/projects/dejavu-runtime/src/looper/mod.rs b/projects/dejavu-runtime/src/looper/mod.rs index 794aeaa..e0daf0d 100644 --- a/projects/dejavu-runtime/src/looper/mod.rs +++ b/projects/dejavu-runtime/src/looper/mod.rs @@ -1,27 +1,25 @@ use core::iter::{Enumerate, Peekable}; -pub trait Looper {} - -impl Looper for ForLooper {} - -pub struct ForLooper +pub struct TemplateLoop where I: Iterator, { iter: Peekable>, } -impl ForLooper +impl TemplateLoop where I: Iterator, { #[inline] pub fn new(iter: I) -> Self { - ForLooper { iter: iter.enumerate().peekable() } + TemplateLoop { + iter: iter.enumerate().peekable(), + } } } -impl Iterator for ForLooper +impl Iterator for TemplateLoop where I: Iterator, { @@ -29,7 +27,16 @@ where #[inline] fn next(&mut self) -> Option<(::Item, LoopItem)> { - self.iter.next().map(|(index, item)| (item, LoopItem { index, first: index == 0, last: self.iter.peek().is_none() })) + self.iter.next().map(|(index, item)| { + ( + item, + LoopItem { + index, + first: index == 0, + last: self.iter.peek().is_none(), + }, + ) + }) } } diff --git a/projects/dejavu-runtime/src/traits/escaper.rs b/projects/dejavu-runtime/src/traits/escaper.rs deleted file mode 100644 index e69de29..0000000 diff --git a/projects/dejavu-runtime/src/traits/mod.rs b/projects/dejavu-runtime/src/traits/mod.rs deleted file mode 100644 index 454af34..0000000 --- a/projects/dejavu-runtime/src/traits/mod.rs +++ /dev/null @@ -1,68 +0,0 @@ -use core::fmt::Write; - -mod escaper; - -pub trait Template { - /// Provides a conservative estimate of the expanded length of the rendered template - const SIZE_HINT: usize; - /// The MIME type (Content-Type) of the data that gets rendered by this Template - const MIME_TYPE: &'static str; - /// The template's extension, if provided - const EXTENSION: &'static str; - /// Helper method which allocates a new `String` and renders into it - /// - /// # Arguments - /// - /// * `fmt`: - /// - /// returns: Result<(), Error> - /// - /// # Examples - /// - /// ``` - /// use dejavu_runtime::Template; - /// ``` - fn render(&self) -> anyhow::Result { - let mut buf = String::with_capacity(Self::SIZE_HINT); - self.render_fmt(&mut buf)?; - Ok(buf) - } - /// Renders the template to the given `writer` fmt buffer - /// - /// # Arguments - /// - /// * `fmt`: - /// - /// returns: Result<(), Error> - /// - /// # Examples - /// - /// ``` - /// use dejavu_runtime::Template; - /// ``` - #[cfg(feature = "std")] - fn render_io(&self, io: &mut W) -> anyhow::Result<()> - where - W: std::io::Write + ?Sized, - { - io.write_all(self.render()?.as_bytes())?; - Ok(()) - } - - /// Renders the template to the given `writer` fmt buffer - /// - /// # Arguments - /// - /// * `fmt`: - /// - /// returns: Result<(), Error> - /// - /// # Examples - /// - /// ``` - /// use dejavu_runtime::Template; - /// ``` - fn render_fmt(&self, fmt: &mut W) -> anyhow::Result<()> - where - W: Write + ?Sized; -} diff --git a/projects/dejavu-runtime/tests/escaper/mod.rs b/projects/dejavu-runtime/tests/escaper/mod.rs deleted file mode 100644 index 77990be..0000000 --- a/projects/dejavu-runtime/tests/escaper/mod.rs +++ /dev/null @@ -1,12 +0,0 @@ -use std::string::ToString; - -use dejavu_engine::{escape, XmlEscaper}; - -#[test] -fn test_escape() { - assert_eq!(escape("", XmlEscaper).to_string(), ""); - assert_eq!(escape("<&>", XmlEscaper).to_string(), "<&>"); - assert_eq!(escape("bla&", XmlEscaper).to_string(), "bla&"); - assert_eq!(escape("", Html).to_string(), "<&>"); + assert_eq!(escape("bla&", Html).to_string(), "bla&"); + assert_eq!(escape("