Update procedures
[shapes.git] / source / texyylex.ll
blob6e850b4e37d2d345eb2fbc368ac31c0075bb4428
1 /* This file is part of Shapes.
2  *
3  * Shapes is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * any later version.
7  *
8  * Shapes is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with Shapes.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Copyright 2008, 2010 Henrik Tidefelt
17  */
21 #include "texscanner.h"
22 #include "strrefdup.h"
23 #include "exitcodes.h"
25 #include <string.h>
26 #include <iostream>
27 #include <cstdio> // This is a workaround for a bug in Flex.
29 #define YY_EXIT_FAILURE Shapes::Interaction::EXIT_INTERNAL_ERROR
33 EnvironmentName [a-zA-Z0-9_]+
35 %option c++
36 %option noyywrap
38 %option prefix="tex"
39 %option yyclass="TeXScanner"
43 "{" {
44         delimStack.push_back( BRACE );
46 "[" {
47         delimStack.push_back( BRACKET );
49 "\\begin{"{EnvironmentName}"}" {
50         delimStack.push_back( BEGIN_END );
52 "}" {
53         if( delimStack.empty( ) )
54                 {
55                         std::ostringstream msg;
56                         msg << "There is no opening delimiter to be matched by '" << yytext << "'." ;
57                         throw strrefdup( msg );
58                 }
59         if( delimStack.back( ) != BRACE )
60                 {
61                         std::ostringstream msg;
62                         msg << "Mismatched closing delimiter '" << yytext << "' (expecting '" << closing( delimStack.back( ) ) << "')." ;
63                         throw strrefdup( msg );
64                 }
65         delimStack.pop_back( );
67 "]" {
68         if( delimStack.empty( ) )
69                 {
70                         std::ostringstream msg;
71                         msg << "There is no opening delimiter to be matched by '" << yytext << "'." ;
72                         throw strrefdup( msg );
73                 }
74         if( delimStack.back( ) != BRACKET )
75                 {
76                         std::ostringstream msg;
77                         msg << "Mismatched closing delimiter '" << yytext << "' (expecting '" << closing( delimStack.back( ) ) << "')." ;
78                         throw strrefdup( msg );
79                 }
80         delimStack.pop_back( );
82 "\\end{"{EnvironmentName}"}" {
83         if( delimStack.empty( ) )
84                 {
85                         std::ostringstream msg;
86                         msg << "There is no opening delimiter to be matched by '" << yytext << "'." ;
87                         throw strrefdup( msg );
88                 }
89         if( delimStack.back( ) != BEGIN_END )
90                 {
91                         std::ostringstream msg;
92                         msg << "Mismatched closing delimiter '" << yytext << "' (expecting '" << closing( delimStack.back( ) ) << "')." ;
93                         throw strrefdup( msg );
94                 }
95         delimStack.pop_back( );
98 "\\{"|"\\}"|"\\["|"\\]"|.|\n {
99   // Do nothing
102 <<EOF>> {
103   return 0;