xref: /Universal-ctags/optlib/yacc.ctags (revision fece18c50a4aeef1bee0cb4f17bf9cdc38519b5d)
1#
2# yacc.ctags --- multitable regex parser for yacc/bison input
3#
4# Copyright (c) 2001-2002, Nick Hibma <n_hibma@van-laarhoven.org>
5# Copyright (c) 2021, Red Hat, Inc.
6# Copyright (c) 2021, Masatake YAMATO
7#
8# Author: Masatake YAMATO <yamato@redhat.com>
9#
10# This program is free software; you can redistribute it and/or
11# modify it under the terms of the GNU General Public License
12# as published by the Free Software Foundation; either version 2
13# of the License, or (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23# USA.
24#
25# The original version of this parser is written in C (+ regex patterns).
26#
27# References:
28#
29# - https://www.gnu.org/software/bison/manual/html_node/Grammar-File.html
30#
31
32--langdef=YACC
33--map-YACC=+.y
34
35#
36# Kind definitions
37#
38
39--kinddef-YACC=t,token,tokens
40--kinddef-YACC=l,label,labels
41
42#
43#
44#
45--_prelude-YACC={{
46    /token-type false def
47    /type-dict 57 dict def
48}}
49
50#
51# Tables declaration
52#
53
54--_tabledef-YACC=toplevel
55--_tabledef-YACC=comment
56--_tabledef-YACC=cPrologue
57--_tabledef-YACC=grammar
58--_tabledef-YACC=cEpilogue
59--_tabledef-YACC=token
60--_tabledef-YACC=cUnion
61--_tabledef-YACC=cString
62--_tabledef-YACC=iString
63--_tabledef-YACC=rule
64--_tabledef-YACC=cActionCommon
65--_tabledef-YACC=cAction
66--_tabledef-YACC=type
67--_tabledef-YACC=cCharlit
68
69#
70# Tables definitions
71#
72--_mtable-regex-YACC=comment/[^*]+//
73--_mtable-regex-YACC=comment/\*\///{tleave}
74--_mtable-regex-YACC=comment/.//
75
76--_mtable-regex-YACC=cPrologue/[^%]+//
77--_mtable-regex-YACC=cPrologue/%\}//{tleave}{_guest=,,0start}
78--_mtable-regex-YACC=cPrologue/.//
79
80--_mtable-regex-YACC=cActionCommon/[^"\/\{\}]+//
81--_mtable-regex-YACC=cActionCommon/"//{tenter=cString}
82--_mtable-regex-YACC=cActionCommon/'//{tenter=cCharlit}
83--_mtable-regex-YACC=cActionCommon/\/\*//{tenter=comment}
84--_mtable-regex-YACC=cActionCommon/\{//{tenter=cAction}
85
86--_mtable-extend-YACC=cAction+cActionCommon
87--_mtable-regex-YACC=cAction/\}//{tleave}
88
89--_mtable-regex-YACC=rule/[^\{;]+//
90--_mtable-regex-YACC=rule/\{//{tenter=cAction}
91--_mtable-regex-YACC=rule/;//{tleave}
92--_mtable-regex-YACC=rule/.//
93
94--_mtable-regex-YACC=grammar/%%//{tjump=cEpilogue}{_guest=C,0end,}
95--_mtable-regex-YACC=grammar/([a-zA-Z_.][-a-zA-Z_.0-9]+)[ \t\n]*:[ \t\n]*/\1/l/{tenter=rule}{{
96    type-dict \1 known {
97        type-dict \1 get . exch typeref:
98    } if
99}}
100--_mtable-regex-YACC=grammar/.//
101
102--_mtable-regex-YACC=cEpilogue/.+//{_guest=,,0end}
103
104--_mtable-regex-YACC=cString/[\\"]+//
105--_mtable-regex-YACC=cString/\\.//
106--_mtable-regex-YACC=cString/"//{tleave}
107
108--_mtable-regex-YACC=cCharlit/[^\\]'//{tleave}
109--_mtable-regex-YACC=cCharlit/\\.'//{tleave}
110--_mtable-regex-YACC=cCharlit/'//{tleave}
111--_mtable-regex-YACC=cCharlit/.//
112
113--_mtable-regex-YACC=iString/"//{tenter=cString}
114--_mtable-regex-YACC=iString/\)//{tleave}
115--_mtable-regex-YACC=iString/.//
116
117#
118# %token TAG? ( ID NUMBER? STRING? )+ ( TAG ( ID NUMBER? STRING? )+ )*
119# TODO: %left  TAG? ( ID NUMBER?)+ ( TAG ( ID NUMBER? )+ )*
120#       The directives %precedence, %right and %nonassoc behave like
121#       %left.
122#
123--_mtable-regex-YACC=token/N?_[ \t]*\(//{tenter=iString}
124--_mtable-regex-YACC=token/([_a-zA-Z][_a-zA-Z0-9]*)[ \t\n]*/\1/t/{{
125    token-type false ne {
126        . token-type typeref:
127    } if
128}}
129# TODO condense multiple whitespaces in type name
130--_mtable-regex-YACC=token/<[ \t]*([_a-zA-Z][_a-zA-Z0-9 *]*)[ \t]*>[ \t\n]*//{{
131    /token-type \1 def
132}}
133--_mtable-regex-YACC=token/"//{tenter=cString}
134--_mtable-regex-YACC=token/'//{tenter=cCharlit}
135--_mtable-regex-YACC=token/-?[ \t\n]*(0x)?[0-9]+[ \t\n]*//
136--_mtable-regex-YACC=token/%//{tleave}{_advanceTo=0start}{{
137    /token-type false def
138}}
139--_mtable-regex-YACC=token/.|\n//
140
141--_mtable-extend-YACC=cUnion+cActionCommon
142--_mtable-regex-YACC=cUnion/\}//{tleave}{_guest=,,0end}{tleave}
143
144#
145# %type  TAG? ( ID | CHAR | STRING )+ ( TAG ( ID | CHAR | STRING )+ )*
146# %nterm TAG? ID+ ( TAG ID+ )*
147#
148--_mtable-regex-YACC=type/N?_[ \t]*\(//{tenter=iString}
149--_mtable-regex-YACC=type/([_a-zA-Z][_a-zA-Z0-9]*)[ \t\n]*//{{
150    token-type false ne {
151        type-dict \1 token-type put
152    } if
153}}
154--_mtable-regex-YACC=type/<[ \t]*([_a-zA-Z][_a-zA-Z0-9 *]*)[ \t]*>[ \t\n]*//{{
155    /token-type \1 def
156}}
157--_mtable-regex-YACC=type/"//{tenter=cString}
158--_mtable-regex-YACC=type/'//{tenter=cCharlit}
159--_mtable-regex-YACC=type/%//{tleave}{_advanceTo=0start}{{
160    /token-type false def
161}}
162--_mtable-regex-YACC=type/.|\n//
163
164--_mtable-regex-YACC=toplevel/\/\*//{tenter=comment}
165--_mtable-regex-YACC=toplevel/%token[ \t\n]+//{tenter=token}{{
166    /token-type false def
167}}
168--_mtable-regex-YACC=toplevel/%(union)[^\{]*\{//{tenter=cUnion}{_guest=C,1start,}
169--_mtable-regex-YACC=toplevel/%(code[^\{]*)?\{//{tenter=cPrologue}{_guest=C,0end,}
170--_mtable-regex-YACC=toplevel/%(type|nterm)[ \n\t]*//{tenter=type}{{
171    /token-type false def
172}}
173
174--_mtable-regex-YACC=toplevel/%%//{tjump=grammar}
175--_mtable-regex-YACC=toplevel/[^\n]*\n//
176
177# TODO: %initial-action skip?
178#
179# -- Directive: %defines DEFINES-FILE
180#     Same as above, but save in the file DEFINES-FILE.
181#  -- Directive: %language "LANGUAGE"
182#  -- Directive: %output "FILE"
183#     Generate the parser implementation in FILE.
184