aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdvard Thörnros <edvard.thornros@gmail.com>2021-02-23 20:02:26 +0100
committerEdvard Thörnros <edvard.thornros@gmail.com>2021-02-23 20:02:26 +0100
commit48a673f3cb6b5b1f7bb79808d596b1df36ab5f46 (patch)
treef0ba19fbd84d61ab2b703059a6f410ed57daf240
parentf6393ccf3f5c60bfe746ef33b7dc321c01b34be8 (diff)
downloadsylt-48a673f3cb6b5b1f7bb79808d596b1df36ab5f46.tar.gz
break the file up
-rw-r--r--src/compiler.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/compiler.rs b/src/compiler.rs
index b5959bb..aa491e6 100644
--- a/src/compiler.rs
+++ b/src/compiler.rs
@@ -343,9 +343,7 @@ fn split_sections<'a>(tokens: &'a TokenStream) -> Vec<&'a[PlacedToken]> {
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, _)))
+ (Some((Token::LeftBrace, _)), ..)
=> {
let mut blocks = 0;
loop {
@@ -356,6 +354,7 @@ fn split_sections<'a>(tokens: &'a TokenStream) -> Vec<&'a[PlacedToken]> {
}
Some((Token::RightBrace, _)) => {
+ curr += 1;
blocks -= 1;
if blocks <= 0 {
break;
@@ -369,12 +368,16 @@ fn split_sections<'a>(tokens: &'a TokenStream) -> Vec<&'a[PlacedToken]> {
_ => {}
}
}
-
- true
+ false
},
(Some((Token::Identifier(_), _)),
Some((Token::ColonColon, _)),
+ Some((Token::Fn, _)))
+ => true,
+
+ (Some((Token::Identifier(_), _)),
+ Some((Token::ColonColon, _)),
Some(_))
=> true,
@@ -545,10 +548,10 @@ impl<'a> Compiler<'a> {
/// The line of the current token.
fn line(&self) -> usize {
- if self.curr < self.section.len() {
- self.section[self.curr].1
+ if self.section.len() == 0 {
+ 0xCAFEBABE
} else {
- self.section[self.section.len() - 1].1
+ self.section[std::cmp::min(self.curr, self.section.len() - 1)].1
}
}
@@ -1507,7 +1510,7 @@ impl<'a> Compiler<'a> {
let section = self.sections[section];
self.init_section(section);
while self.peek() != Token::EOF {
- println!("compiling {} -- statement -- {:?}", s, self.peek());
+ println!("compiling {} -- statement -- {:?}", s, self.line());
self.statement(&mut block);
expect!(self, Token::Newline | Token::EOF,
"Expect newline or EOF after expression.");