User Guide
nmodl_utils.hpp
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 #pragma once
9 
10 /**
11  * \file nmodl_utils.hpp
12  * \brief Utility functions for NMODL lexer
13  *
14  * From nmodl lexer we return different symbols to parser. Instead of writing
15  * those functions in the flex implementation file, those commonly used routines
16  * are defined here. Some of these tasks were implemented in list.c file in the
17  * original mod2c implementation.
18  */
19 
20 #include "parser/nmodl/location.hh"
21 #include "parser/nmodl/nmodl_parser.hpp"
22 
23 namespace nmodl {
24 
25 using PositionType = parser::location;
27 using Token = parser::NmodlParser::token;
29 
30 SymbolType double_symbol(const std::string& value, PositionType& pos);
31 SymbolType integer_symbol(int value, PositionType& pos, const char* text = nullptr);
32 SymbolType name_symbol(const std::string& text, PositionType& pos, TokenType type = Token::NAME);
33 SymbolType prime_symbol(std::string text, PositionType& pos);
34 SymbolType string_symbol(const std::string& text, PositionType& pos);
35 SymbolType token_symbol(const std::string& key, PositionType& pos, TokenType type = Token::UNKNOWN);
36 
37 } // namespace nmodl
nmodl::TokenType
parser::NmodlParser::token_type TokenType
Definition: nmodl_utils.hpp:28
nmodl::string_symbol
SymbolType string_symbol(const std::string &text, PositionType &pos)
Create symbol for ast::String AST class.
Definition: nmodl_utils.cpp:113
nmodl::Token
parser::NmodlParser::token Token
Definition: nmodl_utils.hpp:27
nmodl::double_symbol
SymbolType double_symbol(const std::string &value, PositionType &pos)
Create a symbol for ast::Double AST class.
Definition: nmodl_utils.cpp:28
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::SymbolType
parser::NmodlParser::symbol_type SymbolType
Definition: nmodl_utils.hpp:26
nmodl::integer_symbol
SymbolType integer_symbol(int value, PositionType &pos, const char *text)
Create a symbol for ast::Integer AST.
Definition: nmodl_utils.cpp:47
nmodl::PositionType
parser::location PositionType
Definition: nmodl_utils.hpp:25
nmodl::token_symbol
SymbolType token_symbol(const std::string &key, PositionType &pos, TokenType type)
Create symbol for AST class.
Definition: nmodl_utils.cpp:135
nmodl::prime_symbol
SymbolType prime_symbol(std::string text, PositionType &pos)
Create symbol for ast::Prime AST class.
Definition: nmodl_utils.cpp:93
symbol_type
void symbol_type(const std::string &name, T &value)
Definition: modtoken.cpp:32
nmodl::name_symbol
SymbolType name_symbol(const std::string &text, PositionType &pos, TokenType type)
Create symbol for ast::Name AST class.
Definition: nmodl_utils.cpp:75
nmodl::token_type
TokenType token_type(const std::string &name)
Return token type for given token name.
Definition: token_mapping.cpp:284