Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
YSawc committed Oct 17, 2020
1 parent dd6dd3d commit b5980b4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn main() {
for n in _nas.to_owned().na {
_na.push(simplified(n))
}
println!("after beta: {:?}", _na);
println!("after simplified: {:?}", _na);
}

let mut min = _na.iter();
Expand Down Expand Up @@ -120,7 +120,7 @@ fn main() {
for n in _nas.to_owned().na {
_na.push(simplified(n))
}
println!("after beta: {:?}", _na);
println!("after simplified: {:?}", _na);
} else {
for n in _nas.to_owned().na {
_na.push(n)
Expand Down
2 changes: 1 addition & 1 deletion src/node_arr/node_arr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::super::location::location::*;
use super::super::node::node::*;
use super::super::parser::error::*;
use super::super::program::program::*;
use super::super::simplified::*;
use super::super::simplified::beta::*;
use super::super::simplified::*;
use super::super::token::token::*;
use super::super::var::var::*;

Expand Down
24 changes: 12 additions & 12 deletions src/tests/var/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ fn simplified_variable_under_initialize_test() {
let loc = l.to_owned();
let mut il = loc.iter();
let mut e: Vec<Var> = Vec::new();
e.push(Var {
s: "a".to_string(),
n: NodeSt::num(2, il.next().unwrap().n.c.loc.to_owned()),
});
e.push(Var {
s: "b".to_string(),
n: NodeSt::num(16, il.next().unwrap().n.c.loc.to_owned()),
});
e.push(Var {
s: "c".to_string(),
n: NodeSt::num(34, il.next().unwrap().n.c.loc.to_owned()),
});
e.push(Var::new(
"a".to_string(),
NodeSt::num(2, il.next().unwrap().n.c.loc.to_owned()),
));
e.push(Var::new(
"b".to_string(),
NodeSt::num(16, il.next().unwrap().n.c.loc.to_owned()),
));
e.push(Var::new(
"c".to_string(),
NodeSt::num(34, il.next().unwrap().n.c.loc.to_owned()),
));
assert_eq!(e, l);
}

Expand Down
17 changes: 14 additions & 3 deletions src/token/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ impl Token {
map.insert('='.into(), TokenKind::Assign);
map.insert('{'.into(), TokenKind::LBrace);
map.insert('}'.into(), TokenKind::RBrace);
map.insert('_'.into(), TokenKind::UnderScore);
map
}

Expand Down Expand Up @@ -203,14 +202,26 @@ impl Token {

b = 0;

if input.as_bytes()[i].is_ascii_alphabetic() {
if input.as_bytes()[i].is_ascii_alphabetic() || input.as_bytes()[i] == b'_' {
let t = i;
let mut s = String::new();
if input.as_bytes()[i] == b'_' {
s.push(input.chars().nth(i).unwrap());
i += 1;
}
while i < l && input.as_bytes()[i].is_ascii_alphabetic() {
s.push(input.chars().nth(i).unwrap());
i += 1;
}
// println!("s: {}", s);

if s == "_" {
p_data.push(Self::new(
TokenKind::UnderScore,
Loc::new(t as u8 + b, (i as u8 + 1) + b),
));
continue;
}

p_data.push(Self::ident(s, Loc::new(t as u8 + b, (i as u8 + 1) + b)));
continue;
}
Expand Down
8 changes: 7 additions & 1 deletion src/var/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@ use rustc_hash::FxHashMap;
pub struct Var {
pub s: String,
pub n: NodeSt,
pub m: bool,
}

impl Var {
pub fn new(s: String, n: NodeSt) -> Self {
Self { s, n }
Self { s, n, m: false }
}

pub fn default() -> Self {
Self {
s: String::new(),
n: NodeSt::default(),
m: false,
}
}

pub fn mnew(s: String, n: NodeSt) -> Self {
Self { s, n, m: true }
}
}

pub fn vex(
Expand Down

0 comments on commit b5980b4

Please sign in to comment.