Skip to content

Commit

Permalink
Support new error types
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed Jun 21, 2024
1 parent fe4bdc4 commit 24cf430
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 38 deletions.
20 changes: 12 additions & 8 deletions projects/ygg-vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
name = "yggdrasil-vm"
version = "0.0.0"
authors = ["Aster <[email protected]>"]
description = "..."
description = "Dynamically interpreted syntax tree with yggdrasil grammar"
repository = "https://github.com/oovm/sub_projects"
documentation = "https://docs.rs/sub_projects"
readme = "Readme.md"
documentation = "https://docs.rs/yggdrasil-vm"
readme = "readme.md"
license = "MPL-2.0"
edition = "2021"
exclude = ["package.json", "tests/**"]

[dependencies.yggdrasil-core]
version = "0.1.*"
path = 'C:\Users\Dell\CLionProjects\yggdrasil-rs\projects\ygg-core'
[dependencies.yggdrasil-shared]
version = "0.2.5"
#path = 'C:\Users\Dell\CLionProjects\yggdrasil.rs\projects\ygg-core'

[dependencies.yggdrasil-error]
version = "0.1.4"
#path = 'C:\Users\Dell\CLionProjects\yggdrasil.rs\projects\ygg-rt'

[dependencies.yggdrasil-rt]
version = "0.0.*"
path = 'C:\Users\Dell\CLionProjects\yggdrasil-rs\projects\ygg-rt'
version = "0.1.3"
#path = 'C:\Users\Dell\CLionProjects\yggdrasil.rs\projects\ygg-rt'


[dev-dependencies]
Expand Down
61 changes: 31 additions & 30 deletions projects/ygg-vm/src/vm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
use std::collections::BTreeMap;
use std::str::FromStr;
use yggdrasil_core::optimize::{InsertIgnore, RefineRules};
use yggdrasil_core::{ChoiceExpression, ConcatExpression, ExpressionKind, GrammarInfo, GrammarRule, UnaryExpression, YggdrasilANTLR, YggdrasilExpression, YggdrasilOperator};
use yggdrasil_error::YggdrasilError;

use yggdrasil_rt::{OutputResult, Regex, State, YggdrasilParser, YggdrasilRule};
use yggdrasil_shared::{ChoiceExpression, ConcatExpression, ExpressionBody, GrammarInfo, GrammarRule, parse_grammar, UnaryExpression, YggdrasilExpression, YggdrasilOperator};

pub struct Kabbalah {
grammar: GrammarInfo,
rules: BTreeMap<String, (usize, GrammarRule)>,
}

impl FromStr for Kabbalah {
type Err = ();
type Err = YggdrasilError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut info = YggdrasilANTLR::parse(s).expect("fail");
info = InsertIgnore::default().optimize(&info).unwrap();
info = RefineRules::default().optimize(&info).unwrap();
fn from_str(s: &str) -> Result<Self, YggdrasilError> {
let mut info = parse_grammar(s)?;
Ok(Self {
grammar: info,
rules: Default::default(),
Expand All @@ -29,13 +28,8 @@ pub struct DynamicRule {
}

impl YggdrasilRule for DynamicRule {
fn all_rules() -> &'static [Self] {
&[]
}

fn is_ignore(&self) -> bool {
false
}


}

type Input<'i> = Box<State<'i, DynamicRule>>;
Expand All @@ -59,22 +53,22 @@ impl Kabbalah {
}

fn walk_node(&self, state: Input, node: &YggdrasilExpression) -> Output {
match &node.kind {
ExpressionKind::Ignored => {
match &node.body {
ExpressionBody::Ignored => {
self.walk_ignored(state)
}
ExpressionKind::Function(_) => { todo!() }
ExpressionKind::Choice(v) => {

ExpressionBody::Choice(v) => {
self.walk_choice(state, v)
}
ExpressionKind::Concat(v) => {
ExpressionBody::Concat(v) => {
self.walk_concat(state, v)
}
ExpressionKind::Unary(v) => {
ExpressionBody::Unary(v) => {
self.walk_unary(state, v)
}
ExpressionKind::Rule(_) => { todo!() }
ExpressionKind::Text(s) => {

ExpressionBody::Text(s) => {
match s.insensitive {
true => {
state.match_string_exact(&s.text)
Expand All @@ -84,10 +78,10 @@ impl Kabbalah {
}
}
}
ExpressionKind::CharacterAny => {
ExpressionBody::CharacterAny => {
state.match_char_if(|_| true)
}
ExpressionKind::Boolean(v) => {
ExpressionBody::Boolean(v) => {
match v {
true => {
state.match_insensitive("true")
Expand All @@ -97,13 +91,17 @@ impl Kabbalah {
}
}
}
ExpressionKind::Regex(v) => {
ExpressionBody::Regex(v) => {
match Regex::new(&v.raw) {
Ok(o) => { state.match_regex(&o) }
Err(_) => { todo!() }
}
}
ExpressionKind::Data(_) => { unreachable!() }
ExpressionBody::Rule(_) => { todo!() }
ExpressionBody::Call(_) => {todo!()}
ExpressionBody::CharacterRestOfLine => {todo!()}
ExpressionBody::CharacterRange(_) => {todo!()}
ExpressionBody::Integer(_) => {todo!()}
}
}
fn walk_choice(&self, state: Input, choice: &ChoiceExpression) -> Output {
Expand Down Expand Up @@ -137,20 +135,23 @@ impl Kabbalah {
out = state.optional(|s| self.walk_node(out, s))?
}
YggdrasilOperator::Negative => {}

YggdrasilOperator::Repeats => {}
YggdrasilOperator::Repeats => {
out = state.repeat(|s| self.walk_node(out, s))?
}
YggdrasilOperator::Repeat1 => {}
YggdrasilOperator::Boxing => {}
YggdrasilOperator::RepeatsBetween(_, _) => {}
YggdrasilOperator::Remark => {}
YggdrasilOperator::Recursive => {}
}
}
Ok(out)
}


/// `(WhiteSpace | Newline)* ==> WhiteSpace* | Newline*`
fn walk_ignored(&self, state: Input) -> Output {
for rule in self.grammar.rules.values().filter(| f| f.ignored) {
todo!()
}
todo!()
}
}

0 comments on commit 24cf430

Please sign in to comment.