DevSpec: Grammar now parses params as key[=[val]]
* Updated docs to reflect this. * This was important in allowing us to write the xcbXorg connection code.
This commit is contained in:
@@ -23,7 +23,8 @@
|
||||
"|" { return PIPE; }
|
||||
"(" { return LPAREN; }
|
||||
")" { return RPAREN; }
|
||||
[^\|\(\) \t\r\n]+ { deviceSpecplval.str = strdup(yytext); return STRING; }
|
||||
[ \t]*"="[ \t]* { return EQUALS; } // Allow optional whitespace around equals
|
||||
[^=\|\(\) \t\r\n]+ { deviceSpecplval.str = strdup(yytext); return STRING; } // Exclude = from STRING tokens
|
||||
\r?\n { /* ignore newlines */ }
|
||||
[ \t]+ { /* ignore whitespace */ }
|
||||
. { return yytext[0]; }
|
||||
|
||||
@@ -42,15 +42,18 @@ void yyerror(const char *message)
|
||||
hk::device::SenseDeviceSpec* sensorSpec;
|
||||
hk::device::InteroceptorDeviceSpec* interoceptorSpec;
|
||||
hk::device::ExtrospectorDeviceSpec* extrospectorSpec;
|
||||
std::vector<std::string>* stringVector;
|
||||
std::vector<std::pair<std::string,std::string>>* paramVector;
|
||||
std::pair<std::string,std::string>* param;
|
||||
}
|
||||
|
||||
%token <str> STRING
|
||||
%token PIPE DOUBLE_PIPE LPAREN RPAREN
|
||||
%token <chr> KEYWORD_SPECTYPE_ACTUATOR
|
||||
%token <chr> KEYWORD_SPECTYPE_EXTROSPECTOR KEYWORD_SPECTYPE_INTEROSPECTOR
|
||||
%token EQUALS // Add new token for '='
|
||||
|
||||
%type <stringVector> params opt_params
|
||||
%type <paramVector> params opt_params
|
||||
%type <param> param
|
||||
%type <sensorSpec> spec_body
|
||||
%type <interoceptorSpec> interoceptor_spec
|
||||
%type <extrospectorSpec> extrospector_spec
|
||||
@@ -114,12 +117,32 @@ spec_body:
|
||||
|
||||
opt_params:
|
||||
params
|
||||
| /* empty */ { $$ = new std::vector<std::string>(); }
|
||||
| /* empty */ { $$ = new std::vector<std::pair<std::string,std::string>>(); }
|
||||
;
|
||||
|
||||
param:
|
||||
STRING {
|
||||
$$ = new std::pair<std::string,std::string>($1, "");
|
||||
}
|
||||
| STRING EQUALS {
|
||||
$$ = new std::pair<std::string,std::string>($1, "");
|
||||
}
|
||||
| STRING EQUALS STRING {
|
||||
$$ = new std::pair<std::string,std::string>($1, $3);
|
||||
}
|
||||
;
|
||||
|
||||
params:
|
||||
STRING { $$ = new std::vector<std::string>{ $1 }; }
|
||||
| params PIPE STRING { $$ = $1; $$->push_back($3); }
|
||||
param {
|
||||
$$ = new std::vector<std::pair<std::string,std::string>>();
|
||||
$$->push_back(*$1);
|
||||
delete $1;
|
||||
}
|
||||
| params PIPE param {
|
||||
$$ = $1;
|
||||
$$->push_back(*$3);
|
||||
delete $3;
|
||||
}
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
Reference in New Issue
Block a user