diff options
| -rw-r--r-- | progs/tests/simple.sy | 25 | ||||
| -rw-r--r-- | src/compiler.rs | 39 |
2 files changed, 61 insertions, 3 deletions
diff --git a/progs/tests/simple.sy b/progs/tests/simple.sy index 12a43c0..84bc86d 100644 --- a/progs/tests/simple.sy +++ b/progs/tests/simple.sy @@ -1,2 +1,23 @@ -print extern_test(3.0) -print extern_test(3.0, 4.0, 5.0) +// +// import A + +// +f :: fn { + g! + print q +} + +// +q :: 1 + +// +a := 1 + +qq :: fn { + g! + print q +} + + +// Steg 1: Hitta sektioner +// Dela sektioner, compilera felera sektioner efter varandra diff --git a/src/compiler.rs b/src/compiler.rs index e8c7c62..31ae434 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -5,7 +5,7 @@ use std::rc::Rc; use crate::{Blob, Block, Op, Prog, RustFunction, Type, Value}; use crate::error::{Error, ErrorKind}; -use crate::tokenizer::{Token, TokenStream}; +use crate::tokenizer::{Token, PlacedToken, TokenStream}; macro_rules! nextable_enum { ( $name:ident { $( $thing:ident ),* $( , )? } ) => { @@ -335,8 +335,45 @@ fn add_op(compiler: &Compiler, block: &mut Block, op: Op) -> usize { block.add(op, compiler.line()) } +fn split_sections<'a>(tokens: &'a TokenStream) -> Vec<&'a[PlacedToken]> { + let mut sections = Vec::new(); + + let mut last = 0; + let mut curr = 0; + while curr < tokens.len() { + if match (tokens.get(curr + 0), tokens.get(curr + 1), tokens.get(curr + 2)) { + (Some((Token::Identifier(_), _)), + Some((Token::ColonColon, _)), + Some((Token::Fn, _))) + => true, + + (Some((Token::Identifier(_), _)), + Some((Token::ColonColon, _)), + Some(_)) + => true, + + (Some((Token::Identifier(_), _)), + Some((Token::ColonEqual, _)), + Some(_)) + => true, + + _ => false, + } { + sections.push(&tokens[last..curr]); + last = curr; + } + curr += 1; + } + sections +} + impl Compiler { pub(crate) fn new(current_file: &Path, tokens: TokenStream) -> Self { + { + let sections = split_sections(&tokens); + println!("{:#?}", sections); + } + Self { curr: 0, tokens, |
