Add "module" program variant
This commit is contained in:
parent
9658907d76
commit
2be47871da
2 changed files with 23 additions and 8 deletions
|
|
@ -1,17 +1,32 @@
|
||||||
use crate::span::{HasSpan, Span};
|
use crate::span::{HasSpan, Span};
|
||||||
|
|
||||||
use super::{Space, TableLitElem};
|
use super::{Expr, Space, TableLitElem};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Program {
|
pub enum Program {
|
||||||
pub elems: Vec<(Space, TableLitElem, Space)>,
|
/// 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.
|
/// `Some` if there is a trailing comma, `None` otherwise.
|
||||||
pub trailing_comma: Option<Space>,
|
trailing_comma: Option<Space>,
|
||||||
pub span: Span,
|
span: Span,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasSpan for Program {
|
impl HasSpan for Program {
|
||||||
fn span(&self) -> Span {
|
fn span(&self) -> Span {
|
||||||
self.span
|
match self {
|
||||||
|
Program::Expr { span, .. } => *span,
|
||||||
|
Program::Module { span, .. } => *span,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ pub fn ident() -> EParser<Ident> {
|
||||||
.try_map(|name, span| {
|
.try_map(|name, span| {
|
||||||
if matches!(
|
if matches!(
|
||||||
&name as &str,
|
&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"))
|
Err(Simple::custom(span, "identifier uses reserved name"))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue