lang: rewrite parser

This commit is contained in:
Schrottkatze 2024-04-24 11:07:38 +02:00
parent 6d8b79e8f7
commit 381ab45edc
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc
25 changed files with 524 additions and 1161 deletions

View file

@ -0,0 +1,14 @@
use crate::parser::{syntax_kind::SyntaxKind::*, Parser};
use self::{instruction::instr, lit::literal};
mod instruction;
mod lit;
pub fn expression(p: &mut Parser) {
let expr = p.start();
instr(p);
expr.complete(p, EXPR);
}

View file

@ -0,0 +1,30 @@
use crate::parser::{syntax_kind::SyntaxKind::*, Parser};
use super::lit::literal;
pub fn instr(p: &mut Parser) {
let instr = p.start();
instr_name(p);
instr_params(p);
instr.complete(p, INSTR);
}
fn instr_name(p: &mut Parser) {
let instr_name = p.start();
while p.at(IDENT) {
p.do_bump();
}
instr_name.complete(p, INSTR_NAME);
}
fn instr_params(p: &mut Parser) {
if let Some(start) = literal(p) {
while literal(p).is_some() {}
start.precede(p).complete(p, INSTR_PARAMS);
}
}

View file

@ -0,0 +1,20 @@
use enumset::enum_set;
use crate::parser::{
syntax_kind::{SyntaxKind::*, TokenSet},
CompletedMarker, Parser,
};
const LIT_TOKENS: TokenSet = enum_set!(INT_NUM | FLOAT_NUM | STRING);
pub fn literal(p: &mut Parser) -> Option<CompletedMarker> {
if !LIT_TOKENS.contains(p.current()) {
return None;
}
let lit = p.start();
p.do_bump();
Some(lit.complete(p, LITERAL))
}