113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
-
+
-
+
-
+
|
// identifiers.
string str;
while( m_input.good() )
{
auto c = m_input.peek();
if( !isalpha( c ) && !isdigit( c ) && c != '_' )
if( !isalpha( c ) && !isdigit( c ) && c != '_' && c != '#' )
break;
m_input.get();
str += c;
}
Term result( move( loc ), StringId( str ) );
return result;
}
// TODO this is inefficient, put that stuff into a lookup table.
// Also maybe instead of being hardcoded in the lexer it could be
// configurable, so that when a new operator is defined it can reserve
// its characters here (either as a first char only, or not)
// Currently, - @ $ # ~ and ! can only be used as the first character of an operator identifier,
// Currently, - @ $ ~ and ! can only be used as the first character of an operator identifier,
// so that they can be used as the first character of a prefix operator (we don't want to make it mandatory to insert
// a space between an infix and a prefix operator).
bool Lexer::isOpFirstChar( char c )
{
static string charTable = "+*/%&|^<>=?:.,-@$#!~";
static string charTable = "+*/%&|^<>=?:.,-@$!~";
return charTable.find_first_of( c ) != string::npos;
}
bool Lexer::isOpChar( char c )
{
static string charTable = "+*/%&|^<>=?:.,";
return charTable.find_first_of( c ) != string::npos;
|
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
-
+
|
return nullopt;
auto c = m_input.peek();
if( isdigit( c ) )
return readIntegerLiteral( move( loc ) );
if( isalpha( c ) || c == '_' )
if( isalpha( c ) || c == '_' || c == '#' )
return readAlphanumericIdentifier( move( loc ) );
switch( c )
{
case '(':
m_input.get();
return Term( move( loc ), Delimiter::OpenParen );
|