2025-01-07 14:08:17 -04:00
|
|
|
%{
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <stdexcept>
|
2025-01-08 06:23:34 -04:00
|
|
|
#include <memory>
|
|
|
|
|
#include <functional>
|
2025-08-29 15:16:11 -04:00
|
|
|
#include <user/deviceAttachmentSpec.h>
|
2025-01-07 14:08:17 -04:00
|
|
|
#include <deviceManager/deviceManager.h>
|
|
|
|
|
|
|
|
|
|
#ifndef yylex
|
|
|
|
|
/* We use different prefixes for the lexer and parser.
|
2025-08-29 15:55:11 -04:00
|
|
|
* * Our lexer's prefix is deviceAttachmentPipeSpecl.
|
|
|
|
|
* * Our parser's prefix is deviceAttachmentPipeSpecp.
|
2025-01-07 14:08:17 -04:00
|
|
|
*
|
|
|
|
|
* Yacc and Bison don't have a way to handle the scenario where the lexer has
|
|
|
|
|
* a different prefix from the parser that they generate. They assume that the
|
|
|
|
|
* lexer must have the same prefix as the parser they generate. So we just use
|
|
|
|
|
* this #define below to override yacc/bison's presumed prefix for the lexer.
|
|
|
|
|
*/
|
2025-01-07 20:21:15 -04:00
|
|
|
#error "Yacc should have defined yylex as a preprocessor token, and we need to override it to tell yacc the name of our lex function."
|
2025-01-07 14:08:17 -04:00
|
|
|
#endif
|
|
|
|
|
#undef yylex
|
2025-08-29 15:55:11 -04:00
|
|
|
#define yylex deviceAttachmentPipeSpecllex
|
2025-01-07 14:08:17 -04:00
|
|
|
|
2025-01-14 23:13:02 -04:00
|
|
|
#ifdef yytext
|
|
|
|
|
#undef yytext
|
|
|
|
|
#endif
|
2025-08-29 15:55:11 -04:00
|
|
|
#define yytext deviceAttachmentPipeSpecltext
|
2025-01-14 23:13:02 -04:00
|
|
|
|
2025-01-07 14:08:17 -04:00
|
|
|
// Declare the symbols that our lexer will export.
|
|
|
|
|
int yylex(void);
|
2025-01-14 23:13:02 -04:00
|
|
|
extern char* yytext; // Declare yytext to access the current token text
|
2025-01-07 14:08:17 -04:00
|
|
|
void yyerror(const char *message)
|
|
|
|
|
{
|
2025-01-14 23:13:02 -04:00
|
|
|
throw std::runtime_error(
|
2025-08-29 15:55:11 -04:00
|
|
|
std::string("deviceAttachmentPipeSpec parser error: ")
|
2025-01-14 23:13:02 -04:00
|
|
|
+ std::string(message)
|
|
|
|
|
+ " at token: " + std::string(yytext));
|
2025-01-07 14:08:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
%union {
|
|
|
|
|
char* str;
|
|
|
|
|
char chr;
|
2025-08-29 15:16:11 -04:00
|
|
|
smo::device::DeviceAttachmentSpec* sensorSpec;
|
|
|
|
|
smo::device::InteroceptorDevAttachmentSpec* interoceptorSpec;
|
|
|
|
|
smo::device::ExtrospectorDevAttachmentSpec* extrospectorSpec;
|
2025-01-14 14:09:35 -04:00
|
|
|
std::vector<std::pair<std::string,std::string>>* paramVector;
|
|
|
|
|
std::pair<std::string,std::string>* param;
|
2025-01-07 14:08:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
%token <str> STRING
|
|
|
|
|
%token PIPE DOUBLE_PIPE LPAREN RPAREN
|
|
|
|
|
%token <chr> KEYWORD_SPECTYPE_ACTUATOR
|
|
|
|
|
%token <chr> KEYWORD_SPECTYPE_EXTROSPECTOR KEYWORD_SPECTYPE_INTEROSPECTOR
|
2025-01-14 14:09:35 -04:00
|
|
|
%token EQUALS // Add new token for '='
|
2025-01-07 14:08:17 -04:00
|
|
|
|
2025-01-14 14:09:35 -04:00
|
|
|
%type <paramVector> params opt_params
|
|
|
|
|
%type <param> param
|
2025-01-07 14:08:17 -04:00
|
|
|
%type <sensorSpec> spec_body
|
|
|
|
|
%type <interoceptorSpec> interoceptor_spec
|
|
|
|
|
%type <extrospectorSpec> extrospector_spec
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
file: /* NOTHING */
|
2025-01-13 08:02:59 -04:00
|
|
|
| sensor_specs
|
2025-01-07 14:08:17 -04:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
sensor_specs:
|
|
|
|
|
sensor_spec
|
|
|
|
|
| sensor_specs DOUBLE_PIPE sensor_spec
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
sensor_spec:
|
|
|
|
|
interoceptor_spec
|
|
|
|
|
| extrospector_spec
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
interoceptor_spec:
|
|
|
|
|
KEYWORD_SPECTYPE_INTEROSPECTOR PIPE spec_body {
|
2025-08-29 15:16:11 -04:00
|
|
|
auto spec = std::make_shared<smo::device::InteroceptorDevAttachmentSpec>(
|
|
|
|
|
*static_cast<smo::device::InteroceptorDevAttachmentSpec *>($3));
|
2025-01-07 14:08:17 -04:00
|
|
|
|
|
|
|
|
spec->sensorType = $1;
|
2025-09-28 12:52:59 -04:00
|
|
|
smo::device::DeviceManager::commandLineDASpecs.push_back(*spec);
|
2025-01-13 08:02:59 -04:00
|
|
|
|
2025-01-08 06:23:34 -04:00
|
|
|
delete $3;
|
2025-01-07 14:08:17 -04:00
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
extrospector_spec:
|
|
|
|
|
KEYWORD_SPECTYPE_EXTROSPECTOR PIPE spec_body {
|
2025-08-29 15:16:11 -04:00
|
|
|
auto spec = std::make_shared<smo::device::ExtrospectorDevAttachmentSpec>(
|
|
|
|
|
*static_cast<smo::device::ExtrospectorDevAttachmentSpec *>($3));
|
2025-01-07 14:08:17 -04:00
|
|
|
|
|
|
|
|
spec->sensorType = $1;
|
2025-09-28 12:52:59 -04:00
|
|
|
smo::device::DeviceManager::commandLineDASpecs.push_back(*spec);
|
2025-01-13 08:02:59 -04:00
|
|
|
|
2025-01-08 06:23:34 -04:00
|
|
|
delete $3;
|
2025-01-07 14:08:17 -04:00
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
spec_body:
|
2025-11-01 00:57:04 -04:00
|
|
|
STRING PIPE STRING LPAREN opt_params RPAREN PIPE STRING LPAREN opt_params RPAREN PIPE STRING LPAREN opt_params RPAREN PIPE STRING {
|
2025-08-29 15:16:11 -04:00
|
|
|
$$ = new smo::device::DeviceAttachmentSpec();
|
|
|
|
|
$$->deviceIdentifier = std::string($1);
|
|
|
|
|
$$->sensorType = '\0'; // This will be set by the parent rule
|
2025-10-01 18:10:58 -04:00
|
|
|
$$->qualeIfaceApi = std::string($3);
|
2025-11-01 00:57:04 -04:00
|
|
|
$$->qualeIfaceApiParams = std::move(*$5);
|
|
|
|
|
$$->stimBuffApi = std::string($8);
|
|
|
|
|
$$->stimBuffApiParams = std::move(*$10);
|
|
|
|
|
$$->provider = std::string($13);
|
|
|
|
|
$$->providerParams = std::move(*$15);
|
|
|
|
|
$$->deviceSelector = std::string($18);
|
|
|
|
|
delete $5;
|
|
|
|
|
delete $10;
|
|
|
|
|
delete $15;
|
2025-01-07 14:08:17 -04:00
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
opt_params:
|
|
|
|
|
params
|
2025-01-14 14:09:35 -04:00
|
|
|
| /* empty */ { $$ = new std::vector<std::pair<std::string,std::string>>(); }
|
|
|
|
|
;
|
|
|
|
|
|
2025-01-07 14:08:17 -04:00
|
|
|
params:
|
2025-01-14 14:09:35 -04:00
|
|
|
param {
|
|
|
|
|
$$ = new std::vector<std::pair<std::string,std::string>>();
|
|
|
|
|
$$->push_back(*$1);
|
|
|
|
|
delete $1;
|
|
|
|
|
}
|
|
|
|
|
| params PIPE param {
|
|
|
|
|
$$ = $1;
|
|
|
|
|
$$->push_back(*$3);
|
|
|
|
|
delete $3;
|
|
|
|
|
}
|
2025-01-07 14:08:17 -04:00
|
|
|
;
|
|
|
|
|
|
2025-01-14 23:14:19 -04:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
2025-01-07 14:08:17 -04:00
|
|
|
%%
|