1 /* This file is part of Shapes.
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
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.
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/>.
16 * Copyright 2008, 2010 Henrik Tidefelt
21 #include "texscanner.h"
22 #include "strrefdup.h"
23 #include "exitcodes.h"
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_]+
39 %option yyclass="TeXScanner"
44 delimStack.push_back( BRACE );
47 delimStack.push_back( BRACKET );
49 "\\begin{"{EnvironmentName}"}" {
50 delimStack.push_back( BEGIN_END );
53 if( delimStack.empty( ) )
55 std::ostringstream msg;
56 msg << "There is no opening delimiter to be matched by '" << yytext << "'." ;
57 throw strrefdup( msg );
59 if( delimStack.back( ) != BRACE )
61 std::ostringstream msg;
62 msg << "Mismatched closing delimiter '" << yytext << "' (expecting '" << closing( delimStack.back( ) ) << "')." ;
63 throw strrefdup( msg );
65 delimStack.pop_back( );
68 if( delimStack.empty( ) )
70 std::ostringstream msg;
71 msg << "There is no opening delimiter to be matched by '" << yytext << "'." ;
72 throw strrefdup( msg );
74 if( delimStack.back( ) != BRACKET )
76 std::ostringstream msg;
77 msg << "Mismatched closing delimiter '" << yytext << "' (expecting '" << closing( delimStack.back( ) ) << "')." ;
78 throw strrefdup( msg );
80 delimStack.pop_back( );
82 "\\end{"{EnvironmentName}"}" {
83 if( delimStack.empty( ) )
85 std::ostringstream msg;
86 msg << "There is no opening delimiter to be matched by '" << yytext << "'." ;
87 throw strrefdup( msg );
89 if( delimStack.back( ) != BEGIN_END )
91 std::ostringstream msg;
92 msg << "Mismatched closing delimiter '" << yytext << "' (expecting '" << closing( delimStack.back( ) ) << "')." ;
93 throw strrefdup( msg );
95 delimStack.pop_back( );
98 "\\{"|"\\}"|"\\["|"\\]"|.|\n {