1/* DO NOT EDIT. AUTOMATICALLY GENERATED FROM oct-tex-lexer.in.ll and oct-tex-symbols.in. */
2%top {
3////////////////////////////////////////////////////////////////////////
4//
5// Copyright (C) 2013-2021 The Octave Project Developers
6//
7// See the file COPYRIGHT.md in the top-level directory of this
8// distribution or <https://octave.org/copyright/>.
9//
10// This file is part of Octave.
11//
12// Octave is free software: you can redistribute it and/or modify it
13// under the terms of the GNU General Public License as published by
14// the Free Software Foundation, either version 3 of the License, or
15// (at your option) any later version.
16//
17// Octave is distributed in the hope that it will be useful, but
18// WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20// GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with Octave; see the file COPYING.  If not, see
24// <https://www.gnu.org/licenses/>.
25//
26////////////////////////////////////////////////////////////////////////
27
28#if defined (HAVE_CONFIG_H)
29#  include "config.h"
30#endif
31
32#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
33   // This one needs to be global.
34#  pragma GCC diagnostic ignored "-Wunused-function"
35
36   // Disable these warnings for code that is generated by flex, including
37   // pattern rules.  Push the current state so we can restore the warning
38   // state prior to functions we define at the bottom of the file.
39#  pragma GCC diagnostic push
40#  pragma GCC diagnostic ignored "-Wold-style-cast"
41#  pragma GCC diagnostic ignored "-Wsign-compare"
42#  pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
43#endif
44
45// Define away the deprecated register storage class specifier to avoid
46// potential warnings about it.
47#if ! defined (register)
48#  define register
49#endif
50
51}
52
53%option prefix = "octave_tex_"
54%option noyywrap
55%option reentrant
56%option bison-bridge
57
58%option noyyalloc
59%option noyyrealloc
60%option noyyfree
61
62%x NUM_MODE
63%x MAYBE_NUM_MODE
64
65%{
66
67#include "unistd-wrappers.h"
68
69#include "text-engine.h"
70
71// oct-tex-parser.h must be included after text-engine.h
72#include "oct-tex-parser.h"
73
74// FIXME: with bison 3.x, OCTAVE_TEX_STYPE appears in the generated
75// oct-parse.h file, but there is no definition for YYSTYPE, which is
76// needed by the code that is generated by flex.  I can't seem to find
77// a way to tell flex to use OCTAVE_TEX_STYPE instead of YYSTYPE in
78// the code it generates, or to tell bison to provide the definition
79// of YYSTYPE in the generated oct-parse.h file.
80
81#if defined (OCTAVE_TEX_STYPE_IS_DECLARED) && ! defined YYSTYPE
82#  define YYSTYPE OCTAVE_TEX_STYPE
83#endif
84
85#define YY_NO_UNISTD_H 1
86#define isatty octave_isatty_wrapper
87#define yyguts_t octave_tex_yyguts_t
88
89%}
90
91D   [0-9]
92NUM (({D}+\.?{D}*)|(\.{D}+))
93
94%%
95
96%{
97// Numeric values.
98%}
99
100<NUM_MODE>{NUM} {
101    int nread = sscanf (yytext, "%lf", &(yylval->num));
102
103    if (nread == 1)
104      return NUM;
105  }
106
107<NUM_MODE>[, \t]+ { }
108
109<NUM_MODE>"\n"|. {
110    yyless (0);
111    BEGIN (INITIAL);
112  }
113
114<MAYBE_NUM_MODE>"{" {
115    BEGIN (NUM_MODE);
116    return START;
117  }
118
119<MAYBE_NUM_MODE>"\n"|. {
120    yyless (0);
121    BEGIN (INITIAL);
122  }
123
124%{
125// Simple commands.
126%}
127
128"\\bf" { return BF; }
129"\\it" { return IT; }
130"\\sl" { return SL; }
131"\\rm" { return RM; }
132
133%{
134// Generic font commands.
135%}
136
137"\\fontname" { return FONTNAME; }
138
139"\\fontsize" {
140    BEGIN (MAYBE_NUM_MODE);
141    return FONTSIZE;
142  }
143
144"\\color[rgb]" {
145    BEGIN (MAYBE_NUM_MODE);
146    return COLOR_RGB;
147  }
148
149"\\color" { return COLOR; }
150
151%{
152// Special characters.
153%}
154
155"{" { return START; }
156"}" { return END; }
157"^" { return SUPER; }
158"_" { return SUB; }
159
160"\\{"  |
161"\\}"  |
162"\\^"  |
163"\\_"  |
164"\\\\" {
165    yylval->ch = yytext[1];
166    return CH;
167  }
168
169%{
170// Symbols.
171%}
172
173"\\alpha" { yylval->sym = 0; return SYM; }
174"\\beta" { yylval->sym = 1; return SYM; }
175"\\gamma" { yylval->sym = 2; return SYM; }
176"\\delta" { yylval->sym = 3; return SYM; }
177"\\epsilon" { yylval->sym = 4; return SYM; }
178"\\zeta" { yylval->sym = 5; return SYM; }
179"\\eta" { yylval->sym = 6; return SYM; }
180"\\theta" { yylval->sym = 7; return SYM; }
181"\\vartheta" { yylval->sym = 8; return SYM; }
182"\\iota" { yylval->sym = 9; return SYM; }
183"\\kappa" { yylval->sym = 10; return SYM; }
184"\\lambda" { yylval->sym = 11; return SYM; }
185"\\mu" { yylval->sym = 12; return SYM; }
186"\\nu" { yylval->sym = 13; return SYM; }
187"\\xi" { yylval->sym = 14; return SYM; }
188"\\o" { yylval->sym = 15; return SYM; }
189"\\pi" { yylval->sym = 16; return SYM; }
190"\\varpi" { yylval->sym = 17; return SYM; }
191"\\rho" { yylval->sym = 18; return SYM; }
192"\\sigma" { yylval->sym = 19; return SYM; }
193"\\varsigma" { yylval->sym = 20; return SYM; }
194"\\tau" { yylval->sym = 21; return SYM; }
195"\\upsilon" { yylval->sym = 22; return SYM; }
196"\\phi" { yylval->sym = 23; return SYM; }
197"\\chi" { yylval->sym = 24; return SYM; }
198"\\psi" { yylval->sym = 25; return SYM; }
199"\\omega" { yylval->sym = 26; return SYM; }
200"\\Gamma" { yylval->sym = 27; return SYM; }
201"\\Delta" { yylval->sym = 28; return SYM; }
202"\\Theta" { yylval->sym = 29; return SYM; }
203"\\Lambda" { yylval->sym = 30; return SYM; }
204"\\Xi" { yylval->sym = 31; return SYM; }
205"\\Pi" { yylval->sym = 32; return SYM; }
206"\\Sigma" { yylval->sym = 33; return SYM; }
207"\\Upsilon" { yylval->sym = 34; return SYM; }
208"\\Phi" { yylval->sym = 35; return SYM; }
209"\\Psi" { yylval->sym = 36; return SYM; }
210"\\Omega" { yylval->sym = 37; return SYM; }
211"\\aleph" { yylval->sym = 38; return SYM; }
212"\\wp" { yylval->sym = 39; return SYM; }
213"\\Re" { yylval->sym = 40; return SYM; }
214"\\Im" { yylval->sym = 41; return SYM; }
215"\\partial" { yylval->sym = 42; return SYM; }
216"\\infty" { yylval->sym = 43; return SYM; }
217"\\prime" { yylval->sym = 44; return SYM; }
218"\\nabla" { yylval->sym = 45; return SYM; }
219"\\surd" { yylval->sym = 46; return SYM; }
220"\\angle" { yylval->sym = 47; return SYM; }
221"\\forall" { yylval->sym = 48; return SYM; }
222"\\exists" { yylval->sym = 49; return SYM; }
223"\\neg" { yylval->sym = 50; return SYM; }
224"\\clubsuit" { yylval->sym = 51; return SYM; }
225"\\diamondsuit" { yylval->sym = 52; return SYM; }
226"\\heartsuit" { yylval->sym = 53; return SYM; }
227"\\spadesuit" { yylval->sym = 54; return SYM; }
228"\\int" { yylval->sym = 55; return SYM; }
229"\\pm" { yylval->sym = 56; return SYM; }
230"\\cdot" { yylval->sym = 57; return SYM; }
231"\\times" { yylval->sym = 58; return SYM; }
232"\\ast" { yylval->sym = 59; return SYM; }
233"\\circ" { yylval->sym = 60; return SYM; }
234"\\bullet" { yylval->sym = 61; return SYM; }
235"\\div" { yylval->sym = 62; return SYM; }
236"\\cap" { yylval->sym = 63; return SYM; }
237"\\cup" { yylval->sym = 64; return SYM; }
238"\\vee" { yylval->sym = 65; return SYM; }
239"\\wedge" { yylval->sym = 66; return SYM; }
240"\\oplus" { yylval->sym = 67; return SYM; }
241"\\otimes" { yylval->sym = 68; return SYM; }
242"\\oslash" { yylval->sym = 69; return SYM; }
243"\\leq" { yylval->sym = 70; return SYM; }
244"\\subset" { yylval->sym = 71; return SYM; }
245"\\subseteq" { yylval->sym = 72; return SYM; }
246"\\in" { yylval->sym = 73; return SYM; }
247"\\geq" { yylval->sym = 74; return SYM; }
248"\\supset" { yylval->sym = 75; return SYM; }
249"\\supseteq" { yylval->sym = 76; return SYM; }
250"\\ni" { yylval->sym = 77; return SYM; }
251"\\mid" { yylval->sym = 78; return SYM; }
252"\\equiv" { yylval->sym = 79; return SYM; }
253"\\sim" { yylval->sym = 80; return SYM; }
254"\\approx" { yylval->sym = 81; return SYM; }
255"\\cong" { yylval->sym = 82; return SYM; }
256"\\propto" { yylval->sym = 83; return SYM; }
257"\\perp" { yylval->sym = 84; return SYM; }
258"\\leftarrow" { yylval->sym = 85; return SYM; }
259"\\Leftarrow" { yylval->sym = 86; return SYM; }
260"\\rightarrow" { yylval->sym = 87; return SYM; }
261"\\Rightarrow" { yylval->sym = 88; return SYM; }
262"\\leftrightarrow" { yylval->sym = 89; return SYM; }
263"\\uparrow" { yylval->sym = 90; return SYM; }
264"\\downarrow" { yylval->sym = 91; return SYM; }
265"\\lfloor" { yylval->sym = 92; return SYM; }
266"\\langle" { yylval->sym = 93; return SYM; }
267"\\lceil" { yylval->sym = 94; return SYM; }
268"\\rfloor" { yylval->sym = 95; return SYM; }
269"\\rangle" { yylval->sym = 96; return SYM; }
270"\\rceil" { yylval->sym = 97; return SYM; }
271"\\neq" { yylval->sym = 98; return SYM; }
272"\\ldots" { yylval->sym = 99; return SYM; }
273"\\0" { yylval->sym = 100; return SYM; }
274"\\copyright" { yylval->sym = 101; return SYM; }
275"\\deg" { yylval->sym = 102; return SYM; }
276
277%{
278// Generic character.
279%}
280
281"\n" |
282.    {
283    yylval->ch = yytext[0];
284    return CH;
285  }
286
287%{
288#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
289   // Also disable this warning for functions that are generated by flex
290   // after the pattern rules.
291#  pragma GCC diagnostic ignored "-Wunused-parameter"
292#endif
293%}
294
295%%
296
297#if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
298   // Restore prevailing warning state for remainder of the file.
299#  pragma GCC diagnostic pop
300#endif
301
302void *
303octave_tex_alloc (yy_size_t size, yyscan_t)
304{
305  return malloc (size);
306}
307
308void *
309octave_tex_realloc (void *ptr, yy_size_t size, yyscan_t)
310{
311return realloc (ptr, size);
312}
313
314void
315octave_tex_free (void *ptr, yyscan_t)
316{
317  free (ptr);
318}
319
320namespace octave
321{
322  bool text_parser_tex::init_lexer (const std::string& s)
323  {
324    if (! scanner)
325      octave_tex_lex_init (&scanner);
326
327    if (scanner)
328      {
329        if (buffer_state)
330          {
331            octave_tex__delete_buffer (reinterpret_cast<YY_BUFFER_STATE> (buffer_state),
332                                       scanner);
333            buffer_state = nullptr;
334          }
335
336        buffer_state = octave_tex__scan_bytes (s.data (), s.length (), scanner);
337      }
338
339    return (scanner && buffer_state);
340  }
341
342  void text_parser_tex::destroy_lexer (void)
343  {
344    if (buffer_state)
345      {
346        octave_tex__delete_buffer (reinterpret_cast<YY_BUFFER_STATE> (buffer_state),
347                                   scanner);
348        buffer_state = nullptr;
349      }
350
351    if (scanner)
352      {
353        octave_tex_lex_destroy (scanner);
354        scanner = nullptr;
355      }
356  }
357}
358