patchExprScanner.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::expressions::patchExpr::scanner
28 
29 Description
30  Ragel lexer/scanner interface for patch expressions.
31 
32 Note
33  Ragel code generated with the ./createCode script.
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef expressions_patchExprScanner_H
38 #define expressions_patchExprScanner_H
39 
40 #include "patchExprFwd.H"
41 #include "scalar.H"
42 
43 namespace Foam
44 {
45 namespace expressions
46 {
47 namespace patchExpr
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class scanToken Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 union scanToken
55 {
56  Foam::label ivalue;
57  Foam::scalar svalue;
59 
60  //- Null construct, bit-wise zero for union content
61  scanToken() : ivalue(0) {}
62 };
63 
64 
65 /*---------------------------------------------------------------------------*\
66  Class scanner Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class scanner
70 {
71  // Private Data
72 
73  //- Wrapped lemon parser
74  parser* parser_;
75 
76  // Ragel code state, action
77  int cs, act;
78 
79 
80  // Private Member Functions
81 
82  //- Dispatch .method to parser (if known) or Fatal
83  bool dispatch_method
84  (
85  const parseDriver& driver_,
86  scanToken& scanTok,
87  word&& ident
88  ) const;
89 
90  //- Dispatch identifier to parser (if possible) or Fatal
91  bool dispatch_ident
92  (
93  const parseDriver& driver_,
94  scanToken& scanTok,
95  word&& ident
96  ) const;
97 
98 
99 public:
100 
101  //- Local debugging
102  int debug;
103 
104 
105  // Constructors
106 
107  //- Construct null, optionally setting debugging
108  explicit scanner(bool withDebug = false)
109  :
110  parser_(nullptr),
111  debug(patchExpr::debug)
112  {
113  if (withDebug)
114  {
115  debug |= 4;
116  }
117  }
118 
119 
120  //- Destructor, deletes parser
121  ~scanner();
122 
123 
124  // Member Functions
125 
126  //- Evaluate sub-string
127  bool process
128  (
129  const std::string& str, size_t pos, size_t len,
130  parseDriver& driver_
131  );
132 
133  //- Evaluate sub-string
134  bool process
135  (
136  const std::string& str, size_t pos,
137  parseDriver& driver_
138  )
139  {
140  return process(str, pos, std::string::npos, driver_);
141  }
142 
143  //- Evaluate string
144  bool process(const std::string& str, parseDriver& driver_)
145  {
146  return process(str, 0, std::string::npos, driver_);
147  }
148 };
149 
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 } // End namespace patchExpr
154 } // End namespace expressions
155 } // End namespace Foam
156 
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 #endif
161 
162 // ************************************************************************* //
Foam::expressions::patchExpr::scanToken::ivalue
Foam::label ivalue
Definition: patchExprScanner.H:55
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::expressions::patchExpr::scanner::~scanner
~scanner()
Destructor, deletes parser.
Foam::expressions::patchExpr::scanToken::svalue
Foam::scalar svalue
Definition: patchExprScanner.H:56
patchExprFwd.H
Foam::expressions::patchExpr::scanner::process
bool process(const std::string &str, parseDriver &driver_)
Evaluate string.
Definition: patchExprScanner.H:143
Foam::expressions::patchExpr::scanToken::name
Foam::word * name
Definition: patchExprScanner.H:57
Foam::expressions::patchExpr::scanner::scanner
scanner(bool withDebug=false)
Construct null, optionally setting debugging.
Definition: patchExprScanner.H:107
Foam::expressions::patchExpr::scanToken
Definition: patchExprScanner.H:53
scalar.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::expressions::patchExpr::parseDriver
Driver for patch expressions.
Definition: patchExprDriver.H:140
Foam::expressions::patchExpr::parser
Lemon parser interface for patch expressions grammar.
Definition: patchExprParser.H:49
Foam::expressions::patchExpr::scanner::process
bool process(const std::string &str, size_t pos, size_t len, parseDriver &driver_)
Evaluate sub-string.
Foam::expressions::patchExpr::scanner::debug
int debug
Local debugging.
Definition: patchExprScanner.H:101
Foam::expressions::patchExpr::scanToken::scanToken
scanToken()
Null construct, bit-wise zero for union content.
Definition: patchExprScanner.H:60
Foam::expressions::patchExpr::scanner
Ragel lexer/scanner interface for patch expressions.
Definition: patchExprScanner.H:68
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177