From 8c7e5d47f762cc89a7b20eaeecc8740f2a0e8617 Mon Sep 17 00:00:00 2001 From: Reuben Gardos Reid <5456207+ReubenJ@users.noreply.github.com> Date: Fri, 15 Nov 2024 17:15:59 +0100 Subject: [PATCH] Move pirated functions reported by Aqua to `HerbCore` --- Project.toml | 5 ++--- src/HerbGrammar.jl | 1 - src/grammar_base.jl | 8 -------- src/rulenode_operators.jl | 14 -------------- src/utils.jl | 11 +++-------- 5 files changed, 5 insertions(+), 34 deletions(-) diff --git a/Project.toml b/Project.toml index adf1d73..31d5844 100644 --- a/Project.toml +++ b/Project.toml @@ -1,18 +1,17 @@ name = "HerbGrammar" uuid = "4ef9e186-2fe5-4b24-8de7-9f7291f24af7" authors = ["Sebastijan Dumancic ", "Jaap de Jong ", "Nicolae Filat ", "Piotr Cichoń "] -version = "0.4.0" +version = "0.5.0" [deps] -AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" HerbCore = "2b23ba43-8213-43cb-b5ea-38c12b45bd45" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" TreeView = "39424ebd-4cf3-5550-a685-96706a953f40" [compat] -AbstractTrees = "^0.4" DataStructures = "0.17,0.18" HerbCore = "^0.3.0" +Serialization = "^1.8,^1.10,^1.11" TreeView = "^0.5" julia = "^1.8" diff --git a/src/HerbGrammar.jl b/src/HerbGrammar.jl index 3335c34..2041dc5 100644 --- a/src/HerbGrammar.jl +++ b/src/HerbGrammar.jl @@ -1,7 +1,6 @@ module HerbGrammar import TreeView: walk_tree -using AbstractTrees using DataStructures # NodeRecycler using Serialization # grammar_io diff --git a/src/grammar_base.jl b/src/grammar_base.jl index acc9ef6..83b6619 100644 --- a/src/grammar_base.jl +++ b/src/grammar_base.jl @@ -45,7 +45,6 @@ function get_childtypes(rule::Any, types::AbstractVector{Symbol}) return retval end -Base.getindex(grammar::AbstractGrammar, typ::Symbol) = grammar.bytype[typ] """ nonterminals(grammar::AbstractGrammar)::Vector{Symbol} @@ -183,13 +182,6 @@ Returns the maximum arity (number of children) over all production rules in the max_arity(grammar::AbstractGrammar)::Int = maximum(length(cs) for cs in grammar.childtypes) -function Base.show(io::IO, grammar::AbstractGrammar) - for i in eachindex(grammar.rules) - println(io, i, ": ", grammar.types[i], " = ", grammar.rules[i]) - end -end - - """ add_rule!(g::AbstractGrammar, e::Expr) diff --git a/src/rulenode_operators.jl b/src/rulenode_operators.jl index e9f395b..4581e30 100644 --- a/src/rulenode_operators.jl +++ b/src/rulenode_operators.jl @@ -1,8 +1,3 @@ -HerbCore.RuleNode(ind::Int, grammar::AbstractGrammar) = RuleNode(ind, nothing, [Hole(get_domain(grammar, type)) for type ∈ grammar.childtypes[ind]]) -HerbCore.RuleNode(ind::Int, _val::Any, grammar::AbstractGrammar) = RuleNode(ind, _val, [Hole(get_domain(grammar, type)) for type ∈ grammar.childtypes[ind]]) - -HerbCore.UniformHole(domain::BitVector, grammar::AbstractGrammar) = UniformHole(domain, [Hole(get_domain(grammar, type)) for type ∈ grammar.childtypes[findfirst(domain)]]) - rulesoftype(::Hole, ::Set{Int}) = Set{Int}() """ @@ -344,12 +339,3 @@ function contains_returntype(node::RuleNode, grammar::AbstractGrammar, sym::Symb end return false end - -function Base.display(rulenode::RuleNode, grammar::AbstractGrammar) - root = rulenode2expr(rulenode, grammar) - if isa(root, Expr) - walk_tree(root) - else - root - end -end diff --git a/src/utils.jl b/src/utils.jl index 3eaf4b2..be853ba 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1,8 +1,3 @@ -# Interface to AbstractTrees.jl -AbstractTrees.children(node::RuleNode) = node.children -AbstractTrees.printnode(io::IO, node::RuleNode) = print(io, node.ind) - - """ mindepth_map(grammar::AbstractGrammar) @@ -45,15 +40,15 @@ end Data structure for mapping terminal symbols in the [`AbstractGrammar`](@ref) to their Julia interpretation. """ -const SymbolTable = Dict{Symbol,Any} +const SymbolTable{I} = Dict{Symbol,I} """ - SymbolTable(grammar::AbstractGrammar, mod::Module=Main) + grammar2symboltable(grammar::AbstractGrammar, mod::Module=Main) Returns a [`SymbolTable`](@ref) populated with a mapping from symbols in the [`AbstractGrammar`](@ref) to symbols in module `mod` or `Main`, if defined. """ -function HerbGrammar.SymbolTable(grammar::AbstractGrammar, mod::Module=Main) +function grammar2symboltable(grammar::AbstractGrammar, mod::Module=Main) tab = SymbolTable() for rule in grammar.rules _add_to_symboltable!(tab, rule, mod)