Skip to content

Commit

Permalink
Explicitly deprecate SymbolTable constructor
Browse files Browse the repository at this point in the history
Uses `grammar2symboltable` instead.
  • Loading branch information
ReubenJ committed Nov 26, 2024
1 parent 3cc21e5 commit 9bd7afb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ end
"""
SymbolTable
Data structure for mapping terminal symbols in the [`AbstractGrammar`](@ref) to their Julia interpretation.
Type alias for a `Dict` that maps terminal symbols in the [`AbstractGrammar`](@ref)
to their Julia interpretation.
"""
const SymbolTable = Dict{Symbol,Any}

Expand All @@ -56,6 +57,9 @@ function grammar2symboltable(grammar::AbstractGrammar, mod::Module=Main)
tab
end

# When we eventually remove this deprecation, also remove `SymbolTables` from
# the `treat_as_own` option in `test/runtests.jl`
@deprecate SymbolTable(g::AbstractGrammar, m::Module=Main) grammar2symboltable(g, m)

_add_to_symboltable!(tab::SymbolTable, rule::Any, mod::Module) = true

Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ using HerbCore
using HerbGrammar
using Test

@testset "HerbGrammar.jl" verbose=true begin
@testset "Aqua.jl Checks" Aqua.test_all(HerbGrammar)
@testset "HerbGrammar.jl" verbose = true begin
@testset "Aqua.jl Checks" Aqua.test_all(HerbGrammar; piracies=(treat_as_own=[SymbolTable],))
include("test_csg.jl")
include("test_rulenode_operators.jl")
include("test_rulenode2expr.jl")
Expand Down
13 changes: 9 additions & 4 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
@testset "SymbolTable Tests" begin
module DefiningAVariable
x = 1
g₁ = @cfgrammar begin
end
@testset "SymbolTable Tests" begin
g = @cfgrammar begin
Real = |(1:9)
Real = x
end

st = grammar2symboltable(g₁)
@test !isnothing(st[:x])
st = grammar2symboltable(g, DefiningAVariable)
@test st[:x] == 1

st = SymbolTable(g, DefiningAVariable)
@test st[:x] == 1
end

0 comments on commit 9bd7afb

Please sign in to comment.