@@ -14,6 +14,7 @@ namespace hal
14
14
// stores the list of tokens that are generated and filled during the
15
15
// parsing process adn the different semantic actions
16
16
std::vector<Token> tokens;
17
+ std::stringstream name;
17
18
18
19
// //////////////////////////////////////////////////////////////////////
19
20
// (1) Semantic actions to generate tokens
@@ -27,29 +28,33 @@ namespace hal
27
28
const auto BracketOpenAction = [&tokens](auto & /* ctx */ ) { tokens.emplace_back (BooleanFunctionParser::Token::BracketOpen ()); };
28
29
const auto BracketCloseAction = [&tokens](auto & /* ctx */ ) { tokens.emplace_back (BooleanFunctionParser::Token::BracketClose ()); };
29
30
30
- const auto VariableAction = [&tokens](auto & ctx) {
31
+ const auto VariableStartAction = [&tokens, &name ](auto & ctx) {
31
32
// # Developer Note
32
33
// We combine the first matched character with the remaining
33
34
// string and do not remove any preceding '/' character.
34
- std::stringstream name;
35
- name << std::string (1 , boost::fusion::at_c<0 >(_attr (ctx)));
35
+
36
+ name.str (" " );
37
+
36
38
name << boost::fusion::at_c<1 >(_attr (ctx));
39
+ name << boost::fusion::at_c<2 >(_attr (ctx));
37
40
38
- tokens. emplace_back ( BooleanFunctionParser::Token::Variable ( name.str (), 1 )) ;
41
+ std::cout << " Start: " << name.str () << std::endl ;
39
42
};
40
- const auto VariableIndexAction = [&tokens](auto & ctx) {
41
- // # Developer Note
42
- // Since the first character is an optional '\' character and
43
- // generally escaped a.k.a. removed within HAL, we also do not
44
- // touch the part and only assemble the remaining string.
45
- std::stringstream name;
46
- name << std::string (1 , boost::fusion::at_c<1 >(_attr (ctx)));
43
+ const auto VariableBracketAction = [&tokens, &name](auto & ctx) {
44
+ name << boost::fusion::at_c<0 >(_attr (ctx));
45
+ name << boost::fusion::at_c<1 >(_attr (ctx));
47
46
name << boost::fusion::at_c<2 >(_attr (ctx));
48
47
name << boost::fusion::at_c<3 >(_attr (ctx));
49
- name << boost::fusion::at_c<4 >(_attr (ctx));
50
- name << boost::fusion::at_c<5 >(_attr (ctx));
48
+
49
+ std::cout << " Bracket: " << name.str () << std::endl;
50
+ };
51
+ const auto VariableAction = [&tokens, &name](auto & /* ctx*/ ) {
52
+ std::cout << " Push:" << name.str () << std::endl;
53
+
51
54
tokens.emplace_back (BooleanFunctionParser::Token::Variable (name.str (), 1 ));
55
+ name.str (" " );
52
56
};
57
+
53
58
const auto ConstantAction = [&tokens](auto & ctx) {
54
59
const auto value = (_attr (ctx) == ' 0' ) ? BooleanFunction::Value::ZERO : BooleanFunction::Value::ONE;
55
60
tokens.emplace_back (BooleanFunctionParser::Token::Constant ({value}));
@@ -69,10 +74,13 @@ namespace hal
69
74
const auto BracketOpenRule = x3::lit (" (" )[BracketOpenAction];
70
75
const auto BracketCloseRule = x3::lit (" )" )[BracketCloseAction];
71
76
72
- const auto VariableRule = x3::lexeme[(x3::char_ (" a-zA-Z" ) >> *x3::char_ (" a-zA-Z0-9_" ))][VariableAction];
73
- const auto VariableIndexRoundBracketRule = x3::lexeme[(-(x3::char_ (" \\ " )) >> x3::char_ (" a-zA-Z" ) >> *x3::char_ (" a-zA-Z0-9_" ) >> x3::char_ (" (" ) >> x3::int_ >> x3::char_ (" )" ))] [VariableIndexAction];
74
- const auto VariableIndexSquareBracketRule = x3::lexeme[(-(x3::char_ (" \\ " )) >> x3::char_ (" a-zA-Z" ) >> *x3::char_ (" a-zA-Z0-9_" ) >> x3::char_ (" [" ) >> x3::int_ >> x3::char_ (" ]" ))] [VariableIndexAction];
75
- const auto VariableIndexRule = VariableIndexRoundBracketRule | VariableIndexSquareBracketRule;
77
+ const auto VariableStartRule = x3::lexeme[(-(x3::char_ (" \\ " )) >> x3::char_ (" a-zA-Z" )) >> *x3::char_ (" a-zA-Z" )];
78
+ const auto VariableRoundBracketRule = x3::lexeme[(x3::char_ (" (" ) >> x3::int_ >> x3::char_ (" )" ) >> *x3::char_ (" a-zA-Z0-9_" ))] ;
79
+ const auto VariableSquareBracketRule = x3::lexeme[(x3::char_ (" [" ) >> x3::int_ >> x3::char_ (" ]" ) >> *x3::char_ (" a-zA-Z0-9_" ))] [VariableBracketAction];
80
+
81
+ // const auto VariableRule3 = ;
82
+ // const auto VariableRule2 = VariableRule2 ;
83
+ const auto VariableRule = (VariableStartRule >> *(VariableRoundBracketRule[VariableBracketAction] | VariableSquareBracketRule[VariableStartAction]))[VariableAction];
76
84
77
85
const auto ConstantRule = x3::lexeme[x3::char_ (" 0-1" )][ConstantAction];
78
86
const auto ConstantPrefixRule = x3::lit (" 0b" ) >> x3::lexeme[x3::char_ (" 0-1" )][ConstantAction];
@@ -85,7 +93,7 @@ namespace hal
85
93
// //////////////////////////////////////////////////////////////////
86
94
// (3) Parsing Expression Grammar
87
95
// //////////////////////////////////////////////////////////////////
88
- +(AndRule | NotRule | OrRule | XorRule | VariableIndexRule | VariableRule | ConstantSuffixRule | ConstantPrefixRule | ConstantRule | BracketOpenRule | BracketCloseRule),
96
+ +(AndRule | NotRule | OrRule | XorRule | VariableRule | ConstantSuffixRule | ConstantPrefixRule | ConstantRule | BracketOpenRule | BracketCloseRule),
89
97
x3::space // skips any whitespace in between boolean function
90
98
);
91
99
0 commit comments