fieldExprParser.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-2021 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::fieldExpr::parser
28 
29 Description
30  Lemon parser interface for field expressions grammar
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #ifndef expressions_fieldExprParser_H
35 #define expressions_fieldExprParser_H
36 
37 #include "exprScanToken.H"
38 #include "fieldExprFwd.H"
39 
40 namespace Foam
41 {
42 namespace expressions
43 {
44 namespace fieldExpr
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class parser Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 class parser
52 {
53  // Private Data
54 
55  //- Prompt for parser tracing
56  static constexpr const char* const prompt_ = "fieldExpr:";
57 
58  //- The lemon parser (demand-driven)
59  void* lemon_;
60 
61 
62 public:
63 
64  //- Local object debugging
65  int debug;
66 
67 
68  // Constructors
69 
70  //- Construct null
71  parser() : lemon_(nullptr), debug(fieldExpr::debug) {}
72 
73 
74  //- Destructor, deletes parser backend
75  ~parser()
76  {
77  stop();
78  }
79 
80 
81  // Static Member Functions
82 
83  //- Return the text name corresponding to the tokenId
84  static word tokenName(int tokenId);
85 
86  //- Print all token names
87  static void printTokenNames(Ostream& os);
88 
89  //- Print all rules
90  static void printRules(Ostream& os);
91 
92 
93  // Member Functions
94 
95  //- Start parsing, with the given driver context
96  void start(parseDriver& driver_);
97 
98  //- Stop parsing, freeing the allocated parser
99  void stop();
100 
101  //- Push token type to parser with default token
102  void parse(int tokenId);
103 
104  //- Push token type/value to parser
105  void parse(int tokenId, scanToken tok);
106 };
107 
108 
109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110 
111 } // End namespace fieldExpr
112 } // End namespace expressions
113 } // End namespace Foam
114 
115 
116 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
117 
118 #endif
119 
120 // ************************************************************************* //
Foam::expressions::fieldExpr::parser::start
void start(parseDriver &driver_)
Start parsing, with the given driver context.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::expressions::fieldExpr::parser::printTokenNames
static void printTokenNames(Ostream &os)
Print all token names.
fieldExprFwd.H
Foam::expressions::fieldExpr::parseDriver
Driver for generic primitive field expressions.
Definition: fieldExprDriver.H:82
Foam::expressions::fieldExpr::parser
Lemon parser interface for field expressions grammar.
Definition: fieldExprParser.H:50
Foam::expressions::fieldExpr::parser::printRules
static void printRules(Ostream &os)
Print all rules.
Foam::expressions::scanToken
A low-level input/scan token content. No defined constructors/destructors. All memory management is m...
Definition: exprScanToken.H:51
exprScanToken.H
os
OBJstream os(runTime.globalPath()/outputName)
Foam::expressions::fieldExpr::parser::parse
void parse(int tokenId)
Push token type to parser with default token.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::expressions::fieldExpr::parser::debug
int debug
Local object debugging.
Definition: fieldExprParser.H:64
Foam::expressions::fieldExpr::parser::~parser
~parser()
Destructor, deletes parser backend.
Definition: fieldExprParser.H:74
Foam::expressions::fieldExpr::parser::tokenName
static word tokenName(int tokenId)
Return the text name corresponding to the tokenId.
Foam::expressions::fieldExpr::parser::stop
void stop()
Stop parsing, freeing the allocated parser.
Foam::expressions::fieldExpr::parser::parser
parser()
Construct null.
Definition: fieldExprParser.H:70
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56