Prepare parser for function definitions
This commit is contained in:
parent
86006933d7
commit
9a1bb92dfe
4 changed files with 22 additions and 2 deletions
|
|
@ -46,7 +46,7 @@ pub fn ident() -> BoxedParser<'static, char, Ident, Error> {
|
|||
.try_map(|name, span| {
|
||||
if matches!(
|
||||
&name as &str,
|
||||
"nil" | "true" | "false" | "local" | "not" | "and" | "or"
|
||||
"nil" | "true" | "false" | "local" | "function" | "not" | "and" | "or"
|
||||
) {
|
||||
Err(Simple::custom(span, "identifier uses reserved name"))
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use crate::ast::{BinOp, Expr};
|
|||
use crate::span::HasSpan;
|
||||
|
||||
use super::basic::{space, Error};
|
||||
use super::func_defs::func_def;
|
||||
use super::lit::lit;
|
||||
use super::prefix::prefixed;
|
||||
use super::suffix::suffixed;
|
||||
|
|
@ -36,9 +37,16 @@ fn atom(
|
|||
let var = var(expr.clone()).map(Expr::Var);
|
||||
let table_constr = table_constr(expr.clone()).map(Expr::TableConstr);
|
||||
let table_destr = table_destr(expr.clone()).map(Expr::TableDestr);
|
||||
let func_def = func_def(expr.clone()).map(Expr::FuncDef);
|
||||
let paren = atom_paren(expr.clone());
|
||||
|
||||
let base = lit.or(paren).or(table_destr).or(table_constr).or(var);
|
||||
let base = lit
|
||||
.or(paren)
|
||||
.or(table_destr)
|
||||
.or(table_constr)
|
||||
.or(func_def)
|
||||
.or(var);
|
||||
|
||||
prefixed(suffixed(base, expr))
|
||||
}
|
||||
|
||||
|
|
|
|||
11
src/parser/func_defs.rs
Normal file
11
src/parser/func_defs.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
use chumsky::prelude::*;
|
||||
|
||||
use crate::ast::{Expr, FuncDef};
|
||||
|
||||
use super::basic::Error;
|
||||
|
||||
pub fn func_def(
|
||||
expr: impl Parser<char, Expr, Error = Error>,
|
||||
) -> BoxedParser<'static, char, FuncDef, Error> {
|
||||
todo().boxed()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue