10 #include <catch2/catch_test_macros.hpp>
16 using namespace nmodl;
20 using parser::NmodlParser;
21 using Token = NmodlParser::token;
28 std::istringstream ss(
name);
29 std::istream& in = ss;
37 auto get_token_type = [](
TokenType token) {
38 return parser::NmodlParser::by_type(token).type_get();
47 if (
token_type == get_token_type(Token::NAME) ||
50 token_type == get_token_type(Token::VALENCE) ||
54 REQUIRE(!
value.get_node_name().empty());
58 else if (
token_type == get_token_type(Token::PRIME)) {
60 REQUIRE(!
value.get_node_name().empty());
63 else if (
token_type == get_token_type(Token::INTEGER)) {
65 REQUIRE(
value.get_value() != 0);
68 else if (
token_type == get_token_type(Token::REAL)) {
70 REQUIRE(
value.to_double() != 0);
75 REQUIRE(!
value.get_value().empty());
78 else if (
token_type == get_token_type(Token::VERBATIM) ||
79 token_type == get_token_type(Token::BLOCK_COMMENT) ||
80 token_type == get_token_type(Token::LINE_PART)) {
81 auto value = sym.value.as<std::string>();
82 REQUIRE(!
value.empty());
87 REQUIRE(!
value.text().empty());
90 return sym.type_get() == get_token_type(
type);
93 TEST_CASE(
"NMODL Lexer returning valid token types",
"[Lexer]") {
94 SECTION(
"Some keywords") {
100 SECTION(
"NMODL language keywords and constructs") {
111 SECTION(
"Different number types") {
122 SECTION(
"Name/Strings types") {
127 SECTION(
"Logical operator types") {
137 SECTION(
"Brace types") {
Represent token returned by scanner.
Represents a double variable.
Represents an integer variable.
Represents a prime variable (for ODE)
Class that binds all pieces together for parsing nmodl file.
Represent Lexer/Scanner class for NMODL language parsing.
virtual NmodlParser::symbol_type next_token()
Function for lexer to scan token (replacement for yylex())
void symbol_type(const std::string &name, T &value)
parser::CParser::token Token
encapsulates code generation backend implementations
parser::NmodlParser::symbol_type SymbolType
TokenType token_type(const std::string &name)
Return token type for given token name.
parser::NmodlParser::token_type TokenType
TEST_CASE("NMODL Lexer returning valid token types", "[Lexer]")
bool check_token_type(const std::string &name, TokenType type)
retrieve token type from lexer and check if it's of given type
nmodl::parser::UnitDriver driver