Skip to content

Commit

Permalink
refactor(ast)!: refactor SymbolTable interface to hide implementati…
Browse files Browse the repository at this point in the history
…on details

Change the `SymbolTable` to be a struct with private members, and create
a new interface to interact with it. This hides the fact that the
`SymbolTable` is a `BTreeMap`.

While the symbol table is a simple `BTreeMap` both before and after this
commit, the implementation of this is likely to change multiple times in
the future. In particular, this commit is preparation for adding
`lettings` and `givens` to the symbol table.
  • Loading branch information
niklasdewally committed Jan 30, 2025
1 parent 76606ac commit e615d7d
Show file tree
Hide file tree
Showing 184 changed files with 8,581 additions and 8,094 deletions.
10 changes: 4 additions & 6 deletions conjure_oxide/src/utils/essence_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use std::sync::{Arc, RwLock};
use tree_sitter::{Node, Parser, Tree};
use tree_sitter_essence::LANGUAGE;

use conjure_core::ast::{
Atom, DecisionVariable, Domain, Expression, Literal, Name, Range, SymbolTable,
};
use conjure_core::ast::{Atom, DecisionVariable, Domain, Expression, Literal, Name, Range};

use crate::utils::conjure::EssenceParseError;
use conjure_core::context::Context;
Expand Down Expand Up @@ -72,7 +70,7 @@ fn parse_find_statement(
find_statement_list: Node,
source_code: &str,
) -> BTreeMap<Name, DecisionVariable> {
let mut symbol_table = SymbolTable::new();
let mut vars = BTreeMap::new();

for find_statement in named_children(&find_statement_list) {
let mut temp_symbols = BTreeSet::new();
Expand All @@ -92,10 +90,10 @@ fn parse_find_statement(

for name in temp_symbols {
let decision_variable = DecisionVariable::new(domain.clone());
symbol_table.insert(Name::UserName(String::from(name)), decision_variable);
vars.insert(Name::UserName(String::from(name)), decision_variable);
}
}
symbol_table
vars
}

fn parse_domain(domain: Node, source_code: &str) -> Domain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,26 @@
]
}
],
"next_var": 0,
"variables": [
[
{
"UserName": "x"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
-2,
3
]
}
]
"symbols": {
"next_machine_name": 0,
"variables": [
[
{
"UserName": "x"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
-2,
3
]
}
]
}
}
}
]
]
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,26 @@
]
}
],
"next_var": 0,
"variables": [
[
{
"UserName": "x"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
-2,
3
]
}
]
"symbols": {
"next_machine_name": 0,
"variables": [
[
{
"UserName": "x"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
-2,
3
]
}
]
}
}
}
]
]
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,41 +74,43 @@
]
}
],
"next_var": 0,
"variables": [
[
{
"UserName": "x"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
-5,
5
]
}
]
"symbols": {
"next_machine_name": 0,
"variables": [
[
{
"UserName": "x"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
-5,
5
]
}
]
}
}
}
],
[
{
"UserName": "y"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
-5,
5
]
}
]
],
[
{
"UserName": "y"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
-5,
5
]
}
]
}
}
}
]
]
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,75 +97,77 @@
]
}
],
"next_var": 2,
"variables": [
[
{
"MachineName": 0
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
0,
5
]
}
]
"symbols": {
"next_machine_name": 2,
"variables": [
[
{
"MachineName": 0
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
0,
5
]
}
]
}
}
}
],
[
{
"MachineName": 1
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
0,
5
]
}
]
],
[
{
"MachineName": 1
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
0,
5
]
}
]
}
}
}
],
[
{
"UserName": "x"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
-5,
5
]
}
]
],
[
{
"UserName": "x"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
-5,
5
]
}
]
}
}
}
],
[
{
"UserName": "y"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
-5,
5
]
}
]
],
[
{
"UserName": "y"
},
{
"domain": {
"IntDomain": [
{
"Bounded": [
-5,
5
]
}
]
}
}
}
]
]
]
}
}
Loading

0 comments on commit e615d7d

Please sign in to comment.