Pass test
This commit is contained in:
parent
bff5ba81a3
commit
37a88df613
@ -44,9 +44,10 @@ pub fn lexer<'src>() -> impl Parser<
|
|||||||
Vec<(Token<'src>, SimpleSpan<usize>)>,
|
Vec<(Token<'src>, SimpleSpan<usize>)>,
|
||||||
extra::Err<Rich<'src, char, SimpleSpan<usize>>>,
|
extra::Err<Rich<'src, char, SimpleSpan<usize>>>,
|
||||||
> {
|
> {
|
||||||
let boolean = just("true")
|
let boolean = choice((
|
||||||
.or(just("false"))
|
just("true").padded().to(Token::Boolean(true)),
|
||||||
.map(|s: &str| Token::Boolean(s.parse().unwrap()));
|
just("false").padded().to(Token::Boolean(false)),
|
||||||
|
));
|
||||||
|
|
||||||
let float_numeric = just('-')
|
let float_numeric = just('-')
|
||||||
.or_not()
|
.or_not()
|
||||||
|
@ -164,7 +164,7 @@ pub fn parser<'src>() -> DustParser<'src> {
|
|||||||
|
|
||||||
let block = statement
|
let block = statement
|
||||||
.clone()
|
.clone()
|
||||||
.separated_by(just(Token::Control(";")).or_not())
|
.repeated()
|
||||||
.collect()
|
.collect()
|
||||||
.delimited_by(just(Token::Control("{")), just(Token::Control("}")))
|
.delimited_by(just(Token::Control("{")), just(Token::Control("}")))
|
||||||
.map(|statements| Statement::Block(Block::new(statements)))
|
.map(|statements| Statement::Block(Block::new(statements)))
|
||||||
@ -172,7 +172,7 @@ pub fn parser<'src>() -> DustParser<'src> {
|
|||||||
|
|
||||||
let r#loop = statement
|
let r#loop = statement
|
||||||
.clone()
|
.clone()
|
||||||
.separated_by(just(Token::Control(";")).or_not())
|
.repeated()
|
||||||
.collect()
|
.collect()
|
||||||
.delimited_by(
|
.delimited_by(
|
||||||
just(Token::Keyword("loop")).then(just(Token::Control("{"))),
|
just(Token::Keyword("loop")).then(just(Token::Control("{"))),
|
||||||
@ -182,6 +182,7 @@ pub fn parser<'src>() -> DustParser<'src> {
|
|||||||
.boxed();
|
.boxed();
|
||||||
|
|
||||||
choice((assignment, expression_statement, block, r#loop))
|
choice((assignment, expression_statement, block, r#loop))
|
||||||
|
.then_ignore(just(Token::Control(";")).or_not())
|
||||||
});
|
});
|
||||||
|
|
||||||
statement
|
statement
|
||||||
|
@ -2,8 +2,5 @@ use dust_lang::*;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn set_and_get_variable() {
|
fn set_and_get_variable() {
|
||||||
assert_eq!(
|
assert_eq!(interpret("foobar = true; foobar"), Ok(Value::boolean(true)));
|
||||||
interpret("foobar = true foobar"),
|
|
||||||
Ok(Value::boolean(true))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user