summaryrefslogtreecommitdiff
path: root/Build/source/texk/gregorio/gregorio-4.0.0-beta2/src/vowel/vowel-rules.y
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/gregorio/gregorio-4.0.0-beta2/src/vowel/vowel-rules.y')
-rw-r--r--Build/source/texk/gregorio/gregorio-4.0.0-beta2/src/vowel/vowel-rules.y150
1 files changed, 150 insertions, 0 deletions
diff --git a/Build/source/texk/gregorio/gregorio-4.0.0-beta2/src/vowel/vowel-rules.y b/Build/source/texk/gregorio/gregorio-4.0.0-beta2/src/vowel/vowel-rules.y
new file mode 100644
index 00000000000..3c5bc82ee24
--- /dev/null
+++ b/Build/source/texk/gregorio/gregorio-4.0.0-beta2/src/vowel/vowel-rules.y
@@ -0,0 +1,150 @@
+%{
+/*
+ * Copyright (C) 2015 The Gregorio Project (see CONTRIBUTORS.md)
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "bool.h"
+#include "struct.h"
+#include "unicode.h"
+#include "messages.h"
+
+#include "vowel.h"
+
+#include "vowel-rules.h"
+#include "vowel-rules-l.h"
+
+#if ! defined lint || defined __GNUC__
+# define IGNORE(e) ((void) (e))
+#else
+# define IGNORE(e) /* empty */
+#endif
+
+/* NOTE: This parser might allocate a new value for language; this value MUST
+ * BE FREED after the parser returns (if the value of the language pointer
+ * changes, then free the pointer). This parser DOES free the language
+ * pointer before changing it, if status points to RFPS_ALIASED. */
+
+/* uncomment it if you want to have an interactive shell to understand the
+ * details on how bison works for a certain input */
+/*int gregorio_vowel_rulefile_debug=1;*/
+
+static void gregorio_vowel_rulefile_error(const char *const filename,
+ char **const language, rulefile_parse_status *const status,
+ const char *const error_str)
+{
+ IGNORE(language);
+ IGNORE(status);
+ gregorio_messagef("gregorio_vowel_rulefile_parse", VERBOSITY_ERROR, 0,
+ _("%s: %s"), filename, error_str);
+}
+
+/* this returns false until the language *after* the desired language */
+static __inline bool match_language(char **language,
+ rulefile_parse_status *status, char *const name)
+{
+ if (*status == RFPS_FOUND) {
+ free(name);
+ return true;
+ }
+
+ if (strcmp(*language, name) == 0) {
+ *status = RFPS_FOUND;
+ }
+
+ free(name);
+ return false;
+}
+
+static __inline void alias(char **const language,
+ rulefile_parse_status *const status, char *const name,
+ char *const target)
+{
+ if (strcmp(*language, name) == 0) {
+ gregorio_messagef("alias", VERBOSITY_INFO, 0, _("Aliasing %s to %s"),
+ name, target);
+ if (*status == RFPS_ALIASED) {
+ free(*language);
+ }
+ *language = target;
+ *status = RFPS_ALIASED;
+ } else {
+ free(target);
+ }
+ free(name);
+}
+
+static __inline void add(const rulefile_parse_status *const status,
+ void (*const fn)(const char *), char *const value)
+{
+ if (*status == RFPS_FOUND) {
+ fn(value);
+ }
+ free(value);
+}
+
+#define _MATCH(NAME) if (match_language(language, status, NAME)) YYACCEPT
+#define _ALIAS(NAME, TARGET) alias(language, status, NAME, TARGET)
+#define _ADD(TABLE, CHARS) add(status, gregorio_##TABLE##_table_add, CHARS)
+
+%}
+
+%name-prefix "gregorio_vowel_rulefile_"
+%parse-param { const char *const filename }
+%parse-param { char **language }
+%parse-param { rulefile_parse_status *const status }
+
+%token LANGUAGE VOWEL PREFIX SUFFIX SECONDARY ALIAS SEMICOLON TO
+%token NAME CHARACTERS INVALID
+
+%%
+
+rules
+ :
+ | rules rule
+ ;
+
+rule
+ : LANGUAGE NAME SEMICOLON { _MATCH($2); }
+ | ALIAS NAME TO NAME SEMICOLON { _ALIAS($2, $4); }
+ | VOWEL vowels SEMICOLON
+ | PREFIX prefixes SEMICOLON
+ | SUFFIX suffixes SEMICOLON
+ | SECONDARY secondaries SEMICOLON
+ ;
+
+vowels
+ :
+ | vowels CHARACTERS { _ADD(vowel, $2); }
+ ;
+
+prefixes
+ :
+ | prefixes CHARACTERS { _ADD(prefix, $2); }
+ ;
+
+suffixes
+ :
+ | suffixes CHARACTERS { _ADD(suffix, $2); }
+ ;
+
+secondaries
+ :
+ | secondaries CHARACTERS { _ADD(secondary, $2); }
+ ;