Compare commits

..

No commits in common. "laptop" and "main" have entirely different histories.
laptop ... main

3 changed files with 31 additions and 48 deletions

View File

@ -1,17 +0,0 @@
test:
cargo test
build:
cargo build
scan-file FILENAME:
cargo run -- scan --file {{ FILENAME }}
scan COMMANDS:
cargo run -- scan "{{ COMMANDS }}"
compile COMMANDS:
cargo run -- run "{{ COMMANDS }}"
compile-file FILENAME:
cargo run -- run --file {{ FILENAME }}

View File

@ -14,7 +14,7 @@ pub struct Compiler<'a> {
}
impl<'a> Compiler<'a> {
pub fn from_source(source: &'a str) -> Self {
pub fn from_source(source: &'a String) -> Self {
Compiler {
scanner: Scanner::new(source),
chunk: None,
@ -31,17 +31,23 @@ impl<'a> Compiler<'a> {
self.expression();
//self.consume(TokenType::TokenEof, "Expect end of expression");
self.emit_return();
!self.had_error
return !self.had_error;
}
fn advance(&mut self) {
self.previous = self.current;
if let Some(Ok(token)) = self.scanner.next() {
self.previous = self.current.clone();
while let Some(r) = self.scanner.next() {
match r {
Ok(token) => {
self.current = Some(token);
} else {
break;
}
_ => {
self.error_at_current("error as current token");
}
}
}
}
fn expression(&mut self) {
()
@ -114,18 +120,18 @@ impl<'a> Compiler<'a> {
}
}
use strum_macros::Display;
#[derive(Display, PartialEq, Eq, PartialOrd, Ord)]
enum Precedence {
None,
Assignment,
Or,
And,
Equality,
Comparison,
Term,
Factor,
Unary,
Call,
Primary,
}
// use strum_macros::Display;
// #[derive(Display, PartialEq, Eq, PartialOrd, Ord)]
// enum Precedence {
// None,
// Assignment,
// Or,
// And,
// Equality,
// Comparison,
// Term,
// Factor,
// Unary,
// Call,
// Primary,
// }

View File

@ -101,9 +101,9 @@ fn scan_content(source: &str) {
fn run_content(source: &str) {
let mut _vm: VM = VM::new();
let owned = &source.to_owned();
let mut compiler: Compiler = Compiler::from_source(owned);
compiler.compile();
//todo!("run_content is not hooked up yet");
// let mut compiler: Compiler = Compiler::from_source(owned);
// compiler.compile();
todo!("run_content is not hooked up yet");
// let mut chunk: Chunk = compiler.compile();
// match vm.interpret(&mut chunk) {
// InterpretResult::InterpretOk => exit(0),
@ -111,9 +111,3 @@ fn run_content(source: &str) {
// InterpretResult::InterpretRuntimeError => exit(70),
// }
}
fn compile_content(source: &str) {
let mut _vm: VM = VM::new();
let owned = &source.to_owned();
let mut compiler: Compiler = Compiler::from_source(owned);
compiler.compile();
}