1 |
/* |
/* |
2 |
* Copyright (c) 2015-2016 Christian Schoenebeck |
* Copyright (c) 2015-2020 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
42 |
return n; |
return n; |
43 |
} |
} |
44 |
|
|
45 |
|
// shut up warning that 'register' keyword is deprecated as of C++11 |
46 |
|
#if defined(__cplusplus) && __cplusplus >= 201103L |
47 |
|
# define register |
48 |
|
#endif |
49 |
|
|
50 |
|
// Since this parser is solely used by script code editors, thus not used in a |
51 |
|
// real-time context, always throw an exception instead of exiting on fatal |
52 |
|
// lexer errors (so the debugger may pause with the appropriate back trace) |
53 |
|
#include <stdexcept> |
54 |
|
#define YY_FATAL_ERROR(msg) throw std::runtime_error(msg) |
55 |
|
|
56 |
%} |
%} |
57 |
|
|
58 |
/* generate a reentrant safe scanner */ |
/* generate a reentrant safe scanner */ |
67 |
/* inclusive scanner conditions */ |
/* inclusive scanner conditions */ |
68 |
%s PREPROC_BODY_USE |
%s PREPROC_BODY_USE |
69 |
/* exclusive scanner conditions */ |
/* exclusive scanner conditions */ |
70 |
%x PREPROC_SET_COND PREPROC_RESET_COND PREPROC_IF PREPROC_IF_NOT PREPROC_BODY_EAT PREPROC_PRE_BODY_USE PREPROC_PRE_BODY_EAT PREPROC_EVENT_NAME PREPROC_END_NAME |
%x PREPROC_SET_COND PREPROC_RESET_COND PREPROC_IF PREPROC_IF_NOT PREPROC_BODY_EAT PREPROC_PRE_BODY_USE PREPROC_PRE_BODY_EAT PREPROC_EVENT_NAME PREPROC_END_NAME METRIC UNIT |
71 |
|
|
72 |
DIGIT [0-9] |
DIGIT [0-9] |
73 |
ID [a-zA-Z0-9_]+ |
ID [a-zA-Z][a-zA-Z0-9_]* |
74 |
|
METRIC (k|h|(da)|d|c|m|u) |
75 |
|
UNIT (s|(Hz)|B) |
76 |
|
END_ID on|while|if|select|function|synchronized |
77 |
|
|
78 |
%% |
%% |
79 |
|
|
82 |
return yyextra->token.baseType; |
return yyextra->token.baseType; |
83 |
} |
} |
84 |
|
|
85 |
{DIGIT}+ { |
{DIGIT}+("."{DIGIT}+)? { |
86 |
|
yyextra->token = NumberLiteralToken(yytext); |
87 |
|
return yyextra->token.baseType; |
88 |
|
} |
89 |
|
|
90 |
|
{DIGIT}+("."{DIGIT}+)?/{METRIC}{1,2} { |
91 |
|
yy_push_state(METRIC, yyscanner); |
92 |
yyextra->token = NumberLiteralToken(yytext); |
yyextra->token = NumberLiteralToken(yytext); |
93 |
return yyextra->token.baseType; |
return yyextra->token.baseType; |
94 |
} |
} |
95 |
|
|
96 |
/* there is currently no support for floating point numbers in NKSP yet */ |
{DIGIT}+("."{DIGIT}+)?/{UNIT} { |
97 |
/*{DIGIT}+"."{DIGIT}* { |
yy_push_state(UNIT, yyscanner); |
98 |
yyextra->token = NumberLiteralToken(yytext); |
yyextra->token = NumberLiteralToken(yytext); |
99 |
return yyextra->token.baseType; |
return yyextra->token.baseType; |
100 |
}*/ |
} |
101 |
|
|
102 |
|
<METRIC>{METRIC}{1,2} { |
103 |
|
yyextra->token = MetricPrefixToken(yytext); |
104 |
|
yy_pop_state(yyscanner); |
105 |
|
return yyextra->token.baseType; |
106 |
|
} |
107 |
|
|
108 |
|
<METRIC>{METRIC}{1,2}/{UNIT} { |
109 |
|
yyextra->token = MetricPrefixToken(yytext); |
110 |
|
yy_pop_state(yyscanner); |
111 |
|
yy_push_state(UNIT, yyscanner); |
112 |
|
return yyextra->token.baseType; |
113 |
|
} |
114 |
|
|
115 |
|
<UNIT>{UNIT} { |
116 |
|
yyextra->token = StdUnitToken(yytext); |
117 |
|
yy_pop_state(yyscanner); |
118 |
|
return yyextra->token.baseType; |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
/* Preprocessor statement: SET_CONDITION(name) */ |
/* Preprocessor statement: SET_CONDITION(name) */ |
227 |
|
|
228 |
/* Event Handler Names (only if they occur alone in a document!) */ |
/* Event Handler Names (only if they occur alone in a document!) */ |
229 |
|
|
230 |
^\s*(init|note|release|controller) { |
^\s*(init|note|release|controller|rpn|nrpn) { |
231 |
yyextra->token = EventHandlerNameToken(yytext); |
yyextra->token = EventHandlerNameToken(yytext); |
232 |
return yyextra->token.baseType; |
return yyextra->token.baseType; |
233 |
} |
} |
253 |
return yyextra->token.baseType; |
return yyextra->token.baseType; |
254 |
} |
} |
255 |
|
|
256 |
<PREPROC_END_NAME>[ \t]*{ID} { |
<PREPROC_END_NAME>[ \t]*{END_ID}? { |
257 |
yy_pop_state(yyscanner); |
yy_pop_state(yyscanner); |
258 |
yyextra->token = KeywordToken(yytext); |
yyextra->token = KeywordToken(yytext); |
259 |
return yyextra->token.baseType; |
return yyextra->token.baseType; |
264 |
return yyextra->token.baseType; |
return yyextra->token.baseType; |
265 |
} |
} |
266 |
|
|
267 |
declare|while|if|or|and|not|else|case|select|to|mod|const|polyphonic { |
declare|while|if|or|and|not|else|case|select|to|mod|const|polyphonic|function|call|synchronized { |
268 |
yyextra->token = KeywordToken(yytext); |
yyextra->token = KeywordToken(yytext); |
269 |
return yyextra->token.baseType; |
return yyextra->token.baseType; |
270 |
} |
} |
277 |
return yyextra->token.baseType; |
return yyextra->token.baseType; |
278 |
} |
} |
279 |
|
|
280 |
|
"~"{ID} { |
281 |
|
yyextra->token = RealVariableToken(yytext); |
282 |
|
return yyextra->token.baseType; |
283 |
|
} |
284 |
|
|
285 |
"@"{ID} { |
"@"{ID} { |
286 |
yyextra->token = StringVariableToken(yytext); |
yyextra->token = StringVariableToken(yytext); |
287 |
return yyextra->token.baseType; |
return yyextra->token.baseType; |
288 |
} |
} |
289 |
|
|
290 |
"%"{ID} { |
"%"{ID} { |
291 |
yyextra->token = ArrayVariableToken(yytext); |
yyextra->token = IntegerArrayVariableToken(yytext); |
292 |
|
return yyextra->token.baseType; |
293 |
|
} |
294 |
|
|
295 |
|
"?"{ID} { |
296 |
|
yyextra->token = RealArrayVariableToken(yytext); |
297 |
return yyextra->token.baseType; |
return yyextra->token.baseType; |
298 |
} |
} |
299 |
|
|