Files
salmanoff/smocore/deviceManager/deviceAttachmentPipeSpecp.yy
T

157 lines
4.3 KiB
Plaintext
Raw Normal View History

2025-01-07 14:08:17 -04:00
%{
#include <vector>
#include <utility>
#include <string>
#include <cstring>
#include <cstdlib>
#include <stdexcept>
#include <memory>
#include <functional>
#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.
* * 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
#define yylex deviceAttachmentPipeSpecllex
2025-01-07 14:08:17 -04:00
#ifdef yytext
#undef yytext
#endif
#define yytext deviceAttachmentPipeSpecltext
2025-01-07 14:08:17 -04:00
// Declare the symbols that our lexer will export.
int yylex(void);
extern char* yytext; // Declare yytext to access the current token text
2025-01-07 14:08:17 -04:00
void yyerror(const char *message)
{
throw std::runtime_error(
std::string("deviceAttachmentPipeSpec parser error: ")
+ std::string(message)
+ " at token: " + std::string(yytext));
2025-01-07 14:08:17 -04:00
}
%}
%union {
char* str;
char chr;
smo::device::DeviceAttachmentSpec* sensorSpec;
smo::device::InteroceptorDevAttachmentSpec* interoceptorSpec;
smo::device::ExtrospectorDevAttachmentSpec* extrospectorSpec;
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
%token EQUALS // Add new token for '='
2025-01-07 14:08:17 -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 */
| 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 {
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;
smo::device::DeviceManager::commandLineDASpecs.push_back(*spec);
delete $3;
2025-01-07 14:08:17 -04:00
}
;
extrospector_spec:
KEYWORD_SPECTYPE_EXTROSPECTOR PIPE spec_body {
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;
smo::device::DeviceManager::commandLineDASpecs.push_back(*spec);
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 {
$$ = new smo::device::DeviceAttachmentSpec();
$$->deviceIdentifier = std::string($1);
$$->sensorType = '\0'; // This will be set by the parent rule
$$->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
| /* empty */ { $$ = new std::vector<std::pair<std::string,std::string>>(); }
;
2025-01-07 14:08:17 -04:00
params:
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
%%