#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(unused_mut)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
use std::ops::{Deref,DerefMut};
use std::collections::{HashMap,HashSet};
use crate::RuntimeParser;
use crate::GenAbsyn::*;
pub struct LBox<T>
{
pub exp:Box<T>,
pub line:usize,
pub column:usize,
pub src_id:usize, }
impl<T> LBox<T>
{
pub fn new(e:T,ln:usize,col:usize) -> LBox<T>
{ LBox { exp:Box::new(e), line:ln, column:col, src_id:0 } }
pub fn set_src_id(&mut self, id:usize) {self.src_id=id;}
}
impl<T> Deref for LBox<T>
{
type Target = T;
fn deref(&self) -> &Self::Target {
&self.exp
}
}
impl<T> DerefMut for LBox<T>
{
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.exp
}
}
impl<T:Default> Default for LBox<T>
{
fn default() -> Self {LBox::new(T::default(),0,0)}
}
pub type ABox = LBox<GenAbsyn>;
impl std::fmt::Debug for ABox
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ABox")
.field("exp", &self.exp)
.field("line", &self.line)
.field("column", &self.column)
.finish()
}
}impl Clone for ABox
{
fn clone(&self) -> Self
{
LBox {
exp: self.exp.clone(),
line: self.line,
column: self.column,
src_id: self.src_id,
}
}
}
#[derive(Clone,Debug)]
pub enum GenAbsyn
{
Integer(i64),
BigInteger(String),
Float(f64),
Symbol(&'static str),
Keyword(&'static str),
Alphanum(String),
Stringlit(String),
Verbatim(String),
Uniop(usize,ABox),
Binop(usize,ABox,ABox),
Ternop(usize,ABox,ABox,ABox),
Sequence(usize,Vec<ABox>),
Partial(ABox,String), NewLine,
Whitespaces(usize),
Nothing,
}
impl GenAbsyn
{
pub fn is_complete(&self) -> bool
{
match self
{
Partial(_,_) => false,
Uniop(_,s) => {
println!("s.line {}{}",s.line,s.column);
s.is_complete()
},
Binop(_,a,b) => a.is_complete() && b.is_complete(),
Ternop(_,a,b,c) => a.is_complete() && b.is_complete() && c.is_complete(),
Sequence(_,v) => {
for x in v { if !x.is_complete() {return false; } }
true
}
_ => true,
}
}}
impl Default for GenAbsyn
{
fn default() -> Self { Nothing }
}
pub struct Absyn_Statics<const N:usize,const M:usize,const P:usize>
{
pub KEYWORDS: [&'static str; N],
pub SYMBOLS: [&'static str; M],
pub OPERATORS: [&'static str; P],
pub Keyhash:HashMap<&'static str,usize>,
pub Symhash:HashMap<&'static str,usize>,
pub Ophash: HashMap<&'static str,usize>,
}
impl<const N:usize,const M:usize,const P:usize> Absyn_Statics<N,M,P>
{
pub fn new(k:[&'static str; N],s:[&'static str;M],p:[&'static str;P])
-> Absyn_Statics<N,M,P>
{
let mut newas = Absyn_Statics {
KEYWORDS: k,
SYMBOLS: s,
OPERATORS:p,
Keyhash: HashMap::with_capacity(N),
Symhash: HashMap::with_capacity(M),
Ophash: HashMap::with_capacity(P),
};
for i in 0..N { newas.Keyhash.insert(k[i],i); }
for i in 0..M { newas.Symhash.insert(s[i],i); }
for i in 0..P { newas.Ophash.insert(p[i],i); }
return newas;
}
pub fn is_keyword(&self,k:&str) -> bool
{ self.Keyhash.contains_key(k) }
pub fn is_symbol(&self,k:&str) -> bool
{ self.Symhash.contains_key(k) }
pub fn is_operator(&self,k:&str) -> bool
{ self.Ophash.contains_key(k) }
}
#[macro_export]
macro_rules! lbox {
( $x:expr ) => {
parser.lb($x)
};
}