Skip to content

Commit

Permalink
Prefix StringInterner keywords properties to avoid clash with rust ke…
Browse files Browse the repository at this point in the history
…ywords
  • Loading branch information
Cypher1 committed Apr 27, 2024
1 parent 797f513 commit 3ce69fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
39 changes: 21 additions & 18 deletions takolib/src/ast/string_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ pub struct StringInterner {
// BUT: We can also merge the hashes without losing any information.
pub loc2string: Arc<BTreeMap<IndexIntoFile, StrId>>,
pub strings: Arc<BTreeMap<StrId, String>>,
pub lambda: StrId,
pub pi: StrId,
pub forall: StrId,
pub exists: StrId,
pub r#use: StrId,
pub provide: StrId,
pub kw_lambda: StrId,
pub kw_pi: StrId,
pub kw_forall: StrId,
pub kw_exists: StrId,
pub kw_use: StrId,
pub kw_provide: StrId,
pub kw_public: StrId,
}

impl Default for StringInterner {
Expand All @@ -35,19 +36,21 @@ impl Default for StringInterner {
loc2string: Arc::new(BTreeMap::new()),
strings: Arc::new(BTreeMap::new()),
// These are, temporarily, invalid.
lambda: TypedIndex::max_value(),
pi: TypedIndex::max_value(),
forall: TypedIndex::max_value(),
exists: TypedIndex::max_value(),
r#use: TypedIndex::max_value(),
provide: TypedIndex::max_value(),
kw_lambda: TypedIndex::max_value(),
kw_pi: TypedIndex::max_value(),
kw_forall: TypedIndex::max_value(),
kw_exists: TypedIndex::max_value(),
kw_use: TypedIndex::max_value(),
kw_provide: TypedIndex::max_value(),
kw_public: TypedIndex::max_value(),
};
n.lambda = n.register_str("lambda");
n.pi = n.register_str("pi");
n.forall = n.register_str("forall");
n.exists = n.register_str("exists");
n.r#use = n.register_str("use");
n.provide = n.register_str("provide");
n.kw_lambda = n.register_str("lambda");
n.kw_pi = n.register_str("pi");
n.kw_forall = n.register_str("forall");
n.kw_exists = n.register_str("exists");
n.kw_use = n.register_str("use");
n.kw_provide = n.register_str("provide");
n.kw_public = n.register_str("public");
for key in KEYWORDS.iter() {
n.register_str(key);
}
Expand Down
8 changes: 4 additions & 4 deletions takolib/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,13 @@ pub fn parse(filepath: &Path, contents: &str, tokens: &[Token]) -> Result<Ast, T

fn normalize_keywords_as_ops(ast: &Ast, name: Identifier) -> TokenType {
let interner = &ast.string_interner;
let op = if name == interner.lambda {
let op = if name == interner.kw_lambda {
Symbol::Lambda
} else if name == interner.pi {
} else if name == interner.kw_pi {
Symbol::Pi
} else if name == interner.forall {
} else if name == interner.kw_forall {
Symbol::Forall
} else if name == interner.exists {
} else if name == interner.kw_exists {
Symbol::Exists
} else {
return TokenType::Ident;
Expand Down

0 comments on commit 3ce69fc

Please sign in to comment.