diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 5c7247b..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [] -} \ No newline at end of file diff --git a/lek/src/interpreter.rs b/lek/src/interpreter.rs index 24b3a5f..51c8593 100644 --- a/lek/src/interpreter.rs +++ b/lek/src/interpreter.rs @@ -13,7 +13,7 @@ pub struct Context<'a> { } impl<'a> Context<'a> { - pub fn new(symbol_table: &'a mut SymbolTable, angle_unit: Unit, precision: u32) -> Self { + pub fn new(symbol_table: &'a mut SymbolTable, angle_unit: &Unit, precision: u32) -> Self { Context { angle_unit: angle_unit.clone(), symbol_table, diff --git a/lek/src/parser.rs b/lek/src/parser.rs index 0f00dcd..6250a43 100644 --- a/lek/src/parser.rs +++ b/lek/src/parser.rs @@ -11,6 +11,7 @@ pub struct Context { tokens: Vec, pos: usize, symbol_table: SymbolTable, + angle_unit: Unit, } #[derive(Debug, Clone)] pub enum Unit { @@ -24,16 +25,18 @@ impl Context { tokens: Vec::new(), pos: 0, symbol_table: SymbolTable::new(), + angle_unit: Unit::Radians, } } + + pub fn set_angle_unit(mut self, unit: Unit) -> Self { + self.angle_unit = unit; + + self + } } -pub fn parse( - context: &mut Context, - input: &str, - angle_unit: Unit, - precision: u32, -) -> Result, String> { +pub fn parse(context: &mut Context, input: &str, precision: u32) -> Result, String> { context.tokens = Lexer::lex(input); context.pos = 0; @@ -42,7 +45,7 @@ pub fn parse( statements.push(parse_stmt(context)?); } let mut interpreter = - interpreter::Context::new(&mut context.symbol_table, angle_unit, precision); + interpreter::Context::new(&mut context.symbol_table, &context.angle_unit, precision); interpreter.interpret(statements) }