77 lines
1.6 KiB
Rust
77 lines
1.6 KiB
Rust
use crate::lst_parser::syntax_kind::SyntaxKind::*;
|
|
use crate::SyntaxNode;
|
|
use rowan::Language;
|
|
macro_rules! ast_nodes {
|
|
($($ast:ident, $kind:ident);+) => {
|
|
$(
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
#[repr(transparent)]
|
|
pub struct $ast(SyntaxNode);
|
|
impl rowan::ast::AstNode for $ast {
|
|
type Language = crate::Lang;
|
|
|
|
fn can_cast(kind: <Self::Language as Language>::Kind) -> bool {
|
|
kind == $kind
|
|
}
|
|
|
|
fn cast(node: SyntaxNode) -> Option<Self> {
|
|
if node.kind() == $kind {
|
|
Some(Self(node))
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
fn syntax(&self) -> &SyntaxNode {
|
|
&self.0
|
|
}
|
|
}
|
|
)+
|
|
};
|
|
}
|
|
ast_nodes!(
|
|
Def, DEF;
|
|
DefName, DEF_NAME;
|
|
DefBody, DEF_BODY;
|
|
|
|
Mod, MODULE;
|
|
ModName, MODULE_NAME;
|
|
ModBody, MODULE_BODY;
|
|
|
|
Use, USE;
|
|
UsePat, USE_PAT;
|
|
PatItem, PAT_ITEM;
|
|
PatGlob, PAT_GLOB;
|
|
PatGroup, PAT_GROUP;
|
|
|
|
Literal, LITERAL;
|
|
IntLit, INT_NUM;
|
|
FloatLit, FLOAT_NUM;
|
|
StringLit, STRING;
|
|
|
|
Matrix, MATRIX;
|
|
MatrixRow, MAT_ROW;
|
|
Vector, VEC;
|
|
List, LIST;
|
|
CollectionItem, COLLECTION_ITEM;
|
|
|
|
ParenthesizedExpr, PARENTHESIZED_EXPR;
|
|
Expression, EXPR;
|
|
|
|
Pipeline, PIPELINE;
|
|
|
|
Instruction, INSTR;
|
|
InstructionName, INSTR_NAME;
|
|
InstructionParams, INSTR_PARAMS;
|
|
|
|
AttributeSet, ATTR_SET;
|
|
Attribute, ATTR;
|
|
AttributeName, ATTR_NAME;
|
|
AttributeValue, ATTR_VALUE;
|
|
|
|
ParseError, PARSE_ERR;
|
|
LexError, LEX_ERR;
|
|
|
|
Root, ROOT;
|
|
Eof, EOF
|
|
);
|