Adjust to new (and now docomented) naming convention for bison outputs.
[shapes.git] / source / shapesscanner.h
blob2d3fefc6f2e86905067e0896d1db2cfec774f96c
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
6 * any later version.
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
19 #pragma once
21 #include "sourcelocation.h"
22 #include "charptrless.h"
23 #include "elementarylength.h"
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <stack>
28 #include <map>
29 #include <set>
30 #include <list>
31 #include <string>
32 #include <stdint.h>
34 #ifndef FLEXINT_H // Else *FlexLexer will be defined twice
35 # undef yyFlexLexer
36 # define yyFlexLexer shapesFlexLexer
37 # include <FlexLexer.h>
38 #endif
40 class ShapesScanner : public shapesFlexLexer
42 std::stack< yy_buffer_state * > stateStack;
43 std::stack< ::Shapes::Ast::SourceLocation > locStack;
44 std::stack< size_t > pathCountStack;
45 unsigned int quoteDepth;
46 bool moreState;
47 int lastleng;
48 void more( );
49 std::map< const char *, double, charPtrLess > unitTable;
50 const char * newUnitName;
51 std::set< const Shapes::Ast::FileID *, Shapes::Ast::FileIDPtrLess > neededFiles;
52 std::string sourceDir_;
53 std::list< std::string > needSearchPath;
54 bool inPrelude_;
55 std::istream * preludeFile_;
56 std::list< std::string >::const_iterator preludeIterator_;
57 std::list< std::pair< std::istream *, const Shapes::Ast::FileID * > > yyinQueue_;
58 bool showFiles;
59 bool randSeedSet;
60 std::list< std::pair< char *, size_t > > dataStringChunks_;
61 size_t dataStringTotalLength_;
62 bool interactive_;
63 public:
64 // Ast::SourceLocation loc;
65 ShapesScanner( );
66 virtual ~ShapesScanner( );
67 void setInteractive( bool interactive );
68 void start( );
69 void queueStream( std::istream * is, const Shapes::Ast::FileID * yyinFile );
70 void setSourceDir( const std::string & sourceDir );
71 void push_backNeedPath( const std::string & path );
72 std::string searchFile( const std::string & suffix, bool runtime = false ) const;
73 std::string searchFile( const std::string & suffix, struct stat * dstStat, bool runtime = false ) const;
74 void setShowFiles( bool _showFiles );
75 virtual int yylex( );
76 void doBeforeEachAction( );
78 double lookupUnitFactor( const char * name ) const;
79 Shapes::Concrete::Length strtoLength( const char * str ) const;
80 private:
81 std::string currentNeedFile;
82 size_t currentNeedPushCount;
83 bool currentNeedIsNeed;
84 void push_frontNeedPath( const std::string & path );
85 void pop_frontNeedPath( );
86 void doInclusion( );
87 void rinseString( );
88 void concatenateDataString( );
89 uint32_t unicodeFromGlyphname( const char * name );
90 std::string needpathWithSuffix( const std::string & needpath, const std::string & suffix ) const;