lang: basic ast work

This commit is contained in:
Schrottkatze 2024-06-05 18:00:14 +02:00
parent cfefab9fd0
commit d6bc644fb6
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc
13 changed files with 560 additions and 58 deletions

View file

@ -3,9 +3,9 @@ use owo_colors::{unset_override, OwoColorize};
use rowan::{GreenNode, GreenNodeBuilder, GreenNodeData, GreenTokenData, Language, NodeOrToken};
use std::mem;
use crate::lst_parser::{
input::MEANINGLESS_TOKS,
syntax_kind::{Lang, SyntaxKind},
use crate::{
lst_parser::{input::MEANINGLESS_TOKS, syntax_kind::SyntaxKind},
Lang, SyntaxNode,
};
use super::{
@ -201,4 +201,12 @@ impl Output {
errors,
}
}
pub fn syntax(&self) -> SyntaxNode {
SyntaxNode::new_root(self.green_node.clone())
}
pub fn errors(&self) -> Vec<SyntaxError> {
self.errors.clone()
}
}

View file

@ -53,7 +53,6 @@ pub enum SyntaxKind {
LIST,
// either of a vec, a matrix or a list
COLLECTION_ITEM,
DECL,
PARENTHESIZED_EXPR,
EXPR,
LITERAL,
@ -130,7 +129,6 @@ pub enum SyntaxKind {
ROOT,
EOF,
TOMBSTONE,
ERROR,
}
pub type TokenSet = EnumSet<SyntaxKind>;
@ -140,17 +138,3 @@ impl From<SyntaxKind> for rowan::SyntaxKind {
Self(kind as u16)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Lang {}
impl rowan::Language for Lang {
type Kind = SyntaxKind;
#[allow(unsafe_code)]
fn kind_from_raw(raw: rowan::SyntaxKind) -> Self::Kind {
assert!(raw.0 <= SyntaxKind::ROOT as u16);
unsafe { std::mem::transmute::<u16, SyntaxKind>(raw.0) }
}
fn kind_to_raw(kind: Self::Kind) -> rowan::SyntaxKind {
kind.into()
}
}