/[svn]/linuxsampler/trunk/src/scriptvm/parser.y
ViewVC logotype

Diff of /linuxsampler/trunk/src/scriptvm/parser.y

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2951 by schoenebeck, Fri Jul 15 20:07:47 2016 UTC revision 3008 by schoenebeck, Tue Oct 11 18:25:12 2016 UTC
# Line 18  Line 18 
18    
19      void InstrScript_error(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* err);      void InstrScript_error(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* err);
20      void InstrScript_warning(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* txt);      void InstrScript_warning(YYLTYPE* locp, LinuxSampler::ParserContext* context, const char* txt);
21        int InstrScript_tnamerr(char* yyres, const char* yystr);
22      int InstrScript_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner);      int InstrScript_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner);
23      #define scanner context->scanner      #define scanner context->scanner
24      #define PARSE_ERR(loc,txt)  yyerror(&loc, context, txt)      #define PARSE_ERR(loc,txt)  yyerror(&loc, context, txt)
25      #define PARSE_WRN(loc,txt)  InstrScript_warning(&loc, context, txt)      #define PARSE_WRN(loc,txt)  InstrScript_warning(&loc, context, txt)
26        #define yytnamerr(res,str)  InstrScript_tnamerr(res, str)
27  %}  %}
28    
29  // generate reentrant safe parser  // generate reentrant safe parser
# Line 34  Line 36 
36  %defines  %defines
37  %error-verbose  %error-verbose
38    
39  %token <iValue> INTEGER  %token <iValue> INTEGER "integer literal"
40  %token <sValue> STRING  %token <sValue> STRING "string literal"
41  %token <sValue> IDENTIFIER  %token <sValue> IDENTIFIER "function name"
42  %token <sValue> VARIABLE  %token <sValue> VARIABLE "variable name"
43  %token ON END INIT NOTE DECLARE ASSIGNMENT WHILE IF OR RELEASE AND ELSE FUNCTION CALL  %token ON "keyword 'on'"
44  %token BITWISE_OR BITWISE_AND BITWISE_NOT  %token END "keyword 'end'"
45  %token CONTROLLER SELECT CASE TO NOT CONST_ POLYPHONIC MOD  %token INIT "keyword 'init'"
46  %token LE GE  %token NOTE "keyword 'note'"
47    %token RELEASE "keyword 'release'"
48    %token CONTROLLER "keyword 'controller'"
49    %token DECLARE "keyword 'declare'"
50    %token ASSIGNMENT "operator ':='"
51    %token CONST_ "keyword 'const'"
52    %token POLYPHONIC "keyword 'polyphonic'"
53    %token WHILE "keyword 'while'"
54    %token IF "keyword 'if'"
55    %token ELSE "keyword 'else'"
56    %token SELECT "keyword 'select'"
57    %token CASE "keyword 'case'"
58    %token TO "keyword 'to'"
59    %token OR "operator 'or'"
60    %token AND "operator 'and'"
61    %token NOT "operator 'not'"
62    %token BITWISE_OR "bitwise operator '.or.'"
63    %token BITWISE_AND "bitwise operator '.and.'"
64    %token BITWISE_NOT "bitwise operator '.not.'"
65    %token FUNCTION "keyword 'function'"
66    %token CALL "keyword 'call'"
67    %token MOD "operator 'mod'"
68    %token LE "operator '<='"
69    %token GE "operator '>='"
70    %token END_OF_FILE 0 "end of file"
71    
72  %type <nEventHandlers> script sections  %type <nEventHandlers> script sections
73  %type <nEventHandler> section eventhandler  %type <nEventHandler> section eventhandler
# Line 774  void InstrScript_warning(YYLTYPE* locp, Line 800  void InstrScript_warning(YYLTYPE* locp,
800      //fprintf(stderr, "WRN %d: %s\n", locp->first_line, txt);      //fprintf(stderr, "WRN %d: %s\n", locp->first_line, txt);
801      context->addWrn(locp->first_line, locp->last_line, locp->first_column+1, locp->last_column+1, txt);      context->addWrn(locp->first_line, locp->last_line, locp->first_column+1, locp->last_column+1, txt);
802  }  }
803    
804    /// Custom implementation of yytnamerr() to ensure quotation is always stripped from token names before printing them to error messages.
805    int InstrScript_tnamerr(char* yyres, const char* yystr) {
806      if (*yystr == '"') {
807          int yyn = 0;
808          char const *yyp = yystr;
809          for (;;)
810            switch (*++yyp)
811              {
812    /*
813              case '\'':
814              case ',':
815                goto do_not_strip_quotes;
816    
817              case '\\':
818                if (*++yyp != '\\')
819                  goto do_not_strip_quotes;
820    */
821                /* Fall through.  */
822              default:
823                if (yyres)
824                  yyres[yyn] = *yyp;
825                yyn++;
826                break;
827    
828              case '"':
829                if (yyres)
830                  yyres[yyn] = '\0';
831                return yyn;
832              }
833        do_not_strip_quotes: ;
834        }
835    
836      if (! yyres)
837        return yystrlen (yystr);
838    
839      return yystpcpy (yyres, yystr) - yyres;
840    }

Legend:
Removed from v.2951  
changed lines
  Added in v.3008

  ViewVC Help
Powered by ViewVC