parser works for var decl with assignment
This commit is contained in:
parent
6756d286f9
commit
8ce2b5aad2
6 changed files with 139 additions and 124 deletions
25
src/main.rs
25
src/main.rs
|
|
@ -1,12 +1,14 @@
|
|||
use chumsky::input::{Input, Stream};
|
||||
use chumsky::prelude::end;
|
||||
use chumsky::Parser;
|
||||
use logos::Logos;
|
||||
|
||||
use crate::language_frontend::abstract_syntax_tree::parser::parse;
|
||||
|
||||
mod language_frontend;
|
||||
|
||||
use crate::{
|
||||
language_frontend::lexer::tokens::Token, language_frontend::abstract_syntax_tree::parser::parse};
|
||||
|
||||
use crate::language_frontend::abstract_syntax_tree::ast::{Expr};
|
||||
|
||||
/*
|
||||
Simple Compiler -> 4 Stages:
|
||||
- lex
|
||||
|
|
@ -24,17 +26,24 @@ fn main() {
|
|||
|
||||
println!("{:?}", sourcecode);
|
||||
|
||||
/*
|
||||
|
||||
let lexer = Token::lexer(&sourcecode)
|
||||
.spanned();
|
||||
//.collect::<Vec<_>>();
|
||||
.spanned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for token in lexer {
|
||||
println!("{:?}", token);
|
||||
}
|
||||
*/
|
||||
|
||||
let token_iter = Token::lexer(&sourcecode).spanned().map(|(tok, span)| tok.map(|t| (t, span))).filter_map(Result::ok);
|
||||
|
||||
match parse(&sourcecode) {
|
||||
let token_stream = Stream::from_iter(token_iter)
|
||||
// Tell chumsky to split the (Token, SimpleSpan) stream into its parts so that it can handle the spans for us
|
||||
// This involves giving chumsky an 'end of input' span: we just use a zero-width span at the end of the string
|
||||
.map((0..sourcecode.len()).into(), |(t, s): (_, _)| (t, s));
|
||||
|
||||
|
||||
match parse(&sourcecode) {
|
||||
Ok(res) => println!("{:?}", res),
|
||||
Err(e) => {
|
||||
panic!("{:#?}", e)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue