Skip to content

Commit

Permalink
added basic interface of stage 2 parser
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Oct 15, 2023
1 parent 2ad683a commit 9b361f0
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ target_sources(dlplancore
parsers/elements/driver.cpp
parsers/elements/stage_1_ast/parser_instantiations.cpp
parsers/elements/stage_1_ast/parser.cpp
parsers/elements/stage_2_feature/context.cpp
parsers/elements/stage_2_feature/parser.cpp
elements/utils.cpp
../utils/logging.cpp
../utils/MurmurHash3.cpp
Expand Down
53 changes: 27 additions & 26 deletions src/core/parsers/elements/stage_1_ast/parser_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,32 +242,6 @@ namespace dlplan::core::parsers::elements::stage_1::parser

const auto position_def = int_;

const auto boolean_inner_def = empty_boolean | inclusion_boolean | nullary_boolean;

const auto boolean_def = boolean_inner_def;

// Note: non recursive comes first, i.e., primitive_concept
const auto concept_inner_def = primitive_concept | all_concept | and_concept | bot_concept | diff_concept | equal_concept | not_concept | one_of_concept | or_concept | projection_concept | some_concept | subset_concept | top_concept;

const auto concept_def = concept_inner_def;

const auto numerical_inner_def = concept_distance_numerical | count_numerical | role_distance_numerical | sum_concept_distance_numerical | sum_role_distance_numerical;

const auto numerical_def = numerical_inner;

// Note: non recursive comes first, i.e., primitive_role
const auto role_inner_def = primitive_role | and_role | compose_role | diff_role | identity_role | inverse_role | not_role | or_role | restrict_role | top_role | transitive_closure_role | transitive_reflexive_closure_role;

const auto role_def = role_inner;

const auto element_inner_def = boolean | concept | numerical | role;

const auto element_def = eps > element_inner;

const auto concept_or_role_inner_def = concept | role;

const auto concept_or_role_def = concept_or_role_inner;

const auto empty_boolean_def = lit("b_empty") > lit('(') > concept_or_role > lit(')');

const auto inclusion_boolean_def = lit("b_inclusion") > lit('(') > concept_or_role > lit(')');
Expand Down Expand Up @@ -337,6 +311,33 @@ namespace dlplan::core::parsers::elements::stage_1::parser

const auto transitive_reflexive_closure_role_def = lit("r_transitive_reflexive_closure") > lit('(') > role > lit(')');

const auto boolean_inner_def = empty_boolean | inclusion_boolean | nullary_boolean;

const auto boolean_def = boolean_inner_def;

// Note: non recursive comes first, i.e., primitive_concept
const auto concept_inner_def = primitive_concept | all_concept | and_concept | bot_concept | diff_concept | equal_concept | not_concept | one_of_concept | or_concept | projection_concept | some_concept | subset_concept | top_concept;

const auto concept_def = concept_inner_def;

const auto numerical_inner_def = concept_distance_numerical | count_numerical | role_distance_numerical | sum_concept_distance_numerical | sum_role_distance_numerical;

const auto numerical_def = numerical_inner;

// Note: non recursive comes first, i.e., primitive_role
const auto role_inner_def = primitive_role | and_role | compose_role | diff_role | identity_role | inverse_role | not_role | or_role | restrict_role | top_role | transitive_closure_role | transitive_reflexive_closure_role;

const auto role_def = role_inner;

const auto concept_or_role_inner_def = concept | role;

const auto concept_or_role_def = concept_or_role_inner;

const auto element_inner_def = boolean | concept | numerical | role;

const auto element_def = eps > element_inner;


BOOST_SPIRIT_DEFINE(
name, constant, predicate, position,
boolean_inner, boolean, concept_inner, concept, numerical_inner, numerical, role_inner, role, element_inner, element, concept_or_role_inner, concept_or_role,
Expand Down
9 changes: 9 additions & 0 deletions src/core/parsers/elements/stage_2_feature/context.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "context.hpp"


namespace dlplan::core::parsers::elements::stage_2 {

Context::Context(SyntacticElementFactory& element_factory)
: element_factory(element_factory) { }

}
20 changes: 20 additions & 0 deletions src/core/parsers/elements/stage_2_feature/context.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef SRC_CORE_PARSERS_ELEMENTS_STAGE_2_CONTEXT_HPP_
#define SRC_CORE_PARSERS_ELEMENTS_STAGE_2_CONTEXT_HPP_

#include <map>
#include <memory>
#include <string>

#include "include/dlplan/core.h"


namespace dlplan::core::parsers::elements::stage_2 {
/// @brief Provides additional context during parsing.
struct Context {
SyntacticElementFactory& element_factory;

Context(SyntacticElementFactory& element_factory);
};
}

#endif
36 changes: 36 additions & 0 deletions src/core/parsers/elements/stage_2_feature/parser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "parser.hpp"

#include <sstream>


namespace dlplan::core::parsers::elements::stage_2::parser {

std::shared_ptr<const Boolean> parse_boolean(
Context& context,
const error_handler_type& error_handler,
const stage_1::ast::Element& node) {

}

std::shared_ptr<const Numerical> parse_numerical(
Context& context,
const error_handler_type& error_handler,
const stage_1::ast::Element& node) {

}

std::shared_ptr<const Concept> parse_concept(
Context& context,
const error_handler_type& error_handler,
const stage_1::ast::Element& node) {

}

std::shared_ptr<const Role> parse_role(
Context& context,
const error_handler_type& error_handler,
const stage_1::ast::Element& node) {

}

}
40 changes: 40 additions & 0 deletions src/core/parsers/elements/stage_2_feature/parser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef SRC_CORE_PARSERS_ELEMENTS_STAGE_2_PARSER_HPP_
#define SRC_CORE_PARSERS_ELEMENTS_STAGE_2_PARSER_HPP_

#include <tuple>
#include <variant>

#include "include/dlplan/core.h"

#include "src/core/parsers/common/config.hpp"
#include "src/core/parsers/elements/stage_1_ast/ast.hpp"

#include "context.hpp"


namespace dlplan::core::parsers::elements::stage_2::parser {

extern std::shared_ptr<const Boolean> parse_boolean(
Context& context,
const error_handler_type& error_handler,
const stage_1::ast::Element& node);

extern std::shared_ptr<const Numerical> parse_numerical(
Context& context,
const error_handler_type& error_handler,
const stage_1::ast::Element& node);

extern std::shared_ptr<const Concept> parse_concept(
Context& context,
const error_handler_type& error_handler,
const stage_1::ast::Element& node);

extern std::shared_ptr<const Role> parse_role(
Context& context,
const error_handler_type& error_handler,
const stage_1::ast::Element& node);

}

#endif

0 comments on commit 9b361f0

Please sign in to comment.