forked from katzen-cafe/iowo
Compare commits
No commits in common. "9510d9254cf4b9a4d57a2a12fa15dfdbee641bc7" and "2bea3994c29c9802eef50b166963f4aad15a46a0" have entirely different histories.
9510d9254c
...
2bea3994c2
7 changed files with 18 additions and 20 deletions
|
@ -47,10 +47,10 @@ impl<'src, 'toks> Parser<'src, 'toks> {
|
||||||
self.input.kind(self.pos)
|
self.input.kind(self.pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn start(&mut self, name: &str) -> Marker {
|
pub(crate) fn start(&mut self) -> Marker {
|
||||||
let pos = self.events.len();
|
let pos = self.events.len();
|
||||||
self.push_ev(Event::tombstone());
|
self.push_ev(Event::tombstone());
|
||||||
Marker::new(pos, name)
|
Marker::new(pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn at(&self, kind: SyntaxKind) -> bool {
|
pub(crate) fn at(&self, kind: SyntaxKind) -> bool {
|
||||||
|
@ -88,10 +88,10 @@ pub(crate) struct Marker {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Marker {
|
impl Marker {
|
||||||
pub(crate) fn new(pos: usize, name: &str) -> Self {
|
pub(crate) fn new(pos: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
pos,
|
pos,
|
||||||
bomb: DropBomb::new(format!("Marker {name} must be completed or abandoned")),
|
bomb: DropBomb::new("Marker must be completed or abandoned"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ pub(crate) struct CompletedMarker {
|
||||||
|
|
||||||
impl CompletedMarker {
|
impl CompletedMarker {
|
||||||
pub(crate) fn precede(self, p: &mut Parser<'_, '_>) -> Marker {
|
pub(crate) fn precede(self, p: &mut Parser<'_, '_>) -> Marker {
|
||||||
let new_pos = p.start("new_pos");
|
let new_pos = p.start();
|
||||||
|
|
||||||
match &mut p.events[self.pos] {
|
match &mut p.events[self.pos] {
|
||||||
Event::Start { forward_parent, .. } => {
|
Event::Start { forward_parent, .. } => {
|
||||||
|
|
|
@ -5,7 +5,7 @@ use super::Parser;
|
||||||
mod expression;
|
mod expression;
|
||||||
|
|
||||||
pub fn source_file(p: &mut Parser) {
|
pub fn source_file(p: &mut Parser) {
|
||||||
let root = p.start("root");
|
let root = p.start();
|
||||||
|
|
||||||
expression::expression(p);
|
expression::expression(p);
|
||||||
p.eat_succeeding_ws();
|
p.eat_succeeding_ws();
|
||||||
|
|
|
@ -47,7 +47,7 @@ mod collection {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expression(p: &mut Parser) -> Option<CompletedMarker> {
|
pub fn expression(p: &mut Parser) -> Option<CompletedMarker> {
|
||||||
let expr = p.start("expr");
|
let expr = p.start();
|
||||||
|
|
||||||
if atom(p).or_else(|| instr(p)).is_none() {
|
if atom(p).or_else(|| instr(p)).is_none() {
|
||||||
expr.abandon(p);
|
expr.abandon(p);
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::parser::{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn matrix(p: &mut Parser) -> CompletedMarker {
|
pub fn matrix(p: &mut Parser) -> CompletedMarker {
|
||||||
let matrix = p.start("matrix");
|
let matrix = p.start();
|
||||||
p.eat(MAT_KW);
|
p.eat(MAT_KW);
|
||||||
|
|
||||||
if !p.eat(PAT_DIMENSIONS) {
|
if !p.eat(PAT_DIMENSIONS) {
|
||||||
|
@ -20,7 +20,7 @@ pub fn matrix(p: &mut Parser) -> CompletedMarker {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn matrix_body(p: &mut Parser) {
|
fn matrix_body(p: &mut Parser) {
|
||||||
let mat_body = p.start("mat_body");
|
let mat_body = p.start();
|
||||||
if !p.eat(L_BRACK) {
|
if !p.eat(L_BRACK) {
|
||||||
mat_body.complete_err(p, SyntaxError::Expected(vec![MAT_BODY]));
|
mat_body.complete_err(p, SyntaxError::Expected(vec![MAT_BODY]));
|
||||||
return ();
|
return ();
|
||||||
|
@ -28,10 +28,10 @@ fn matrix_body(p: &mut Parser) {
|
||||||
|
|
||||||
let mut going = true;
|
let mut going = true;
|
||||||
|
|
||||||
let mut mat_row = p.start("mat_row");
|
let mut mat_row = p.start();
|
||||||
let mut row_items = 0;
|
let mut row_items = 0;
|
||||||
while going {
|
while going {
|
||||||
let mat_item = p.start("mat_item");
|
let mat_item = p.start();
|
||||||
if expression(p).is_some() {
|
if expression(p).is_some() {
|
||||||
mat_item.complete(p, MAT_ITEM);
|
mat_item.complete(p, MAT_ITEM);
|
||||||
row_items += 1;
|
row_items += 1;
|
||||||
|
@ -39,24 +39,22 @@ fn matrix_body(p: &mut Parser) {
|
||||||
COMMA => p.do_bump(),
|
COMMA => p.do_bump(),
|
||||||
SEMICOLON => {
|
SEMICOLON => {
|
||||||
mat_row.complete(p, MAT_ROW);
|
mat_row.complete(p, MAT_ROW);
|
||||||
mat_row = p.start("mat_row");
|
mat_row = p.start();
|
||||||
p.do_bump();
|
p.do_bump();
|
||||||
row_items = 0;
|
row_items = 0;
|
||||||
}
|
}
|
||||||
R_BRACK => going = false,
|
R_BRACK => going = false,
|
||||||
_ => {
|
_ => {
|
||||||
let err = p.start("err");
|
let err = p.start();
|
||||||
p.do_bump();
|
p.do_bump();
|
||||||
|
|
||||||
err.complete_err(p, SyntaxError::Expected(vec![COMMA, SEMICOLON, R_BRACK]));
|
err.complete_err(p, SyntaxError::Expected(vec![COMMA, SEMICOLON, R_BRACK]));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else if p.at(R_BRACK) {
|
} else if p.at(R_BRACK) {
|
||||||
mat_item.abandon(p);
|
|
||||||
going = false;
|
going = false;
|
||||||
} else {
|
} else {
|
||||||
mat_item.abandon(p);
|
let err = p.start();
|
||||||
let err = p.start("err");
|
|
||||||
p.do_bump();
|
p.do_bump();
|
||||||
err.complete_err(p, SyntaxError::Expected(vec![EXPR, R_BRACK]));
|
err.complete_err(p, SyntaxError::Expected(vec![EXPR, R_BRACK]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub fn instr(p: &mut Parser) -> Option<CompletedMarker> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let instr = p.start("instr");
|
let instr = p.start();
|
||||||
|
|
||||||
instr_name(p);
|
instr_name(p);
|
||||||
instr_params(p);
|
instr_params(p);
|
||||||
|
@ -16,7 +16,7 @@ pub fn instr(p: &mut Parser) -> Option<CompletedMarker> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn instr_name(p: &mut Parser) {
|
fn instr_name(p: &mut Parser) {
|
||||||
let instr_name = p.start("instr_name");
|
let instr_name = p.start();
|
||||||
|
|
||||||
while p.at(IDENT) {
|
while p.at(IDENT) {
|
||||||
p.do_bump();
|
p.do_bump();
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub fn literal(p: &mut Parser) -> Option<CompletedMarker> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let lit = p.start("lit");
|
let lit = p.start();
|
||||||
|
|
||||||
p.do_bump();
|
p.do_bump();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
mat 2x2 [
|
mat 2x2 [
|
||||||
1 2, 2;
|
1, 2;
|
||||||
3, 4
|
3, 4
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue