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 2015 Henrik Tidefelt
21 #include "namespacescanner.h"
22 #include "strrefdup.h"
23 #include "exitcodes.h"
25 #include "shapesexceptions.h"
27 using namespace Shapes;
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;
42 UnquotedArg [^ \t\n<>]+
43 QuotedArg ["]([^"]|([\\][\\"]))*["]
48 %option prefix="namespace"
49 %option yyclass="NamespaceScanner"
51 %x DiscardRestOfLineAndBEGIN_INITIAL
58 {DirPrefix}"encapsulated" {
59 declarations_->setEncapsulated();
61 {DirPrefix}"prelude:" { BEGIN( Prelude ); }
62 {DirPrefix}"ignore:" { BEGIN( Ignore ); }
69 Ast::theAnalysisErrorsList.push_back( new Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( "Unrecognized command." ) ) );
70 BEGIN( DiscardRestOfLineAndBEGIN_INITIAL );
76 Ast::theAnalysisErrorsList.push_back( new Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( "Illegal use of reserved tab character." ) ) );
79 <Prelude,Ignore,Order>[\n][ ] {
81 ++namespacelloc.lastColumn;
83 <Prelude,Ignore>[\n] {
88 <Prelude>{UnquotedArg} {
89 declarations_->addPrelude( yytext );
91 <Prelude>{QuotedArg} {
92 declarations_->addPrelude( rinseString( yytext ) );
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 ) );
106 throw Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( "Stray character among <ignore> arguments." ) );
109 <Order>{UnquotedArg} {
110 orderSet2_.insert( orderSet2_.begin( ), yytext );
113 orderSet2_.insert( orderSet2_.begin( ), rinseString( yytext ) );
116 if( orderSet2_.empty( ) ){
117 Ast::theAnalysisErrorsList.push_back( new Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( "Missing item." ) ) );
118 }else if( firstSet_ ){
121 declarations_->addPrecedes( orderSet1_, orderSet2_ );
123 orderSet1_ = orderSet2_;
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 '<'." ) ) );
133 declarations_->addPrecedes( orderSet1_, orderSet2_ );
138 throw Exceptions::NamespaceDirectoryError( namespacelloc, strrefdup( "Stray character among <order> arguments." ) );
141 <DiscardRestOfLineAndBEGIN_INITIAL>.* {
144 <DiscardRestOfLineAndBEGIN_INITIAL>[\n] {
154 ++namespacelloc.lastLine;
155 namespacelloc.lastColumn = 0;
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.