sehe / splitting-large-x3-parsers Goto Github PK
View Code? Open in Web Editor NEWin reference to https://stackoverflow.com/questions/61800010/is-this-the-correct-way-of-defining-a-set-of-recursive-rules
in reference to https://stackoverflow.com/questions/61800010/is-this-the-correct-way-of-defining-a-set-of-recursive-rules
Seth,
I think the SIOF problem could be eliminated by using something like:
/** @file
* Defines template class defn_gram,
* for defining the type of right hand side(RHS) of a variable.
* as the nested type.
* The user should provide specializations for a particular
* variable. A macro to help doing this is in DEFN_GRAM.hpp.
* No #include guards are provided because this could be
* used in different grammars in same file.
*/
template
< symb_gram<symb_kinds::varble_kind>::syms AnVarble
/**@brief
* the variable whose RHS is being defined.
*/
>
struct
defn_gram
/**@brief
* Specializations contain nested type
* which is the type of the grammar expression
* defining AnVar.
*/
;
inserted in the parser namespace, and then, for each rule, provide a specialization of the above using
a macro, something like:
#ifndef GRAM_STK_DEFN_GRAM_SPECIAL_HPP_INCLUDED
#define GRAM_STK_DEFN_GRAM_SPECIAL_HPP_INCLUDED
/** @file
*/
/** @def DEFN_GRAM_SPECIAL
* @brief generates, within a grammar class, a specialization
* of defn_gram template class with nested 'using type'
* @param AnVarble the enumerator for the variable to be defined.
* @param Scope the scope (e.g. ClassName::) where the definition occurs.
* Note, it should be empty if the definition is inside the class.
* @param ... the definition of AnVarble
*/
#define DEFN_GRAM_SPECIAL(AnVarble,Scope, ...) \
template<> \
struct Scope \
defn_gram \
< Scope symb_gram<symb_kinds::varble_kind>::syms::AnVarble \
> \
{ using type=decltype( __VA_ARGS__); \
}; \
//DEFN_GRAM define
#endif//GRAM_STK_DEFN_GRAM_SPECIAL_HPP_INCLUDED
Then, in the actual parser_rule, you could use the defn_gram::type to
retrieve the RHS of the rule with RuleId.
In the above, translated RuleId as AnVarble. The above is actually based on
code which uses enum's instead of local classes to be the equivalent of spirit's RuleId.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.