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:
@@ -46,6 +46,11 @@ If there's more than one parameter item in a list of `api-params` or
|
||||
+edev|audio-implexor|alsa(shmem|param2|param3)|alsa()|cardname
|
||||
```
|
||||
|
||||
Each parameter must be in one of these forms:
|
||||
* key=value
|
||||
* key=
|
||||
* key
|
||||
|
||||
Some examples follow:
|
||||
|
||||
### To attach a particular window from a window manager:
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
@@ -30,9 +30,9 @@ public:
|
||||
char sensorType;
|
||||
std::string implexor;
|
||||
std::string api;
|
||||
std::vector<std::string> apiParams;
|
||||
std::vector<std::pair<std::string,std::string>> apiParams;
|
||||
std::string provider;
|
||||
std::vector<std::string> providerParams;
|
||||
std::vector<std::pair<std::string,std::string>> providerParams;
|
||||
std::string deviceSelector;
|
||||
|
||||
std::string stringify() const
|
||||
@@ -42,12 +42,20 @@ public:
|
||||
<< implexor << ", API: " << api << ", API Params: (";
|
||||
for (const auto& param : apiParams)
|
||||
{
|
||||
os << param << " ";
|
||||
os << param.first;
|
||||
if (!param.second.empty()) {
|
||||
os << "=" << param.second;
|
||||
}
|
||||
os << " ";
|
||||
}
|
||||
os << "), Provider: " << provider << ", Provider Params: (";
|
||||
for (const auto& param : providerParams)
|
||||
{
|
||||
os << param << " ";
|
||||
os << param.first;
|
||||
if (!param.second.empty()) {
|
||||
os << "=" << param.second;
|
||||
}
|
||||
os << " ";
|
||||
}
|
||||
os << "), Device Selector: " << deviceSelector << std::endl;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user