From e02107e1b7edfdf23d2f27003daf78a4039068b2 Mon Sep 17 00:00:00 2001
From: "James O. D. Hunt" <jamesodhunt@gmail.com>
Date: Fri, 17 Jan 2025 14:37:46 +0000
Subject: [PATCH] magic: Add detection for yacc / bison

Recognised `yacc(1)` / `bison(1)` `*.y` grammar files.

For information on the grammar file format, see:

```sh
$ info bison grammar
```

> **Note:**
>
> If you are running on Debian, Ubuntu or a derivative,
> you may need to install the `bison(1)` documentation
> package for the above to work:
>
> ```sh
> $ sudo apt -y install bison-doc
> ```

Signed-off-by: James O. D. Hunt <jamesodhunt@gmail.com>
---
 magic/Magdir/yacc | 24 ++++++++++++++++++++++++
 magic/Makefile.am |  1 +
 2 files changed, 25 insertions(+)
 create mode 100644 magic/Magdir/yacc

diff --git a/magic/Magdir/yacc b/magic/Magdir/yacc
new file mode 100644
index 00000000..7aaac663
--- /dev/null
+++ b/magic/Magdir/yacc
@@ -0,0 +1,24 @@
+#-------------------------------------------------------------------------------
+# file(1) magic for yacc(1) / bison(1) LALR(1) parser generator source files.
+#
+# For information on the grammar file format, run the `info(1)` command as:
+#
+# ```sh
+# $ info bison grammar
+# ```
+#
+# Note:
+#
+# If you are running on Debian, Ubuntu or a derivative, you may need
+# to install the `bison(1)` documentation package for the above to work:
+#
+# ```sh
+# $ sudo apt -y install bison-doc
+# ```
+#-------------------------------------------------------------------------------
+
+0	regex		%%\n	yacc(1) or bison(1) grammar file
+!:ext	y
+>0	regex		%\\{	with C prologue
+>0	regex		%token	with token declarations
+>0	regex		%(left|right|nonassoc|precedence)	with associativity/precedence declarations
diff --git a/magic/Makefile.am b/magic/Makefile.am
index e0f90343..3895a215 100644
--- a/magic/Makefile.am
+++ b/magic/Makefile.am
@@ -348,6 +348,7 @@ $(MAGIC_FRAGMENT_DIR)/xenix \
 $(MAGIC_FRAGMENT_DIR)/xilinx \
 $(MAGIC_FRAGMENT_DIR)/xo65 \
 $(MAGIC_FRAGMENT_DIR)/xwindows \
+$(MAGIC_FRAGMENT_DIR)/yacc \
 $(MAGIC_FRAGMENT_DIR)/yara \
 $(MAGIC_FRAGMENT_DIR)/zfs \
 $(MAGIC_FRAGMENT_DIR)/zilog \
-- 
2.48.1

