diff --git a/src/ast/program.rs b/src/ast/program.rs index 8573ec1..5a198d0 100644 --- a/src/ast/program.rs +++ b/src/ast/program.rs @@ -1,17 +1,32 @@ use crate::span::{HasSpan, Span}; -use super::{Space, TableLitElem}; +use super::{Expr, Space, TableLitElem}; #[derive(Debug, Clone)] -pub struct Program { - pub elems: Vec<(Space, TableLitElem, Space)>, - /// `Some` if there is a trailing comma, `None` otherwise. - pub trailing_comma: Option, - pub span: Span, +pub enum Program { + /// Structure: `s0 lit s1` + Expr { + s0: Space, + expr: Expr, + s1: Space, + span: Span, + }, + + /// Structure: `s0 module elems trailing_comma` + Module { + s0: Space, + elems: Vec<(Space, TableLitElem, Space)>, + /// `Some` if there is a trailing comma, `None` otherwise. + trailing_comma: Option, + span: Span, + }, } impl HasSpan for Program { fn span(&self) -> Span { - self.span + match self { + Program::Expr { span, .. } => *span, + Program::Module { span, .. } => *span, + } } } diff --git a/src/parser/basic.rs b/src/parser/basic.rs index 5a951dd..8d7ba1d 100644 --- a/src/parser/basic.rs +++ b/src/parser/basic.rs @@ -45,7 +45,7 @@ pub fn ident() -> EParser { .try_map(|name, span| { if matches!( &name as &str, - "nil" | "true" | "false" | "local" | "function" | "not" | "and" | "or" + "nil" | "true" | "false" | "not" | "and" | "or" | "local" | "function" | "module" ) { Err(Simple::custom(span, "identifier uses reserved name")) } else {