From 6fe6d746e2bb4739d33f807ea100509e6dc62574 Mon Sep 17 00:00:00 2001 From: Reuben Gardos Reid <5456207+ReubenJ@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:35:41 +0300 Subject: [PATCH] Explicitly deprecate `SymbolTable` constructor Uses `grammar2symboltable` instead. --- src/utils.jl | 6 +++++- test/runtests.jl | 4 ++-- test/test_utils.jl | 15 ++++++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index e4158fd..9f4709f 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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} @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 448d21f..4e0e58c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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") diff --git a/test/test_utils.jl b/test/test_utils.jl index 2d22f72..0ed9523 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -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]) -end \ No newline at end of file + st = grammar2symboltable(g, DefiningAVariable) + @test st[:x] == 1 + + st = SymbolTable(g, DefiningAVariable) + @test st[:x] == 1 +end