Fix ';' in let term, allow '.' in name

This commit is contained in:
Nicolas Abril 2023-09-14 19:42:23 +02:00
parent af194db86c
commit 4a092a3bce
2 changed files with 4 additions and 4 deletions

View File

@ -6,7 +6,7 @@ use crate::ast::Number;
#[derive(Logos, Debug, PartialEq, Clone)]
#[logos(error=LexingError)]
pub enum Token {
#[regex("[_a-zA-Z][_a-zA-Z0-9]*", |lex| lex.slice().parse().ok())]
#[regex("[_.a-zA-Z][_.a-zA-Z0-9]*", |lex| lex.slice().parse().ok())]
Name(String),
#[regex("@|λ")]

View File

@ -125,6 +125,7 @@ where
let var = name().map(|name| Term::Var { nam: name }).boxed();
let global_var = just(Token::Dollar).ignore_then(name()).map(|name| Term::GlobalVar { nam: name }).boxed();
let era_or_name = choice((select!(Token::Asterisk => None), name().map(Some))).boxed();
let term_sep = choice((just(Token::NewLine), just(Token::Semicolon)));
recursive(|term| {
// λx body
@ -157,7 +158,7 @@ where
.then_ignore(just(Token::Equals))
.then_ignore(new_line())
.then(term.clone())
.then_ignore(just(Token::Semicolon))
.then_ignore(term_sep.clone())
.then_ignore(new_line())
.then(term.clone())
.map(|(((fst, snd), val), next)| Term::Dup { fst, snd, val: Box::new(val), nxt: Box::new(next) })
@ -171,8 +172,7 @@ where
.then_ignore(just(Token::Equals))
.then_ignore(new_line())
.then(term.clone())
.then_ignore(new_line())
.then_ignore(just(Token::Semicolon))
.then_ignore(term_sep)
.then_ignore(new_line())
.then(term.clone())
.map(|((name, body), next)| Term::App {