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 Henrik Tidefelt
21 #include "texscanner.h"
22 #include "strrefdup.h"
23 #include "exitcodes.h"
28 #define YY_EXIT_FAILURE Shapes::Interaction::EXIT_INTERNAL_ERROR
32 EnvironmentName [a-zA-Z0-9_]+
38 %option yyclass="TeXScanner"
43 delimStack.push_back( BRACE );
46 delimStack.push_back( BRACKET );
48 "\\begin{"{EnvironmentName}"}" {
49 delimStack.push_back( BEGIN_END );
52 if( delimStack.empty( ) )
54 std::ostringstream msg;
55 msg << "There is no opening delimiter to be matched by '" << yytext << "'." ;
56 throw strrefdup( msg );
58 if( delimStack.back( ) != BRACE )
60 std::ostringstream msg;
61 msg << "Mismatched closing delimiter '" << yytext << "' (expecting '" << closing( delimStack.back( ) ) << "')." ;
62 throw strrefdup( msg );
64 delimStack.pop_back( );
67 if( delimStack.empty( ) )
69 std::ostringstream msg;
70 msg << "There is no opening delimiter to be matched by '" << yytext << "'." ;
71 throw strrefdup( msg );
73 if( delimStack.back( ) != BRACKET )
75 std::ostringstream msg;
76 msg << "Mismatched closing delimiter '" << yytext << "' (expecting '" << closing( delimStack.back( ) ) << "')." ;
77 throw strrefdup( msg );
79 delimStack.pop_back( );
81 "\\end{"{EnvironmentName}"}" {
82 if( delimStack.empty( ) )
84 std::ostringstream msg;
85 msg << "There is no opening delimiter to be matched by '" << yytext << "'." ;
86 throw strrefdup( msg );
88 if( delimStack.back( ) != BEGIN_END )
90 std::ostringstream msg;
91 msg << "Mismatched closing delimiter '" << yytext << "' (expecting '" << closing( delimStack.back( ) ) << "')." ;
92 throw strrefdup( msg );
94 delimStack.pop_back( );
97 "\\{"|"\\}"|"\\["|"\\]"|.|\n {