Allow primitive literals, lists and tuples in fuzzer expressions.

This commit is contained in:
KtorZ 2024-03-04 20:40:40 +01:00
parent c7cd89d127
commit 3e922c0a52
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
1 changed files with 16 additions and 10 deletions

View File

@ -1,5 +1,3 @@
use chumsky::prelude::*;
use crate::{ use crate::{
ast, ast,
expr::UntypedExpr, expr::UntypedExpr,
@ -7,10 +5,11 @@ use crate::{
annotation, annotation,
chain::{call::parser as call, field_access, tuple_index::parser as tuple_index, Chain}, chain::{call::parser as call, field_access, tuple_index::parser as tuple_index, Chain},
error::ParseError, error::ParseError,
expr::{self, var}, expr::{self, bytearray, int, list, string, tuple, var},
token::Token, token::Token,
}, },
}; };
use chumsky::prelude::*;
pub fn parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseError> { pub fn parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseError> {
// TODO: can remove Token::Bang after a few releases (curr v1.0.11) // TODO: can remove Token::Bang after a few releases (curr v1.0.11)
@ -89,7 +88,14 @@ pub fn fuzzer<'a>() -> impl Parser<Token, UntypedExpr, Error = ParseError> + 'a
call(expression.clone()), call(expression.clone()),
)); ));
var() choice((
string(),
int(),
bytearray(),
tuple(expression.clone()),
list(expression.clone()),
var(),
))
.then(chain.repeated()) .then(chain.repeated())
.foldl(|expr, chain| match chain { .foldl(|expr, chain| match chain {
Chain::Call(args, span) => expr.call(args, span), Chain::Call(args, span) => expr.call(args, span),