From 2ef2421fb869972157b898d6689bf075badc6f18 Mon Sep 17 00:00:00 2001 From: Tilman Hinnerichs Date: Mon, 26 Feb 2024 11:52:41 +0100 Subject: [PATCH] Grammar -> AbstractGrammar according to HerbCore 0.2, HerbGrammar -> 0.2 --- Project.toml | 10 +++++----- src/interpreter.jl | 16 ++++++++-------- test/test_execute_on_input.jl | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Project.toml b/Project.toml index 2a2c6ba..b268ead 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "HerbInterpret" uuid = "5bbddadd-02c5-4713-84b8-97364418cca7" authors = ["Tilman Hinnerichs ", "Jaap de Jong ", "Sebastijan Dumancic ", "Reuben Gardos Reid "] -version = "0.1.1" +version = "0.1.2" [deps] HerbCore = "2b23ba43-8213-43cb-b5ea-38c12b45bd45" @@ -9,10 +9,10 @@ HerbGrammar = "4ef9e186-2fe5-4b24-8de7-9f7291f24af7" HerbSpecification = "6d54aada-062f-46d8-85cf-a1ceaf058a06" [compat] -HerbCore = "0.1.1" -HerbGrammar = "0.1.0" -HerbSpecification = "0.1.0" -julia = "1.8" +HerbCore = "^0.2.0" +HerbGrammar = "^0.2.0" +HerbSpecification = "^0.1.0" +julia = "^1.8" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/src/interpreter.jl b/src/interpreter.jl index 4f53134..3a8f6f9 100644 --- a/src/interpreter.jl +++ b/src/interpreter.jl @@ -89,38 +89,38 @@ function execute_on_input(tab::SymbolTable, expr::Any, input::Vector{T})::Vector end """ - execute_on_input(grammar::Grammar, program::RuleNode, input::Dict{Symbol, T})::Any where T + execute_on_input(grammar::AbstractGrammar, program::RuleNode, input::Dict{Symbol, T})::Any where T Converts a `RuleNode` program into an expression using a given `grammar`, then evaluates this expression with a single input dictionary `input` and a symbol table derived from the `grammar` using [`execute_on_input(tab::SymbolTable, expr::Any, input::Dict{Symbol, T})`](@ref). # Arguments -- `grammar::Grammar`: A grammar object used to convert the `RuleNode` into an executable expression. +- `grammar::AbstractGrammar`: A grammar object used to convert the `RuleNode` into an executable expression. - `program::RuleNode`: The program, represented as a `RuleNode`, to be converted and evaluated. - `input::Dict{Symbol, T}`: A dictionary providing input values for symbols used in the generated expression. # Returns - `Any`: The result of evaluating the generated expression with the given input dictionary. """ -function execute_on_input(grammar::Grammar, program::RuleNode, input::Dict{Symbol, T})::Any where T +function execute_on_input(grammar::AbstractGrammar, program::RuleNode, input::Dict{Symbol, T})::Any where T expression = rulenode2expr(program, grammar) symboltable = SymbolTable(grammar) return execute_on_input(symboltable, expression, input) end """ - execute_on_input(grammar::Grammar, program::RuleNode, input::Vector{T})::Vector{Any} where T <: Dict{Symbol, <:Any} + execute_on_input(grammar::AbstractGrammar, program::RuleNode, input::Vector{T})::Vector{Any} where T <: Dict{Symbol, <:Any} Converts a `RuleNode` program into an expression using a given `grammar`, then evaluates this expression for each input dictionary in a vector `input` and a symbol table derived from the `grammar` using [`execute_on_input(tab::SymbolTable, expr::Any, input::Dict{Symbol, T})`](@ref). # Arguments -- `grammar::Grammar`: A grammar object used to convert the `RuleNode` into an executable expression. +- `grammar::AbstractGrammar`: A grammar object used to convert the `RuleNode` into an executable expression. - `program::RuleNode`: The program, represented as a `RuleNode`, to be converted and evaluated. - `input::Vector{T}`: A vector of dictionaries, each providing input values for symbols used in the generated expression. # Returns - `Vector{Any}`: A vector containing the results of evaluating the generated expression for each input dictionary. """ -function execute_on_input(grammar::Grammar, program::RuleNode, input::Vector{T})::Vector{Any} where T <: Dict{Symbol, <:Any} +function execute_on_input(grammar::AbstractGrammar, program::RuleNode, input::Vector{T})::Vector{Any} where T <: Dict{Symbol, <:Any} expression = rulenode2expr(program, grammar) symboltable = SymbolTable(grammar) return execute_on_input(symboltable, expression, input) @@ -128,11 +128,11 @@ end """ - evaluate_program(program::RuleNode, examples::Vector{<:IOExample}, grammar::Grammar, evaluation_function::Function) + evaluate_program(program::RuleNode, examples::Vector{<:IOExample}, grammar::AbstractGrammar, evaluation_function::Function) Runs a program on the examples and returns tuples of actual desired output and the program's output """ -function evaluate_program(program::RuleNode, examples::Vector{<:IOExample}, grammar::Grammar, evaluation_function::Function) +function evaluate_program(program::RuleNode, examples::Vector{<:IOExample}, grammar::AbstractGrammar, evaluation_function::Function) depwarn("`evaluate_program` is deprecated and should no longer be used. Please use HerbSearch.evaluate instead.", :evaluate_program) results = Tuple{<:Number,<:Number}[] diff --git a/test/test_execute_on_input.jl b/test/test_execute_on_input.jl index 104b5ed..2b57840 100644 --- a/test/test_execute_on_input.jl +++ b/test/test_execute_on_input.jl @@ -46,7 +46,7 @@ end end end - @testset "With Grammar and RuleNode" begin + @testset "With grammar and RuleNode" begin grammar = create_dummy_grammar() # integer arithmetic program = create_dummy_rulenode() # :(1+x)