jesperhh / qmlfmt

qmlfmt - command line application that formats QML files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

generating an AST

opened this issue · comments

hello ,
can you help me to generate an ast in c++ using boost spirit v2 and the grammar bellow ?
I saw all documentation and examples but I stil didn't start .
#include
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/qi_string.hpp>
#include <boost/fusion/adapted.hpp>
using namespace std;
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;

//Nos règles de grammaire
namespace regles_de_grammar{

//Importing our using librairies

using boost::spirit::qi::char_;
using boost::spirit::qi::uint_;
using boost::spirit::qi::int_;
using boost::spirit::qi::lit;

//Rules for predicats

auto pred_gt = char_('>'); // the pred_gt is defined by the character '>'
auto pred_lt = char_('<'); // defined by <

auto pred_ge = char_('>')>char_('=');//defined by > followed by =
auto pred_le = char_('<')>char_('=');//defined by < followed by =
auto pred_eq = char_('=');//defined by =
auto pred_ne = char_('!')>char_('=');//defined by ! followed by =

auto predicate = pred_gt | pred_lt | pred_ge |
pred_le | pred_eq | pred_ne;

auto tbl_name = char_>> *(char_); // the name of the table is a string
auto col_name = char_>> *(char_) ;// the name of a column is a string
auto start= uint_;
auto t_end=uint_;
//je dois verifier col_ref
auto col_reference = col_name | (col_name > '[' > start >':' > ']') | (col_name > '[' > ':' > t_end >']') | (col_name > '['> start > ':'> t_end>']');
auto col_predicate = col_reference >> predicate >> *(char_);
auto col_projection = col_reference >> col_predicate;
auto project_list = (col_projection) % (',') | col_projection;
auto from_stmt = tbl_name;//def of a from statement
auto seq_any_log_expr = "ANY" >> col_predicate;
auto seq_all_log_expr= "ALL">> col_predicate;
auto select = lit("SELECT") > project_list >lit("FROM") >from_stmt;//defined bu select followed by project_list followed by from_stmt
/auto pos_log_expr = col_predicate | (pos_and_log_expr) | (pos_or_log_expr);//let these 2
auto pos_and_log_expr= ((pos_log_expr )> "AND" >( pos_log_expr>));
auto pos_or_log_expr = ((pos_log_expr) > "OR" >>(pos_log_expr)) | pos_log_expr >> "OR" >> pos_log_expr;
/

}//fin namespace regles_de_grammar

Unfortunately I don't have any experience with boost spirit - and this project is also completely unrelated to boost spirit.