feat: Implement lexer and parser for AST
Introduces the lexer and parser modules, enabling the conversion of source code into an Abstract Syntax Tree (AST). This includes: - Defining token kinds and structures. - Implementing lexer logic to tokenize input. - Defining AST node kinds and structures. - Implementing parser logic to construct the AST from tokens. - Adding support for basic expressions, lists, keywords, and identifiers. - Adding the `lazy_static` dependency for keyword interning. - Refactoring `Value::Nil` to `Value::Void`.
This commit is contained in:
+4
-1
@@ -23,6 +23,8 @@ pub struct Context {
|
||||
/// The core AST variant enum for performance and structure
|
||||
#[derive(Debug)]
|
||||
pub enum UntypedKind {
|
||||
/// The "..." placeholder for incomplete code
|
||||
Nop,
|
||||
Constant(Value),
|
||||
Identifier(Arc<str>),
|
||||
If {
|
||||
@@ -41,6 +43,7 @@ pub enum UntypedKind {
|
||||
impl Node<UntypedKind> {
|
||||
pub fn eval(&self, ctx: &mut Context) -> Value {
|
||||
match &self.kind {
|
||||
UntypedKind::Nop => Value::Void,
|
||||
UntypedKind::Constant(v) => v.clone(),
|
||||
UntypedKind::Identifier(_) => todo!("Lookup in Context"),
|
||||
UntypedKind::If { cond, then_br, else_br } => {
|
||||
@@ -49,7 +52,7 @@ impl Node<UntypedKind> {
|
||||
} else if let Some(eb) = else_br {
|
||||
eb.eval(ctx)
|
||||
} else {
|
||||
Value::Nil
|
||||
Value::Void
|
||||
}
|
||||
}
|
||||
UntypedKind::Call { callee, args } => {
|
||||
|
||||
Reference in New Issue
Block a user