mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-06-22 18:51:22 +02:00
Created set_angle_unit() builder function for the parser context.
This commit is contained in:
parent
1e5159f84f
commit
bccbbee2c4
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
@ -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": []
|
|
||||||
}
|
|
@ -13,7 +13,7 @@ pub struct Context<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> 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 {
|
Context {
|
||||||
angle_unit: angle_unit.clone(),
|
angle_unit: angle_unit.clone(),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
|
@ -11,6 +11,7 @@ pub struct Context {
|
|||||||
tokens: Vec<Token>,
|
tokens: Vec<Token>,
|
||||||
pos: usize,
|
pos: usize,
|
||||||
symbol_table: SymbolTable,
|
symbol_table: SymbolTable,
|
||||||
|
angle_unit: Unit,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Unit {
|
pub enum Unit {
|
||||||
@ -24,16 +25,18 @@ impl Context {
|
|||||||
tokens: Vec::new(),
|
tokens: Vec::new(),
|
||||||
pos: 0,
|
pos: 0,
|
||||||
symbol_table: SymbolTable::new(),
|
symbol_table: SymbolTable::new(),
|
||||||
}
|
angle_unit: Unit::Radians,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(
|
pub fn set_angle_unit(mut self, unit: Unit) -> Self {
|
||||||
context: &mut Context,
|
self.angle_unit = unit;
|
||||||
input: &str,
|
|
||||||
angle_unit: Unit,
|
self
|
||||||
precision: u32,
|
}
|
||||||
) -> Result<Option<Float>, String> {
|
}
|
||||||
|
|
||||||
|
pub fn parse(context: &mut Context, input: &str, precision: u32) -> Result<Option<Float>, String> {
|
||||||
context.tokens = Lexer::lex(input);
|
context.tokens = Lexer::lex(input);
|
||||||
context.pos = 0;
|
context.pos = 0;
|
||||||
|
|
||||||
@ -42,7 +45,7 @@ pub fn parse(
|
|||||||
statements.push(parse_stmt(context)?);
|
statements.push(parse_stmt(context)?);
|
||||||
}
|
}
|
||||||
let mut interpreter =
|
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)
|
interpreter.interpret(statements)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user