| 1 |
%{ |
| 2 |
/* |
| 3 |
* Gregorio is a program that translates gabc files to GregorioTeX |
| 4 |
* This file implements the score lexer. |
| 5 |
* |
| 6 |
* Gregorio score determination in gabc input. |
| 7 |
* Copyright (C) 2006-2025 The Gregorio Project (see CONTRIBUTORS.md) |
| 8 |
* |
| 9 |
* This file is part of Gregorio. |
| 10 |
* |
| 11 |
* This program is free software: you can redistribute it and/or modify it |
| 12 |
* under the terms of the GNU General Public License as published by the Free |
| 13 |
* Software Foundation, either version 3 of the License, or (at your option) |
| 14 |
* any later version. |
| 15 |
* |
| 16 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 19 |
* more details. |
| 20 |
* |
| 21 |
* You should have received a copy of the GNU General Public License along with |
| 22 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "config.h" |
| 26 |
#include <stdio.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <string.h> |
| 29 |
#include "struct.h" |
| 30 |
#include "messages.h" |
| 31 |
#include "bool.h" |
| 32 |
#include "support.h" |
| 33 |
|
| 34 |
#include "gabc.h" |
| 35 |
#include "gabc-score-determination.h" |
| 36 |
#include "gabc-score-determination-y.h" |
| 37 |
|
| 38 |
static bool eof_found = false; |
| 39 |
|
| 40 |
#define START_STYLE(STYLE) return STYLE ## _BEGIN |
| 41 |
|
| 42 |
#define END_STYLE(STYLE) return STYLE ## _END |
| 43 |
|
| 44 |
#define RETURN_CHARACTERS \ |
| 45 |
gabc_score_determination_lval.text = \ |
| 46 |
gabc_unescape(gabc_score_determination_text); \ |
| 47 |
return CHARACTERS |
| 48 |
|
| 49 |
#define RETURN_SPACE \ |
| 50 |
gabc_score_determination_lval.text = gregorio_strdup(" "); \ |
| 51 |
return CHARACTERS |
| 52 |
|
| 53 |
#define YY_NO_INPUT |
| 54 |
|
| 55 |
#define YY_INPUT(buf,result,max_size) \ |
| 56 |
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) { \ |
| 57 |
int c = '*'; \ |
| 58 |
int n; \ |
| 59 |
for (n = 0; n < max_size \ |
| 60 |
&& (c = getc(gabc_score_determination_in)) != EOF \ |
| 61 |
&& c != '\n'; ++n ) { \ |
| 62 |
buf[n] = (char) c; \ |
| 63 |
} \ |
| 64 |
if (c == '\n') { \ |
| 65 |
buf[n++] = (char) c; \ |
| 66 |
} \ |
| 67 |
if (c == EOF && ferror(gabc_score_determination_in)) { \ |
| 68 |
YY_FATAL_ERROR("input in flex scanner failed"); \ |
| 69 |
} \ |
| 70 |
result = n; \ |
| 71 |
} else { \ |
| 72 |
errno=0; \ |
| 73 |
while ((result = fread(buf, 1, max_size, gabc_score_determination_in)) \ |
| 74 |
== 0 && ferror(gabc_score_determination_in)) { \ |
| 75 |
if (errno != EINTR) { \ |
| 76 |
YY_FATAL_ERROR("input in flex scanner failed"); \ |
| 77 |
break; \ |
| 78 |
} \ |
| 79 |
errno = 0; \ |
| 80 |
clearerr(gabc_score_determination_in); \ |
| 81 |
} \ |
| 82 |
} \ |
| 83 |
gabc_digest(buf, result) |
| 84 |
|
| 85 |
#define YY_USER_ACTION gabc_update_location(&gabc_score_determination_lloc, \ |
| 86 |
gabc_score_determination_text, gabc_score_determination_leng); |
| 87 |
|
| 88 |
%} |
| 89 |
|
| 90 |
%x attribute |
| 91 |
%x score |
| 92 |
%x notes |
| 93 |
%x sp |
| 94 |
%x verb |
| 95 |
%x comments |
| 96 |
%x inicomments |
| 97 |
%x alt |
| 98 |
%x protrusion_value |
| 99 |
%x protrusion_end |
| 100 |
|
| 101 |
%option stack |
| 102 |
%option pointer |
| 103 |
%option nounput |
| 104 |
%option noyy_push_state |
| 105 |
%option noyy_pop_state |
| 106 |
%option noyy_top_state |
| 107 |
%option align |
| 108 |
%option noread |
| 109 |
%option nomain |
| 110 |
%option noalways-interactive |
| 111 |
%option nonever-interactive |
| 112 |
%option prefix="gabc_score_determination_" |
| 113 |
%option noyywrap |
| 114 |
%option 8bit |
| 115 |
|
| 116 |
|
| 117 |
/* The expression for attribute below is rather messy because we allow |
| 118 |
for (a) single-line values, ending with a semicolon at end of line or a |
| 119 |
double semicolon, (b) multi-line values, which end at a double |
| 120 |
semicolon. */ |
| 121 |
|
| 122 |
%% |
| 123 |
<INITIAL>^(\xBB|\xEF|\xBF)+ { |
| 124 |
/* BOM written by a lot of windows softwares when they write UTF-8 */ |
| 125 |
} |
| 126 |
<INITIAL>^[\n\r]+ { |
| 127 |
/* ignoring empty lines */ |
| 128 |
} |
| 129 |
<INITIAL>^[\%#] { |
| 130 |
BEGIN(inicomments); |
| 131 |
} |
| 132 |
<inicomments>(\n|\r)+ { |
| 133 |
BEGIN(INITIAL); |
| 134 |
} |
| 135 |
<inicomments>[^\n\r]+ { |
| 136 |
/* ignored */ |
| 137 |
} |
| 138 |
<INITIAL>:(\ )? { |
| 139 |
BEGIN(attribute); |
| 140 |
return COLON; |
| 141 |
} |
| 142 |
<attribute>;;?[\n\r \t]*[\n\r] { |
| 143 |
BEGIN(INITIAL); |
| 144 |
return SEMICOLON; |
| 145 |
} |
| 146 |
<attribute>[^;]+ { |
| 147 |
gabc_score_determination_lval.text = |
| 148 |
gregorio_strdup(gabc_score_determination_text); |
| 149 |
return ATTRIBUTE; |
| 150 |
} |
| 151 |
<attribute>; { |
| 152 |
gabc_score_determination_lval.text = |
| 153 |
gregorio_strdup(gabc_score_determination_text); |
| 154 |
return ATTRIBUTE; |
| 155 |
} |
| 156 |
<INITIAL>def-m[0-9] { |
| 157 |
gabc_score_determination_lval.character = gabc_score_determination_text[5]; |
| 158 |
return DEF_MACRO; |
| 159 |
} |
| 160 |
<INITIAL>name { |
| 161 |
gabc_score_determination_lval.text = |
| 162 |
gregorio_strdup(gabc_score_determination_text); |
| 163 |
return NAME; |
| 164 |
} |
| 165 |
<INITIAL>score-copyright { |
| 166 |
gabc_score_determination_lval.text = |
| 167 |
gregorio_strdup(gabc_score_determination_text); |
| 168 |
return SCORE_COPYRIGHT; |
| 169 |
} |
| 170 |
<INITIAL>gabc-copyright { |
| 171 |
gabc_score_determination_lval.text = |
| 172 |
gregorio_strdup(gabc_score_determination_text); |
| 173 |
return GABC_COPYRIGHT; |
| 174 |
} |
| 175 |
<INITIAL>mode { |
| 176 |
gabc_score_determination_lval.text = |
| 177 |
gregorio_strdup(gabc_score_determination_text); |
| 178 |
return MODE; |
| 179 |
} |
| 180 |
<INITIAL>mode-modifier { |
| 181 |
gabc_score_determination_lval.text = |
| 182 |
gregorio_strdup(gabc_score_determination_text); |
| 183 |
return MODE_MODIFIER; |
| 184 |
} |
| 185 |
<INITIAL>mode-differentia { |
| 186 |
gabc_score_determination_lval.text = |
| 187 |
gregorio_strdup(gabc_score_determination_text); |
| 188 |
return MODE_DIFFERENTIA; |
| 189 |
} |
| 190 |
<INITIAL>annotation { |
| 191 |
gabc_score_determination_lval.text = |
| 192 |
gregorio_strdup(gabc_score_determination_text); |
| 193 |
return ANNOTATION; |
| 194 |
} |
| 195 |
<INITIAL>author { |
| 196 |
gabc_score_determination_lval.text = |
| 197 |
gregorio_strdup(gabc_score_determination_text); |
| 198 |
return AUTHOR; |
| 199 |
} |
| 200 |
<INITIAL>language { |
| 201 |
gabc_score_determination_lval.text = |
| 202 |
gregorio_strdup(gabc_score_determination_text); |
| 203 |
return LANGUAGE; |
| 204 |
} |
| 205 |
<INITIAL>staff-lines { |
| 206 |
gabc_score_determination_lval.text = |
| 207 |
gregorio_strdup(gabc_score_determination_text); |
| 208 |
return STAFF_LINES; |
| 209 |
} |
| 210 |
<INITIAL>nabc-lines { |
| 211 |
gabc_score_determination_lval.text = |
| 212 |
gregorio_strdup(gabc_score_determination_text); |
| 213 |
return NABC_LINES; |
| 214 |
} |
| 215 |
<INITIAL>oriscus-orientation { |
| 216 |
gabc_score_determination_lval.text = |
| 217 |
gregorio_strdup(gabc_score_determination_text); |
| 218 |
return ORISCUS_ORIENTATION; |
| 219 |
} |
| 220 |
<INITIAL>[A-Za-z0-9_]+(-[A-Za-z0-9_]+)* { |
| 221 |
gabc_score_determination_lval.text = |
| 222 |
gregorio_strdup(gabc_score_determination_text); |
| 223 |
return OTHER_HEADER; |
| 224 |
} |
| 225 |
<INITIAL>%%+(\n|\r)+ { |
| 226 |
BEGIN(score); |
| 227 |
return END_OF_DEFINITIONS; |
| 228 |
} |
| 229 |
<INITIAL>. { |
| 230 |
gregorio_messagef("det_score", VERBOSITY_ERROR, 0, |
| 231 |
_("unrecognized character: \"%c\" in definition part"), |
| 232 |
gabc_score_determination_text[0]); |
| 233 |
} |
| 234 |
<score>[\n\r][\n\r \t]* { |
| 235 |
RETURN_SPACE; |
| 236 |
} |
| 237 |
<score>(\$.|[^-,;:.\{\}\(\[\]<%\n\r])+ { |
| 238 |
RETURN_CHARACTERS; |
| 239 |
} |
| 240 |
<score>- { |
| 241 |
return HYPHEN; |
| 242 |
} |
| 243 |
<score>[,;:.] { |
| 244 |
gabc_score_determination_lval.text = |
| 245 |
gregorio_strdup(gabc_score_determination_text); |
| 246 |
return PROTRUDING_PUNCTUATION; |
| 247 |
} |
| 248 |
<score><nlba> { |
| 249 |
return NLBA_B; |
| 250 |
} |
| 251 |
<score><\/nlba> { |
| 252 |
return NLBA_E; |
| 253 |
} |
| 254 |
<score><i> { |
| 255 |
START_STYLE(I); |
| 256 |
} |
| 257 |
<score><\/i> { |
| 258 |
END_STYLE(I); |
| 259 |
} |
| 260 |
<score><tt> { |
| 261 |
START_STYLE(TT); |
| 262 |
} |
| 263 |
<score><\/tt> { |
| 264 |
END_STYLE(TT); |
| 265 |
} |
| 266 |
<score><ul> { |
| 267 |
START_STYLE(UL); |
| 268 |
} |
| 269 |
<score><\/ul> { |
| 270 |
END_STYLE(UL); |
| 271 |
} |
| 272 |
<score><c> { |
| 273 |
START_STYLE(C); |
| 274 |
} |
| 275 |
<score><\/c> { |
| 276 |
END_STYLE(C); |
| 277 |
} |
| 278 |
<score><b> { |
| 279 |
START_STYLE(B); |
| 280 |
} |
| 281 |
<score><\/b> { |
| 282 |
END_STYLE(B); |
| 283 |
} |
| 284 |
<score><sc> { |
| 285 |
START_STYLE(SC); |
| 286 |
} |
| 287 |
<score><\/sc> { |
| 288 |
END_STYLE(SC); |
| 289 |
} |
| 290 |
<score><e> { |
| 291 |
START_STYLE(ELISION); |
| 292 |
} |
| 293 |
<score><\/e> { |
| 294 |
END_STYLE(ELISION); |
| 295 |
} |
| 296 |
<score><sp> { |
| 297 |
BEGIN(sp); |
| 298 |
return SP_BEGIN; |
| 299 |
} |
| 300 |
<sp><\/sp> { |
| 301 |
BEGIN(score); |
| 302 |
return SP_END; |
| 303 |
} |
| 304 |
<sp>[\n\r][\n\r \t]* { |
| 305 |
RETURN_SPACE; |
| 306 |
} |
| 307 |
<sp>(\$.|[^<\{\}\n\r])+ { |
| 308 |
RETURN_CHARACTERS; |
| 309 |
} |
| 310 |
<score>\% { |
| 311 |
BEGIN(comments); |
| 312 |
} |
| 313 |
<comments>(\n|\r)+ { |
| 314 |
BEGIN(score); |
| 315 |
} |
| 316 |
<comments>[^\n\r]+ { |
| 317 |
/* ignored */ |
| 318 |
} |
| 319 |
<score><v> { |
| 320 |
BEGIN(verb); |
| 321 |
return VERB_BEGIN; |
| 322 |
} |
| 323 |
<verb><\/v> { |
| 324 |
BEGIN(score); |
| 325 |
return VERB_END; |
| 326 |
} |
| 327 |
<verb,alt>(\$.|[^<])+ { |
| 328 |
RETURN_CHARACTERS; |
| 329 |
} |
| 330 |
<verb,score,alt>< { |
| 331 |
RETURN_CHARACTERS; |
| 332 |
} |
| 333 |
<score>\{ { |
| 334 |
return CENTER_BEGIN; |
| 335 |
} |
| 336 |
<score>\} { |
| 337 |
return CENTER_END; |
| 338 |
} |
| 339 |
<score><alt> { |
| 340 |
BEGIN(alt); |
| 341 |
return ALT_BEGIN; |
| 342 |
} |
| 343 |
<alt><\/alt> { |
| 344 |
BEGIN(score); |
| 345 |
return ALT_END; |
| 346 |
} |
| 347 |
<score><eu> { |
| 348 |
return EUOUAE_B; |
| 349 |
} |
| 350 |
<score><\/eu> { |
| 351 |
return EUOUAE_E; |
| 352 |
} |
| 353 |
<score>\[\/] { |
| 354 |
return TRANSLATION_CENTER_END; |
| 355 |
} |
| 356 |
<score>\[ { |
| 357 |
return TRANSLATION_BEGIN; |
| 358 |
} |
| 359 |
<score>\] { |
| 360 |
return TRANSLATION_END; |
| 361 |
} |
| 362 |
<score><[\n\r \t]*clear[\n\r \t]*\/?[\n\r \t]*> { |
| 363 |
return CLEAR; |
| 364 |
} |
| 365 |
<score><[\n\r \t]*pr[\n\r \t]*\/?[\n\r \t]*> { |
| 366 |
return PROTRUSION; |
| 367 |
} |
| 368 |
<score><[\n\r \t]*pr[\n\r \t]*:[\n\r \t]* { |
| 369 |
BEGIN(protrusion_value); |
| 370 |
return PROTRUSION; |
| 371 |
} |
| 372 |
<protrusion_value>([0-9]*\.?[0-9]+|[0-9]+\.) { |
| 373 |
BEGIN(protrusion_end); |
| 374 |
gabc_score_determination_lval.text = |
| 375 |
gregorio_strdup(gabc_score_determination_text); |
| 376 |
return PROTRUSION_VALUE; |
| 377 |
} |
| 378 |
<protrusion_end>[\n\r \t]*\/?[\n\r \t]*> { |
| 379 |
BEGIN(score); |
| 380 |
return PROTRUSION_END; |
| 381 |
} |
| 382 |
<score>\( { |
| 383 |
BEGIN(notes); |
| 384 |
return OPENING_BRACKET; |
| 385 |
} |
| 386 |
<notes>(\$.|[^|\)])+ { |
| 387 |
gabc_score_determination_lval.text = |
| 388 |
gregorio_strdup(gabc_score_determination_text); |
| 389 |
return NOTES; |
| 390 |
} |
| 391 |
<notes>\| { |
| 392 |
return NABC_CUT; |
| 393 |
} |
| 394 |
<notes>\) { |
| 395 |
BEGIN(score); |
| 396 |
return CLOSING_BRACKET; |
| 397 |
} |
| 398 |
<notes>\)(\ |\t|\n|\r)+ { |
| 399 |
BEGIN(score); |
| 400 |
return CLOSING_BRACKET_WITH_SPACE; |
| 401 |
} |
| 402 |
<<EOF>> { |
| 403 |
if (!eof_found) { |
| 404 |
eof_found = true; |
| 405 |
return END_OF_FILE; |
| 406 |
} else { |
| 407 |
yyterminate(); |
| 408 |
} |
| 409 |
} |
| 410 |
.|\n { |
| 411 |
gregorio_messagef("gabc_score_determination_lex", VERBOSITY_ERROR, 0, |
| 412 |
_("unrecognized character: \"%c\""), |
| 413 |
gabc_score_determination_text[0]); |
| 414 |
} |
| 415 |
%% |
| 416 |
|