0031756: Data Exchange - broken parsing of STEP entity in case of missing last parameter
[occt.git] / src / StepFile / step.lex
1 /* 
2  Copyright (c) 1999-2014 OPEN CASCADE SAS
3
4  This file is part of Open CASCADE Technology software library.
5
6  This library is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License version 2.1 as published
8  by the Free Software Foundation, with special exception defined in the file
9  OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10  distribution for complete text of the license and disclaimer of any warranty.
11
12  Alternatively, this file may be used under the terms of Open CASCADE
13  commercial license or contractual agreement.
14 */ 
15
16 /*
17     c++                 generate C++ parser class
18     8bit                don't fail on 8-bit input characters
19     warn                warn about inconsistencies
20     nodefault           don't create default echo-all rule
21     noyywrap            don't use yywrap() function
22     yyclass             define name of the scanner class
23 */
24 %option c++
25 %option 8bit warn nodefault
26 %option noyywrap
27 %option yyclass="step::scanner"
28
29 %top{
30 // This file is part of Open CASCADE Technology software library.
31 // This file is generated, do not modify it directly; edit source file step.lex instead.
32
33 // Pre-include stdlib.h to avoid redefinition of integer type macros (INT8_MIN and similar in generated code)
34 #if !defined(_MSC_VER) || (_MSC_VER >= 1600) // Visual Studio 2010+
35 #include "stdint.h"
36 #endif
37 }
38
39 %{
40 #include <step.tab.hxx>
41 #include "stdio.h"
42
43 // Tell flex which function to define
44 #ifdef  YY_DECL
45 # undef YY_DECL
46 #endif
47 #define YY_DECL int step::scanner::lex (step::parser::semantic_type* /*yylval*/, step::parser::location_type* /*yylloc*/)
48
49 typedef step::parser::token token;
50
51 /* skl 31.01.2002 for OCC133(OCC96,97) - uncorrect
52 long string in files Henri.stp and 401.stp*/
53 #include <Standard_Failure.hxx>
54 #define YY_FATAL_ERROR(msg) Standard_Failure::Raise(msg);
55
56 /* abv 07.06.02: force inclusion of stdlib.h on WNT to avoid warnings */
57 #ifdef _MSC_VER
58 // add includes for flex 2.91 (Linux version)
59 #include <stdlib.h>
60 #include <io.h>
61
62 // Avoid includion of unistd.h if parser is generated on Linux (flex 2.5.35)
63 #ifndef YY_NO_UNISTD_H
64 #define YY_NO_UNISTD_H
65 #endif
66
67 // disable MSVC warnings in flex 2.89 and 2.5.35 code
68 // Note that Intel compiler also defines _MSC_VER but has different warning ids
69 #if defined(__INTEL_COMPILER)
70 #pragma warning(disable:177 1786 1736)
71 #elif defined(__clang__)
72 #pragma GCC diagnostic ignored "-Wunused-function"
73 #pragma GCC diagnostic ignored "-Winconsistent-dllimport"
74 #pragma GCC diagnostic ignored "-Wunneeded-internal-declaration"
75 #else
76 #pragma warning(disable:4131 4244 4273 4127 4267)
77 #endif
78
79 #endif /* MSC_VER */
80
81 #define CreateNewText myDataModel->CreateNewText
82 #define SetTypeArg myDataModel->SetTypeArg
83
84 // disable GCC warnings in flex code
85 #ifdef __GNUC__
86 #pragma GCC diagnostic ignored "-Wunused-function"
87 #if (__GNUC__ > 5)
88 #pragma GCC diagnostic ignored "-Wmisleading-indentation"
89 #endif
90 #endif
91 %}
92 %x Com End Text
93 %%
94 "/*"               { BEGIN(Com); }     /* start of comment - put the scanner in the "Com" state */
95 <Com>[^*\n]*       {;}                 /* in comment, skip any characters except asterisk (and newline, handled by its own rule) */
96 <Com>[*]+[^*/\n]*  {;}                 /* in comment, skip any sequence of asterisks followed by other symbols (except slash or newline) */
97 <Com>[*]+[/]       { BEGIN(INITIAL); } /* end of comment - reset the scanner to initial state */
98
99 [']                { BEGIN(Text); yymore(); }   /* start of quoted text string - put the scanner in the "Text" state, but keep ' as part of yytext */
100 <Text>[\n]         { yymore(); yylineno ++; }   /* newline in text string - increment line counter and keep collecting yytext */
101 <Text>[']          { yymore(); }                /* single ' inside text string - keep collecting yytext*/
102 <Text>[^\n']+      { yymore(); }                /* a sequence of any characters except ' and \n - keep collecting yytext */
103 <Text>[']/[" "\n\r]*[\)\,]    { BEGIN(INITIAL); CreateNewText(YYText(),YYLeng()); SetTypeArg(ArgumentType_Text); return(token::QUID); } /* end of string (apostrophe followed by comma or closing parenthesis) - reset the scanner to initial state, record the value of all yytext collected */
104
105 "       "       {;}
106 " "             {;}
107 <*>[\n]         { yylineno ++; } /* count lines (one rule for all start conditions) */
108 [\r]            {;} /* abv 30.06.00: for reading DOS files */
109 [\0]+           {;} /* fix from C21. for test load e3i file with line 15 with null symbols */
110
111 #[0-9]+/=               { CreateNewText(YYText(),YYLeng()); return(token::ENTITY); }
112 #[0-9]+/[       ]*=     { CreateNewText(YYText(),YYLeng()); return(token::ENTITY); }
113 #[0-9]+         { CreateNewText(YYText(),YYLeng()); return(token::IDENT); }
114 [-+0-9][0-9]*   { CreateNewText(YYText(),YYLeng()); SetTypeArg(ArgumentType_Integer); return(token::QUID); }
115 [-+\.0-9][\.0-9]+       { CreateNewText(YYText(),YYLeng()); SetTypeArg(ArgumentType_Float); return(token::QUID); }
116 [-+\.0-9][\.0-9]+E[-+0-9][0-9]* { CreateNewText(YYText(),YYLeng()); SetTypeArg(ArgumentType_Float); return(token::QUID); }
117 ["][0-9A-F]+["]         { CreateNewText(YYText(),YYLeng()); SetTypeArg(ArgumentType_Hexa); return(token::QUID); }
118 [.]*[A-Z0-9_]+[.]       { CreateNewText(YYText(),YYLeng()); SetTypeArg(ArgumentType_Enum); return(token::QUID); }
119 [(]             { return ('('); }
120 [)]             { return (')'); }
121 [,]             { myDataModel->PrepareNewArg(); return (','); }
122 [$]             { CreateNewText(YYText(),YYLeng()); SetTypeArg(ArgumentType_Nondef); return(token::QUID); }
123 [=]             { return ('='); }
124 [;]             { return (';'); }
125
126 (?i:STEP);            { return(token::STEP); }
127 (?i:HEADER);          { return(token::HEADER); }
128 (?i:ENDSEC);          { return(token::ENDSEC); }
129 (?i:DATA);            { return(token::DATA); }
130 (?i:ENDSTEP);         { return(token::ENDSTEP);}
131 (?i:ENDSTEP);.*       { return(token::ENDSTEP);}
132 (?i:END-ISO)[0-9\-]*; { BEGIN(End); return(token::ENDSTEP); } /* at the end of the STEP data, enter dedicated start condition "End" to skip everything that follows */
133 (?i:ISO)[0-9\-]*;     { return(token::STEP); }
134
135 [/]            { return ('/'); }
136 &(?i:SCOPE)        { return(token::SCOPE); }
137 (?i:ENDSCOPE)  { return(token::ENDSCOPE); }
138 [a-zA-Z0-9_]+  { CreateNewText(YYText(),YYLeng()); return(token::TYPE); }
139 ![a-zA-Z0-9_]+ { CreateNewText(YYText(),YYLeng()); return(token::TYPE); }
140 [^)]           { CreateNewText(YYText(),YYLeng()); SetTypeArg(ArgumentType_Misc); return(token::QUID); }
141
142 <End>[^\n]     {;} /* skip any characters (except newlines) */
143
144 %%
145
146 step::scanner::scanner(StepFile_ReadData* theDataModel, std::istream* in, std::ostream* out)
147     : stepFlexLexer(in, out), myDataModel(theDataModel)
148 {
149 }