NEURON
nmodl.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <catch2/catch_test_macros.hpp>
9 
10 #include "ast/program.hpp"
11 #include "parser/nmodl_driver.hpp"
13 #include "utils/test_utils.hpp"
14 #include "utils/common_utils.hpp"
17 
18 using namespace nmodl;
19 using namespace visitor;
20 using namespace test;
21 using namespace test_utils;
22 
24 
25 
26 //=============================================================================
27 // AST to NMODL printer tests
28 //=============================================================================
29 
30 std::string run_nmodl_visitor(const std::string& text) {
32  const auto& ast = driver.parse_string(text);
33 
34  std::stringstream stream;
35  NmodlPrintVisitor(stream).visit_program(*ast);
36 
37  // check that, after visitor rearrangement, parents are still up-to-date
39 
40  return stream.str();
41 }
42 
43 SCENARIO("Convert AST back to NMODL form", "[visitor][nmodl]") {
44  for (const auto& construct: nmodl_valid_constructs) {
45  auto test_case = construct.second;
46  const std::string& input_nmodl_text = reindent_text(test_case.input);
47  const std::string& output_nmodl_text = reindent_text(test_case.output);
48  GIVEN(test_case.name) {
49  THEN("Visitor successfully returns : " + input_nmodl_text) {
50  auto result = run_nmodl_visitor(input_nmodl_text);
51  REQUIRE(result == output_nmodl_text);
52  }
53  }
54  }
55 }
Visitor for checking parents of ast nodes
Class that binds all pieces together for parsing nmodl file.
Visitor for printing AST back to NMODL
void visit_program(const ast::Program &node) override
visit node of type ast::Program
Visitor for checking parents of ast nodes
int check_ast(const ast::Ast &node)
A small wrapper to have a nicer call in parser.cpp.
Common utility functions for file/dir manipulation.
bool parse_string(const std::string &input)
parser Units provided as string (used for testing)
Definition: unit_driver.cpp:40
std::map< std::string, NmodlTestCase > const nmodl_valid_constructs
std::string reindent_text(const std::string &text, int indent_level)
Reindent nmodl text for text-to-text comparison.
Definition: test_utils.cpp:55
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
std::string run_nmodl_visitor(const std::string &text)
Definition: nmodl.cpp:30
SCENARIO("Convert AST back to NMODL form", "[visitor][nmodl]")
Definition: nmodl.cpp:43
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
#define text
Definition: plot.cpp:60
Auto generated AST classes declaration.
nmodl::parser::UnitDriver driver
Definition: parser.cpp:28