Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
publicmatt | 8bb55d110a |
|
@ -0,0 +1,17 @@
|
||||||
|
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 }}
|
|
@ -14,7 +14,7 @@ pub struct Compiler<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Compiler<'a> {
|
impl<'a> Compiler<'a> {
|
||||||
pub fn from_source(source: &'a String) -> Self {
|
pub fn from_source(source: &'a str) -> Self {
|
||||||
Compiler {
|
Compiler {
|
||||||
scanner: Scanner::new(source),
|
scanner: Scanner::new(source),
|
||||||
chunk: None,
|
chunk: None,
|
||||||
|
@ -31,23 +31,17 @@ impl<'a> Compiler<'a> {
|
||||||
self.expression();
|
self.expression();
|
||||||
//self.consume(TokenType::TokenEof, "Expect end of expression");
|
//self.consume(TokenType::TokenEof, "Expect end of expression");
|
||||||
self.emit_return();
|
self.emit_return();
|
||||||
return !self.had_error;
|
!self.had_error
|
||||||
}
|
}
|
||||||
|
|
||||||
fn advance(&mut self) {
|
fn advance(&mut self) {
|
||||||
self.previous = self.current.clone();
|
self.previous = self.current;
|
||||||
while let Some(r) = self.scanner.next() {
|
if let Some(Ok(token)) = self.scanner.next() {
|
||||||
match r {
|
|
||||||
Ok(token) => {
|
|
||||||
self.current = Some(token);
|
self.current = Some(token);
|
||||||
break;
|
} else {
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
self.error_at_current("error as current token");
|
self.error_at_current("error as current token");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn expression(&mut self) {
|
fn expression(&mut self) {
|
||||||
()
|
()
|
||||||
|
@ -120,18 +114,18 @@ impl<'a> Compiler<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use strum_macros::Display;
|
use strum_macros::Display;
|
||||||
// #[derive(Display, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Display, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
// enum Precedence {
|
enum Precedence {
|
||||||
// None,
|
None,
|
||||||
// Assignment,
|
Assignment,
|
||||||
// Or,
|
Or,
|
||||||
// And,
|
And,
|
||||||
// Equality,
|
Equality,
|
||||||
// Comparison,
|
Comparison,
|
||||||
// Term,
|
Term,
|
||||||
// Factor,
|
Factor,
|
||||||
// Unary,
|
Unary,
|
||||||
// Call,
|
Call,
|
||||||
// Primary,
|
Primary,
|
||||||
// }
|
}
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -101,9 +101,9 @@ fn scan_content(source: &str) {
|
||||||
fn run_content(source: &str) {
|
fn run_content(source: &str) {
|
||||||
let mut _vm: VM = VM::new();
|
let mut _vm: VM = VM::new();
|
||||||
let owned = &source.to_owned();
|
let owned = &source.to_owned();
|
||||||
// let mut compiler: Compiler = Compiler::from_source(owned);
|
let mut compiler: Compiler = Compiler::from_source(owned);
|
||||||
// compiler.compile();
|
compiler.compile();
|
||||||
todo!("run_content is not hooked up yet");
|
//todo!("run_content is not hooked up yet");
|
||||||
// let mut chunk: Chunk = compiler.compile();
|
// let mut chunk: Chunk = compiler.compile();
|
||||||
// match vm.interpret(&mut chunk) {
|
// match vm.interpret(&mut chunk) {
|
||||||
// InterpretResult::InterpretOk => exit(0),
|
// InterpretResult::InterpretOk => exit(0),
|
||||||
|
@ -111,3 +111,9 @@ fn run_content(source: &str) {
|
||||||
// InterpretResult::InterpretRuntimeError => exit(70),
|
// 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();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue