Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / texyylex.ll
blob8ff7ab4904731d8244e759f5fa8f0c1dec9374a4
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 Henrik Tidefelt
17  */
21 #include "texscanner.h"
22 #include "strrefdup.h"
23 #include "exitcodes.h"
25 #include <string.h>
26 #include <iostream>
28 #define YY_EXIT_FAILURE Shapes::Interaction::EXIT_INTERNAL_ERROR
32 EnvironmentName [a-zA-Z0-9_]+
34 %option c++
35 %option noyywrap
37 %option prefix="tex"
38 %option yyclass="TeXScanner"
42 "{" {
43         delimStack.push_back( BRACE );
45 "[" {
46         delimStack.push_back( BRACKET );
48 "\\begin{"{EnvironmentName}"}" {
49         delimStack.push_back( BEGIN_END );
51 "}" {
52         if( delimStack.empty( ) )
53                 {
54                         std::ostringstream msg;
55                         msg << "There is no opening delimiter to be matched by '" << yytext << "'." ;
56                         throw strrefdup( msg );
57                 }
58         if( delimStack.back( ) != BRACE )
59                 {
60                         std::ostringstream msg;
61                         msg << "Mismatched closing delimiter '" << yytext << "' (expecting '" << closing( delimStack.back( ) ) << "')." ;
62                         throw strrefdup( msg );
63                 }
64         delimStack.pop_back( );
66 "]" {
67         if( delimStack.empty( ) )
68                 {
69                         std::ostringstream msg;
70                         msg << "There is no opening delimiter to be matched by '" << yytext << "'." ;
71                         throw strrefdup( msg );
72                 }
73         if( delimStack.back( ) != BRACKET )
74                 {
75                         std::ostringstream msg;
76                         msg << "Mismatched closing delimiter '" << yytext << "' (expecting '" << closing( delimStack.back( ) ) << "')." ;
77                         throw strrefdup( msg );
78                 }
79         delimStack.pop_back( );
81 "\\end{"{EnvironmentName}"}" {
82         if( delimStack.empty( ) )
83                 {
84                         std::ostringstream msg;
85                         msg << "There is no opening delimiter to be matched by '" << yytext << "'." ;
86                         throw strrefdup( msg );
87                 }
88         if( delimStack.back( ) != BEGIN_END )
89                 {
90                         std::ostringstream msg;
91                         msg << "Mismatched closing delimiter '" << yytext << "' (expecting '" << closing( delimStack.back( ) ) << "')." ;
92                         throw strrefdup( msg );
93                 }
94         delimStack.pop_back( );
97 "\\{"|"\\}"|"\\["|"\\]"|.|\n {
98   // Do nothing
101 <<EOF>> {
102   return 0;