use std::rc::Rc; use std::str::FromStr; use lalrpop_util::ParseError; use crate::rsprocess::structure::{RSset, RSprocess, RSenvironment, RSassert, RSassertOp, RSBHML}; grammar; // matches words (letter followed by numbers, letters or _) Literal = { r"[[:alpha:]][[:word:]]*" }; // all numbers are i64 Num: i64 = { r"[0-9]+" =>? i64::from_str(<>) .map_err(|_| ParseError::User { error: "Number is too big" }) }; // macro for matching sequence of patterns with C as separator Separeted: Vec = { C)+> => match e { None => v, Some(e) => { v.push(e); v } } }; // ----- SetParser ----- pub Set: RSset<'input> = { => s }; Set_of_entities: RSset<'input> = { "{" "}" => RSset::from(vec![]), "{" "}" => RSset::from(vec![t]), "{" > "}" => RSset::from(t) }; // ----- ContextParser ----- pub Context: Box> = { "[" "]" => Box::new(RSprocess::Nill), "[" "]" => Box::new(t), "[" > "]" => Box::new(RSprocess::NondeterministicChoice{ children: t }) }; Boxed_CTX_process: Rc> = { => Rc::new(t) } CTX_process: RSprocess<'input> = { "." => RSprocess::EntitySet{ entities: c, next_process: Rc::new(k) }, "(" ")" => k, "(" > ")" => RSprocess::Summation{ children: k }, "<" ">" "." => RSprocess::WaitEntity{ repeat: n, repeated_process: Rc::new(k1), next_process: Rc::new(k)}, "nil" => RSprocess::Nill, => RSprocess::RecursiveIdentifier{ identifier } }; // ----- EnvironmentParser ----- pub Environment: Box> = { "[" "]" => Box::new(RSenvironment::new()), "[" > "]" => Box::new(RSenvironment::from(t)) }; Env_term: (&'input str, RSprocess<'input>) = { "=" => (identifier, k) }; // ----- AssertParser ----- pub Assert: Box> = { => Box::new(f) }; Formula_Assert: RSassert<'input> = { "-" => RSassert::Not(Box::new(f)), "(" "^" ")" => RSassert::Xor(Box::new(f1), Box::new(f2)), "(" > ")" => RSassert::Or(f), "(" > ")" => RSassert::And(f), "inW" => RSassert::Sub(c, RSassertOp::InW), "inR" => RSassert::Sub(c, RSassertOp::InR), "inI" => RSassert::Sub(c, RSassertOp::InI), "inP" => RSassert::Sub(c, RSassertOp::InP), "?" "inW" => RSassert::NonEmpty(RSassertOp::InW), "?" "inR" => RSassert::NonEmpty(RSassertOp::InR), "?" "inI" => RSassert::NonEmpty(RSassertOp::InI), "?" "inP" => RSassert::NonEmpty(RSassertOp::InP), }; // ----- BHMLParser ----- pub BHML: Box> = { => Box::new(g) }; Formula_BHML: RSBHML<'input> = { "true" => RSBHML::True, "false" => RSBHML::False, "(" > ")" => RSBHML::Or(g), "(" > ")" => RSBHML::And(g), "<" ">" => RSBHML::Diamond(Box::new(f), Box::new(g)), "[" "]" => RSBHML::Box(Box::new(f), Box::new(g)), };