mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2024-12-22 10:05:52 +01:00
lang: parse pipelines
This commit is contained in:
parent
30f17773a8
commit
afd493be16
3 changed files with 48 additions and 38 deletions
|
@ -5,44 +5,7 @@ use self::{collection::collection, instruction::instr, lit::literal, pipeline::P
|
|||
mod collection;
|
||||
mod instruction;
|
||||
mod lit;
|
||||
mod pipeline {
|
||||
use enumset::enum_set;
|
||||
|
||||
use crate::lst_parser::{
|
||||
error::SyntaxError,
|
||||
syntax_kind::{SyntaxKind::*, TokenSet},
|
||||
CompletedMarker, Parser,
|
||||
};
|
||||
|
||||
use super::expression;
|
||||
|
||||
pub fn pipeline(p: &mut Parser, start_expr: CompletedMarker) -> Option<CompletedMarker> {
|
||||
if !pipe(p) {
|
||||
return Some(start_expr);
|
||||
}
|
||||
let pipeline_marker = start_expr.precede(p, "pipeline_start");
|
||||
|
||||
loop {
|
||||
if expression(p, true).is_none() {
|
||||
return Some(pipeline_marker.complete_err(p, SyntaxError::PipelineNeedsSink));
|
||||
}
|
||||
if !pipe(p) {
|
||||
return Some(pipeline_marker.complete(p, PIPELINE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const PIPES: TokenSet = enum_set!(PIPE | MAPPING_PIPE | NULL_PIPE);
|
||||
|
||||
fn pipe(p: &mut Parser) -> bool {
|
||||
if PIPES.contains(p.current()) {
|
||||
p.do_bump();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
mod pipeline;
|
||||
|
||||
pub fn expression(p: &mut Parser, in_pipe: bool) -> Option<CompletedMarker> {
|
||||
let expr = p.start("expr");
|
||||
|
|
36
crates/lang/src/lst_parser/grammar/expression/pipeline.rs
Normal file
36
crates/lang/src/lst_parser/grammar/expression/pipeline.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use enumset::enum_set;
|
||||
|
||||
use crate::lst_parser::{
|
||||
error::SyntaxError,
|
||||
syntax_kind::{SyntaxKind::*, TokenSet},
|
||||
CompletedMarker, Parser,
|
||||
};
|
||||
|
||||
use super::expression;
|
||||
|
||||
pub fn pipeline(p: &mut Parser, start_expr: CompletedMarker) -> Option<CompletedMarker> {
|
||||
if !pipe(p) {
|
||||
return Some(start_expr);
|
||||
}
|
||||
let pipeline_marker = start_expr.precede(p, "pipeline_start");
|
||||
|
||||
loop {
|
||||
if expression(p, true).is_none() {
|
||||
return Some(pipeline_marker.complete_err(p, SyntaxError::PipelineNeedsSink));
|
||||
}
|
||||
if !pipe(p) {
|
||||
return Some(pipeline_marker.complete(p, PIPELINE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const PIPES: TokenSet = enum_set!(PIPE | MAPPING_PIPE | NULL_PIPE);
|
||||
|
||||
fn pipe(p: &mut Parser) -> bool {
|
||||
if PIPES.contains(p.current()) {
|
||||
p.do_bump();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
|
@ -19,10 +19,21 @@ pub fn lex(src: &str) -> Vec<(SyntaxKind, &str)> {
|
|||
pub enum SyntaxKind {
|
||||
#[token("def")]
|
||||
DEF_KW = 0,
|
||||
DEF,
|
||||
DEF_NAME,
|
||||
DEF_BODY,
|
||||
#[token("let")]
|
||||
LET_KW,
|
||||
#[token("in")]
|
||||
IN_KW,
|
||||
LET_IN,
|
||||
#[token("mod")]
|
||||
MOD_KW,
|
||||
MODULE,
|
||||
MODULE_BODY,
|
||||
#[token("use")]
|
||||
USE_KW,
|
||||
USE_PAT,
|
||||
#[regex("[\\d]+")]
|
||||
INT_NUM,
|
||||
#[regex("[+-]?([\\d]+\\.[\\d]*|[\\d]*\\.[\\d]+)")]
|
||||
|
|
Loading…
Reference in a new issue