From 82226c508c9d19da3ee72defed4f8c723b79ebee Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Mon, 20 Aug 2018 15:58:09 +0200 Subject: [PATCH] Add simple language infrastructure simple tests of PEGTL based on the PEGTL reversed Hello, World! example --- CMakeLists.txt | 4 +++- src/CMakeLists.txt | 4 ++++ src/language/CMakeLists.txt | 13 +++++++++++ src/language/PastisParser.cpp | 44 +++++++++++++++++++++++++++++++++++ src/language/PastisParser.hpp | 8 +++++++ src/main.cpp | 6 +++++ 6 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/language/CMakeLists.txt create mode 100644 src/language/PastisParser.cpp create mode 100644 src/language/PastisParser.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f04ce0f29..9223a9adb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,10 +134,11 @@ add_subdirectory(src) include_directories(src) include_directories(src/algebra) +include_directories(src/language) include_directories(src/mesh) include_directories(src/output) -include_directories(src/utils) include_directories(src/scheme) +include_directories(src/utils) include_directories(src/experimental) @@ -219,5 +220,6 @@ target_link_libraries( pastis kokkos PastisUtils + PastisLanguage PastisMesh PastisExperimental) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fcc3e886e..1a59893e1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,10 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(utils) include_directories(utils) +# Pastis language +add_subdirectory(language) +include_directories(language) + # Pastis algebra #add_subdirectory(algebra) include_directories(algebra) diff --git a/src/language/CMakeLists.txt b/src/language/CMakeLists.txt new file mode 100644 index 000000000..31b2bb1bc --- /dev/null +++ b/src/language/CMakeLists.txt @@ -0,0 +1,13 @@ +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +# ------------------- Source files -------------------- + +add_library( + PastisLanguage + PastisParser.cpp) + +#include_directories(${PASTIS_SOURCE_DIR}/utils) + +# Additional dependencies +#add_dependencies(PastisMesh) diff --git a/src/language/PastisParser.cpp b/src/language/PastisParser.cpp new file mode 100644 index 000000000..7be5c4e94 --- /dev/null +++ b/src/language/PastisParser.cpp @@ -0,0 +1,44 @@ +#include <PastisParser.hpp> +#include <iostream> + +#define TAO_PEGTL_NAMESPACE language +#include <pegtl.hpp> +namespace language +{ +using namespace tao::language; + +// clang-format off +//struct prefix : string< 'H', 'e', 'l', 'l', 'o', ',', ' ' > {}; +struct prefix : TAO_PEGTL_STRING("Hello, ") {}; +struct name : plus< alpha > {}; +struct grammar + : must< prefix, name, star< sor< space, digit, string < '+' >, string < '-' >, string < '/' >, string < '*' > > >, one< '!' >, eof > +{ +}; +// clang-format on + +template< typename Rule > +struct action + : nothing< Rule > +{ +}; + +template<> +struct action< name > +{ + template< typename Input > + static void apply( const Input& in, std::string& v ) + { + v = in.string(); + } +}; +} + +void parser(const std::string& in_flow) { + std::string name; + language::string_input in( in_flow , std::string("source_name")); + language::parse< language::grammar, language::action >( in, name ); + + std::cout << in_flow << " -> "; + std::cout << "Good bye, " << name << "!" << std::endl; +} diff --git a/src/language/PastisParser.hpp b/src/language/PastisParser.hpp new file mode 100644 index 000000000..0c68127d4 --- /dev/null +++ b/src/language/PastisParser.hpp @@ -0,0 +1,8 @@ +#ifndef PASTIS_PARSER_HPP +#define PASTIS_PARSER_HPP + +#include <string> + +void parser(const std::string& in_flow); + +#endif // PASTIS_PARSER_HPP diff --git a/src/main.cpp b/src/main.cpp index f277ce412..2bfab31ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,7 @@ #include <MeshNodeBoundary.hpp> #include <GmshReader.hpp> +#include <PastisParser.hpp> #include <CLI/CLI.hpp> #include <limits> @@ -36,6 +37,11 @@ int main(int argc, char *argv[]) { + if (argc == 2) { + parser(argv[1]); + return 0; + } + long unsigned number = 10; std::string filename; { -- GitLab