NEURON
modtoken.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 "lexer/modtoken.hpp"
9 
10 namespace nmodl {
11 
13 
14 std::string ModToken::position() const {
15  std::stringstream ss;
16  if (external) {
17  ss << "EXTERNAL";
18  } else if (start_line() == 0) {
19  ss << "UNKNOWN";
20  } else {
21  ss << pos;
22  }
23  return ss.str();
24 }
25 
26 std::ostream& operator<<(std::ostream& stream, const ModToken& mt) {
27  // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
28  stream << std::setw(15) << mt.name << " at [" << mt.position() << "]";
29  return stream << " type " << mt.token;
30 }
31 
32 ModToken operator+(ModToken const& adder1, ModToken const& adder2) {
33  LocationType sum_pos = adder1.pos + adder2.pos;
34  ModToken sum(adder1.name, adder1.token, sum_pos);
35 
36  return sum;
37 }
38 
39 } // namespace nmodl
Represent token returned by scanner.
Definition: modtoken.hpp:50
int token
token value returned by lexer
Definition: modtoken.hpp:58
std::string position() const
Return position of the token as string.
Definition: modtoken.cpp:14
bool external
true if token is externally defined variable (e.g. t, dt in NEURON)
Definition: modtoken.hpp:64
nmodl::parser::location LocationType
Definition: modtoken.hpp:51
int start_line() const
Return line number where token started in the mod file.
Definition: modtoken.hpp:100
std::string name
name of the token
Definition: modtoken.hpp:55
LocationType pos
position of token in the mod file
Definition: modtoken.hpp:61
static double location(void *v)
Definition: impedanc.cpp:79
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::parser::location LocationType
Definition: modtoken.cpp:12
std::ostream & operator<<(std::ostream &stream, const ModToken &mt)
Definition: modtoken.cpp:26
ModToken operator+(ModToken const &adder1, ModToken const &adder2)
Definition: modtoken.cpp:32