Update suitable examples and tests to use blank mode
[shapes.git] / source / namespaceyylex.ll
blobde5939f822d05a2017f42516cd64836c872a9f59
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 2015 Henrik Tidefelt
17  */
21 #include "namespacescanner.h"
22 #include "strrefdup.h"
23 #include "exitcodes.h"
24 #include "globals.h"
25 #include "shapesexceptions.h"
27 using namespace Shapes;
28 #include "yyltype.h"
30 #include <string.h>
31 #include <iostream>
32 #include <cstdio> // This is a workaround for a bug in Flex.
34 #define YY_USER_ACTION doBeforeEachAction( );
35 #define YY_EXIT_FAILURE Shapes::Interaction::EXIT_INTERNAL_ERROR
37 YYLTYPE namespacelloc;
41 DirPrefix ^[ \t]*
42 UnquotedArg [^ \t\n<>]+
43 QuotedArg ["]([^"]|([\\][\\"]))*["]
45 %option c++
46 %option noyywrap
48 %option prefix="namespace"
49 %option yyclass="NamespaceScanner"
51 %x DiscardRestOfLineAndBEGIN_INITIAL
52 %x Prelude
53 %x Ignore
54 %x Order
58 {DirPrefix}"encapsulated" {
59   declarations_->setEncapsulated();
61 {DirPrefix}"prelude:" { BEGIN( Prelude ); }
62 {DirPrefix}"ignore:" { BEGIN( Ignore ); }
63 {DirPrefix}"order:" {
64   firstSet_ = true;
65   orderSet2_.clear( );
66   BEGIN( Order );
68 {DirPrefix} {
69   Ast::theAnalysisErrorsList.push_back( new Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( "Unrecognized command." ) ) );
70   BEGIN( DiscardRestOfLineAndBEGIN_INITIAL );
73 <*>[ ]+ ;
75 <*>[\t] {
76   Ast::theAnalysisErrorsList.push_back( new Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( "Illegal use of reserved tab character." ) ) );
79 <Prelude,Ignore,Order>[\n][ ] {
80   endOfLine( );
81   ++namespacelloc.lastColumn;
83 <Prelude,Ignore>[\n] {
84   endOfLine( );
85   BEGIN( INITIAL );
88 <Prelude>{UnquotedArg} {
89   declarations_->addPrelude( yytext );
91 <Prelude>{QuotedArg} {
92   declarations_->addPrelude( rinseString( yytext ) );
94 <Prelude>. {
95   std::cerr << "yytext: \"" << yytext << "\"" << std::endl ;
96   throw Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( "Stray character among <prelude> arguments." ) );
99 <Ignore>{UnquotedArg} {
100   declarations_->addIgnore( yytext );
102 <Ignore>{QuotedArg} {
103   declarations_->addIgnore( rinseString( yytext ) );
105 <Ignore>. {
106   throw Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( "Stray character among <ignore> arguments." ) );
109 <Order>{UnquotedArg} {
110   orderSet2_.insert( orderSet2_.begin( ), yytext );
112 <Order>{QuotedArg} {
113   orderSet2_.insert( orderSet2_.begin( ), rinseString( yytext ) );
115 <Order>[<] {
116   if( orderSet2_.empty( ) ){
117     Ast::theAnalysisErrorsList.push_back( new Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( "Missing item." ) ) );
118   }else if( firstSet_ ){
119     firstSet_ = false;
120   }else{
121     declarations_->addPrecedes( orderSet1_, orderSet2_ );
122   }
123   orderSet1_ = orderSet2_;
124   orderSet2_.clear( );
126 <Order>[\n] {
127   endOfLine( );
128   if( orderSet2_.empty( ) ){
129     Ast::theAnalysisErrorsList.push_back( new Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( "Missing item." ) ) );
130   } else if( firstSet_ ){
131     Ast::theAnalysisErrorsList.push_back( new Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( "Expected '<'." ) ) );
132   }else{
133     declarations_->addPrecedes( orderSet1_, orderSet2_ );
134   }
135   BEGIN( INITIAL );
137 <Order>. {
138   throw Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( "Stray character among <order> arguments." ) );
141 <DiscardRestOfLineAndBEGIN_INITIAL>.* {
142   BEGIN( INITIAL );
144 <DiscardRestOfLineAndBEGIN_INITIAL>[\n] {
145   endOfLine( );
146   BEGIN( INITIAL );
149 <*>[\n] {
150   endOfLine( );
153 <*>#.*[\n] {
154   ++namespacelloc.lastLine;
155   namespacelloc.lastColumn = 0;
158 . {
159   Ast::theAnalysisErrorsList.push_back( new Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( ( std::string( "Unrecognized token: " ) + yytext ).c_str( ) ) ) );
160   BEGIN( DiscardRestOfLineAndBEGIN_INITIAL );
164 /* The closing %% above marks the end of the Rules section and the beginning
165  * of the User Subroutines section. All text from here to the end of the
166  * file is copied verbatim to the end of the generated lex.pdf.c file.
167  * This section is where you put definitions of helper functions.
168  */