1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

fix a bit of parser

This commit is contained in:
Natapat Samutpong 2022-02-25 15:59:17 +07:00
parent a956b8c7d2
commit 16fca1cee6
3 changed files with 5 additions and 9 deletions

View file

@ -1,5 +1,6 @@
# Hycron # Hycron
Programming language that compiles to C Programming language that compiles to C
Note: The syntax can still be changed, if you have an idea, feel free to make an issues about it. Note: The syntax can still be changed, if you have an idea, feel free to make an issues about it.
# Prerequistie # Prerequistie

View file

@ -3,8 +3,10 @@ let bar: string = "str";
let baz: bool = true; let baz: bool = true;
fun qux (lhs: int rhs: int) -> int = lhs + rhs; fun qux (lhs: int rhs: int) -> int = lhs + rhs;
fun quux () -> string = "Hi, World!\n";
fun main () -> int = do fun main () -> int = do
let msg: string = "Hello, World!"; let msg: string = "Hello, World!\n";
write(msg); write(msg);
write(quux());
0; 0;
end; end;

View file

@ -35,7 +35,7 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>> {
.map(|s: String| Token::Float(s)); .map(|s: String| Token::Float(s));
let string = just('"') let string = just('"')
.ignore_then(filter(|c| *c != '\\' && *c != '"').repeated()) .ignore_then(filter(|c| *c != '"').repeated())
.then_ignore(just('"')) .then_ignore(just('"'))
.collect::<String>() .collect::<String>()
.map(|s: String| Token::String(s)); .map(|s: String| Token::String(s));
@ -134,8 +134,6 @@ pub enum Expr {
else_: Box<Self>, else_: Box<Self>,
}, },
Do { body: Vec<Self> }, Do { body: Vec<Self> },
Import(String),
} }
fn expr_parser() -> impl Parser<Token, Expr, Error = Simple<Token>> + Clone { fn expr_parser() -> impl Parser<Token, Expr, Error = Simple<Token>> + Clone {
@ -282,10 +280,6 @@ fn expr_parser() -> impl Parser<Token, Expr, Error = Simple<Token>> + Clone {
body: Box::new(body), body: Box::new(body),
}).labelled("function"); }).labelled("function");
let declare_import = just(Token::Import)
.ignore_then(ident.clone())
.map(Expr::Import);
let if_cond = just(Token::If) let if_cond = just(Token::If)
.ignore_then(expr.clone()) .ignore_then(expr.clone())
.then_ignore(just(Token::Then)) .then_ignore(just(Token::Then))
@ -307,7 +301,6 @@ fn expr_parser() -> impl Parser<Token, Expr, Error = Simple<Token>> + Clone {
declare_var declare_var
.or(declare_fun) .or(declare_fun)
.or(declare_import)
.or(if_cond) .or(if_cond)
.or(do_block) .or(do_block)
.or(expr) .or(expr)