/[svn]/linuxsampler/trunk/src/network/lscp.y
ViewVC logotype

Diff of /linuxsampler/trunk/src/network/lscp.y

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

revision 1245 by schoenebeck, Tue Jun 19 15:54:13 2007 UTC revision 1332 by schoenebeck, Sun Sep 9 12:22:34 2007 UTC
# Line 37  Line 37 
37    
38  // to save us typing work in the rules action definitions  // to save us typing work in the rules action definitions
39  #define LSCPSERVER ((yyparse_param_t*) yyparse_param)->pServer  #define LSCPSERVER ((yyparse_param_t*) yyparse_param)->pServer
40    #define SESSION_PARAM ((yyparse_param_t*) yyparse_param)
41    #define INCREMENT_LINE { SESSION_PARAM->iLine++; SESSION_PARAM->iColumn = 0; }
42    
43  // clears input buffer  // clears input buffer
44  void restart(yyparse_param_t* pparam, int& yychar);  void restart(yyparse_param_t* pparam, int& yychar);
# Line 48  void yyerror(const char* s); Line 50  void yyerror(const char* s);
50  static char buf[1024]; // input buffer to feed the parser with new characters  static char buf[1024]; // input buffer to feed the parser with new characters
51  static int bytes = 0;  // current number of characters in the input buffer  static int bytes = 0;  // current number of characters in the input buffer
52  static int ptr   = 0;  // current position in the input buffer  static int ptr   = 0;  // current position in the input buffer
53    static String sLastError; // error message of the last error occured
54    
55  // external reference to the function which actually reads from the socket  // external reference to the function which actually reads from the socket
56  extern int GetLSCPCommand( void *buf, int max_size);  extern int GetLSCPCommand( void *buf, int max_size);
57    
58    // external reference to the function in lscpserver.cpp which returns the
59    // current session (only works because the server runs as singleton)
60    extern yyparse_param_t* GetCurrentYaccSession();
61    
62  // returns true if supplied characters has an ASCII code of 128 or higher  // returns true if supplied characters has an ASCII code of 128 or higher
63  inline bool isExtendedAsciiChar(const char c) {  inline bool isExtendedAsciiChar(const char c) {
64      return (c < 0);      return (c < 0);
# Line 72  int yylex(YYSTYPE* yylval) { Line 79  int yylex(YYSTYPE* yylval) {
79      }      }
80      // this is the next character in the input stream      // this is the next character in the input stream
81      const char c = buf[ptr++];      const char c = buf[ptr++];
82        // increment current reading position (just for verbosity / messages)
83        GetCurrentYaccSession()->iColumn++;
84      // we have to handle "normal" and "extended" ASCII characters separately      // we have to handle "normal" and "extended" ASCII characters separately
85      if (isExtendedAsciiChar(c)) {      if (isExtendedAsciiChar(c)) {
86          // workaround for characters with ASCII code higher than 127          // workaround for characters with ASCII code higher than 127
# Line 123  int hexsToNumber(char hex_digit0, char h Line 132  int hexsToNumber(char hex_digit0, char h
132    
133  // reentrant parser  // reentrant parser
134  %pure_parser  %pure_parser
135    
136    // tell bison to spit out verbose syntax error messages
137  %error-verbose  %error-verbose
138    
139  %token <Char> EXT_ASCII_CHAR  %token <Char> EXT_ASCII_CHAR
140    
141  %type <Char> char digit digit_oct digit_hex escape_seq escape_seq_octal escape_seq_hex  %type <Char> char char_base digit digit_oct digit_hex escape_seq escape_seq_octal escape_seq_hex
142  %type <Dotnum> dotnum volume_value boolean  %type <Dotnum> dotnum volume_value boolean
143  %type <Number> number sampler_channel instrument_index fx_send_id audio_channel_index device_index midi_input_channel_index midi_input_port_index midi_map midi_bank midi_prog midi_ctrl  %type <Number> number sampler_channel instrument_index fx_send_id audio_channel_index device_index midi_input_channel_index midi_input_port_index midi_map midi_bank midi_prog midi_ctrl
144  %type <String> string string_escaped text text_escaped stringval stringval_escaped digits param_val_list param_val query_val pathname dirname filename map_name entry_name fx_send_name engine_name command add_instruction create_instruction destroy_instruction get_instruction list_instruction load_instruction set_chan_instruction load_instr_args load_engine_args audio_output_type_name midi_input_type_name remove_instruction unmap_instruction set_instruction subscribe_event unsubscribe_event map_instruction reset_instruction clear_instruction find_instruction move_instruction copy_instruction scan_mode edit_instruction  %type <String> string string_escaped text text_escaped stringval digits param_val_list param_val query_val pathname dirname filename map_name entry_name fx_send_name engine_name command add_instruction create_instruction destroy_instruction get_instruction list_instruction load_instruction set_chan_instruction load_instr_args load_engine_args audio_output_type_name midi_input_type_name remove_instruction unmap_instruction set_instruction subscribe_event unsubscribe_event map_instruction reset_instruction clear_instruction find_instruction move_instruction copy_instruction scan_mode edit_instruction
145  %type <FillResponse> buffer_size_type  %type <FillResponse> buffer_size_type
146  %type <KeyValList> key_val_list query_val_list  %type <KeyValList> key_val_list query_val_list
147  %type <LoadMode> instr_load_mode  %type <LoadMode> instr_load_mode
148  %type <Bool> modal_arg  %type <Bool> modal_arg
149    %type <UniversalPath> path path_base
150    
151  %start input  %start input
152    
# Line 155  input                 : line LF Line 167  input                 : line LF
167                        | line CR LF                        | line CR LF
168                        ;                        ;
169    
170  line                  :  /* epsilon (empty line ignored) */ { return LSCP_DONE; }  line                  :  /* epsilon (empty line ignored) */ { INCREMENT_LINE; return LSCP_DONE; }
171                        |  comment  { return LSCP_DONE; }                        |  comment  { INCREMENT_LINE; return LSCP_DONE; }
172                        |  command  { LSCPSERVER->AnswerClient($1); return LSCP_DONE; }                        |  command  { INCREMENT_LINE; LSCPSERVER->AnswerClient($1); return LSCP_DONE; }
173                        |  error    { LSCPSERVER->AnswerClient("ERR:0:Unknown command.\r\n"); RESTART; return LSCP_SYNTAX_ERROR; }                        |  error    { INCREMENT_LINE; LSCPSERVER->AnswerClient("ERR:0:" + sLastError + "\r\n"); RESTART; return LSCP_SYNTAX_ERROR; }
174                        ;                        ;
175    
176  comment               :  '#'  comment               :  '#'
# Line 315  get_instruction       :  AVAILABLE_ENGIN Line 327  get_instruction       :  AVAILABLE_ENGIN
327  set_instruction       :  AUDIO_OUTPUT_DEVICE_PARAMETER SP number SP string '=' param_val_list             { $$ = LSCPSERVER->SetAudioOutputDeviceParameter($3, $5, $7);      }  set_instruction       :  AUDIO_OUTPUT_DEVICE_PARAMETER SP number SP string '=' param_val_list             { $$ = LSCPSERVER->SetAudioOutputDeviceParameter($3, $5, $7);      }
328                        |  AUDIO_OUTPUT_CHANNEL_PARAMETER SP number SP number SP string '=' param_val_list  { $$ = LSCPSERVER->SetAudioOutputChannelParameter($3, $5, $7, $9); }                        |  AUDIO_OUTPUT_CHANNEL_PARAMETER SP number SP number SP string '=' param_val_list  { $$ = LSCPSERVER->SetAudioOutputChannelParameter($3, $5, $7, $9); }
329                        |  MIDI_INPUT_DEVICE_PARAMETER SP number SP string '=' param_val_list               { $$ = LSCPSERVER->SetMidiInputDeviceParameter($3, $5, $7);        }                        |  MIDI_INPUT_DEVICE_PARAMETER SP number SP string '=' param_val_list               { $$ = LSCPSERVER->SetMidiInputDeviceParameter($3, $5, $7);        }
330                          |  MIDI_INPUT_PORT_PARAMETER SP number SP number SP string '=' NONE                 { $$ = LSCPSERVER->SetMidiInputPortParameter($3, $5, $7, "");      }
331                        |  MIDI_INPUT_PORT_PARAMETER SP number SP number SP string '=' param_val_list       { $$ = LSCPSERVER->SetMidiInputPortParameter($3, $5, $7, $9);      }                        |  MIDI_INPUT_PORT_PARAMETER SP number SP number SP string '=' param_val_list       { $$ = LSCPSERVER->SetMidiInputPortParameter($3, $5, $7, $9);      }
332                        |  CHANNEL SP set_chan_instruction                                                  { $$ = $3;                                                         }                        |  CHANNEL SP set_chan_instruction                                                  { $$ = $3;                                                         }
333                        |  MIDI_INSTRUMENT_MAP SP NAME SP midi_map SP map_name                              { $$ = LSCPSERVER->SetMidiInstrumentMapName($5, $7);               }                        |  MIDI_INSTRUMENT_MAP SP NAME SP midi_map SP map_name                              { $$ = LSCPSERVER->SetMidiInstrumentMapName($5, $7);               }
# Line 480  pathname                  :  stringval Line 493  pathname                  :  stringval
493  dirname                   :  stringval  dirname                   :  stringval
494                            ;                            ;
495    
496  filename                  :  stringval_escaped  filename                  :  path  { $$ = $1.toPosix(); /*TODO: assuming POSIX*/ }
497                            ;                            ;
498    
499  map_name                  :  stringval  map_name                  :  stringval
# Line 524  boolean               :  number  { $$ = Line 537  boolean               :  number  { $$ =
537                        |  string  { $$ = -1; }                        |  string  { $$ = -1; }
538                        ;                        ;
539    
 string                :  char          { std::string s; s = $1; $$ = s; }  
                       |  '\\'          { $$ = "\\";                     } // we have to place this rule here, because we currently distinguish between escaped and unescaped strings  
                       |  string char   { $$ = $1 + $2;                  }  
                       ;  
   
 string_escaped        :  char                        { std::string s; s = $1; $$ = s; }  
                       |  escape_seq                  { std::string s; s = $1; $$ = s; }  
                       |  string_escaped char         { $$ = $1 + $2;                  }  
                       |  string_escaped escape_seq   { $$ = $1 + $2;                  }  
                       ;  
   
540  dotnum                :      digits '.' digits  { $$ = atof(String($1 + "." + $3).c_str());                         }  dotnum                :      digits '.' digits  { $$ = atof(String($1 + "." + $3).c_str());                         }
541                        |  '+' digits '.' digits  { String s = "+"; s += $2; s += "."; s += $4; $$ = atof(s.c_str()); }                        |  '+' digits '.' digits  { String s = "+"; s += $2; s += "."; s += $4; $$ = atof(s.c_str()); }
542                        |  '-' digits '.' digits  { $$ = atof(String("-" + $2 + "." + $4).c_str());                   }                        |  '-' digits '.' digits  { $$ = atof(String("-" + $2 + "." + $4).c_str());                   }
# Line 601  number                :  digit       { $ Line 603  number                :  digit       { $
603                        |  '7' digits  { $$ = atoi(String(String("7") + $2).c_str()); }                        |  '7' digits  { $$ = atoi(String(String("7") + $2).c_str()); }
604                        |  '8' digits  { $$ = atoi(String(String("8") + $2).c_str()); }                        |  '8' digits  { $$ = atoi(String(String("8") + $2).c_str()); }
605                        |  '9' digits  { $$ = atoi(String(String("9") + $2).c_str()); }                        |  '9' digits  { $$ = atoi(String(String("9") + $2).c_str()); }
606                          ;
607    
608  char                  :  'A' { $$ = 'A'; } | 'B' { $$ = 'B'; } | 'C' { $$ = 'C'; } | 'D' { $$ = 'D'; } | 'E' { $$ = 'E'; } | 'F' { $$ = 'F'; } | 'G' { $$ = 'G'; } | 'H' { $$ = 'H'; } | 'I' { $$ = 'I'; } | 'J' { $$ = 'J'; } | 'K' { $$ = 'K'; } | 'L' { $$ = 'L'; } | 'M' { $$ = 'M'; } | 'N' { $$ = 'N'; } | 'O' { $$ = 'O'; } | 'P' { $$ = 'P'; } | 'Q' { $$ = 'Q'; } | 'R' { $$ = 'R'; } | 'S' { $$ = 'S'; } | 'T' { $$ = 'T'; } | 'U' { $$ = 'U'; } | 'V' { $$ = 'V'; } | 'W' { $$ = 'W'; } | 'X' { $$ = 'X'; } | 'Y' { $$ = 'Y'; } | 'Z' { $$ = 'Z'; }  path                  :  '\'' path_base '\''  { $$ = $2; }
609                        |  'a' { $$ = 'a'; } | 'b' { $$ = 'b'; } | 'c' { $$ = 'c'; } | 'd' { $$ = 'd'; } | 'e' { $$ = 'e'; } | 'f' { $$ = 'f'; } | 'g' { $$ = 'g'; } | 'h' { $$ = 'h'; } | 'i' { $$ = 'i'; } | 'j' { $$ = 'j'; } | 'k' { $$ = 'k'; } | 'l' { $$ = 'l'; } | 'm' { $$ = 'm'; } | 'n' { $$ = 'n'; } | 'o' { $$ = 'o'; } | 'p' { $$ = 'p'; } | 'q' { $$ = 'q'; } | 'r' { $$ = 'r'; } | 's' { $$ = 's'; } | 't' { $$ = 't'; } | 'u' { $$ = 'u'; } | 'v' { $$ = 'v'; } | 'w' { $$ = 'w'; } | 'x' { $$ = 'x'; } | 'y' { $$ = 'y'; } | 'z' { $$ = 'z'; }                        |  '\"' path_base '\"'  { $$ = $2; }
610                        |  '0' { $$ = '0'; } | '1' { $$ = '1'; } | '2' { $$ = '2'; } | '3' { $$ = '3'; } | '4' { $$ = '4'; } | '5' { $$ = '5'; } | '6' { $$ = '6'; } | '7' { $$ = '7'; } | '8' { $$ = '8'; } | '9' { $$ = '9'; }                        ;
611                        |  '!' { $$ = '!'; } | '#' { $$ = '#'; } | '$' { $$ = '$'; } | '%' { $$ = '%'; } | '&' { $$ = '&'; } | '(' { $$ = '('; } | ')' { $$ = ')'; } | '*' { $$ = '*'; } | '+' { $$ = '+'; } | '-' { $$ = '-'; } | '.' { $$ = '.'; } | ',' { $$ = ','; } | '/' { $$ = '/'; }  
612                        |  ':' { $$ = ':'; } | ';' { $$ = ';'; } | '<' { $$ = '<'; } | '=' { $$ = '='; } | '>' { $$ = '>'; } | '?' { $$ = '?'; } | '@' { $$ = '@'; }  path_base             :  '/'                     { $$ = Path();                           }
613                        |  '[' { $$ = '['; } | ']' { $$ = ']'; } | '^' { $$ = '^'; } | '_' { $$ = '_'; }                        |  path_base '/'           { $$ = $1;                               }
614                        |  '{' { $$ = '{'; } | '|' { $$ = '|'; } | '}' { $$ = '}'; } | '~' { $$ = '~'; }                        |  path_base text_escaped  { Path p; p.appendNode($2); $$ = $1 + p; }
615                        |  EXT_ASCII_CHAR                        ;
616    
617    stringval             :  '\'' text '\''  { $$ = $2; }
618                          |  '\"' text '\"'  { $$ = $2; }
619                        ;                        ;
620    
621  text                  :  SP           { $$ = " ";      }  text                  :  SP           { $$ = " ";      }
# Line 624  text_escaped          :  SP Line 630  text_escaped          :  SP
630                        |  text_escaped string_escaped  { $$ = $1 + $2;  }                        |  text_escaped string_escaped  { $$ = $1 + $2;  }
631                        ;                        ;
632    
633  stringval             :  '\'' text '\''  { $$ = $2; }  string                :  char          { std::string s; s = $1; $$ = s; }
634                        |  '\"' text '\"'  { $$ = $2; }                        |  string char   { $$ = $1 + $2;                  }
635                        ;                        ;
636    
637  stringval_escaped     :  '\'' text_escaped '\''  { $$ = $2; }  string_escaped        :  char_base                   { std::string s; s = $1; $$ = s; }
638                        |  '\"' text_escaped '\"'  { $$ = $2; }                        |  escape_seq                  { std::string s; s = $1; $$ = s; }
639                          |  string_escaped char_base    { $$ = $1 + $2;                  }
640                          |  string_escaped escape_seq   { $$ = $1 + $2;                  }
641                          ;
642    
643    // full ASCII character set except space, quotation mark and apostrophe
644    char                  :  char_base
645                          |  '\\'  { $$ = '\\'; }
646                          |  '/'   { $$ = '/';  }
647                          ;
648    
649    // ASCII characters except space, quotation mark, apostrophe, backslash and slash
650    char_base             :  'A' { $$ = 'A'; } | 'B' { $$ = 'B'; } | 'C' { $$ = 'C'; } | 'D' { $$ = 'D'; } | 'E' { $$ = 'E'; } | 'F' { $$ = 'F'; } | 'G' { $$ = 'G'; } | 'H' { $$ = 'H'; } | 'I' { $$ = 'I'; } | 'J' { $$ = 'J'; } | 'K' { $$ = 'K'; } | 'L' { $$ = 'L'; } | 'M' { $$ = 'M'; } | 'N' { $$ = 'N'; } | 'O' { $$ = 'O'; } | 'P' { $$ = 'P'; } | 'Q' { $$ = 'Q'; } | 'R' { $$ = 'R'; } | 'S' { $$ = 'S'; } | 'T' { $$ = 'T'; } | 'U' { $$ = 'U'; } | 'V' { $$ = 'V'; } | 'W' { $$ = 'W'; } | 'X' { $$ = 'X'; } | 'Y' { $$ = 'Y'; } | 'Z' { $$ = 'Z'; }
651                          |  'a' { $$ = 'a'; } | 'b' { $$ = 'b'; } | 'c' { $$ = 'c'; } | 'd' { $$ = 'd'; } | 'e' { $$ = 'e'; } | 'f' { $$ = 'f'; } | 'g' { $$ = 'g'; } | 'h' { $$ = 'h'; } | 'i' { $$ = 'i'; } | 'j' { $$ = 'j'; } | 'k' { $$ = 'k'; } | 'l' { $$ = 'l'; } | 'm' { $$ = 'm'; } | 'n' { $$ = 'n'; } | 'o' { $$ = 'o'; } | 'p' { $$ = 'p'; } | 'q' { $$ = 'q'; } | 'r' { $$ = 'r'; } | 's' { $$ = 's'; } | 't' { $$ = 't'; } | 'u' { $$ = 'u'; } | 'v' { $$ = 'v'; } | 'w' { $$ = 'w'; } | 'x' { $$ = 'x'; } | 'y' { $$ = 'y'; } | 'z' { $$ = 'z'; }
652                          |  '0' { $$ = '0'; } | '1' { $$ = '1'; } | '2' { $$ = '2'; } | '3' { $$ = '3'; } | '4' { $$ = '4'; } | '5' { $$ = '5'; } | '6' { $$ = '6'; } | '7' { $$ = '7'; } | '8' { $$ = '8'; } | '9' { $$ = '9'; }
653                          |  '!' { $$ = '!'; } | '#' { $$ = '#'; } | '$' { $$ = '$'; } | '%' { $$ = '%'; } | '&' { $$ = '&'; } | '(' { $$ = '('; } | ')' { $$ = ')'; } | '*' { $$ = '*'; } | '+' { $$ = '+'; } | '-' { $$ = '-'; } | '.' { $$ = '.'; } | ',' { $$ = ','; }
654                          |  ':' { $$ = ':'; } | ';' { $$ = ';'; } | '<' { $$ = '<'; } | '=' { $$ = '='; } | '>' { $$ = '>'; } | '?' { $$ = '?'; } | '@' { $$ = '@'; }
655                          |  '[' { $$ = '['; } | ']' { $$ = ']'; } | '^' { $$ = '^'; } | '_' { $$ = '_'; }
656                          |  '{' { $$ = '{'; } | '|' { $$ = '|'; } | '}' { $$ = '}'; } | '~' { $$ = '~'; }
657                          |  EXT_ASCII_CHAR
658                        ;                        ;
659    
660  escape_seq            :  '\\' '\''  { $$ = '\''; }  escape_seq            :  '\\' '\''  { $$ = '\''; }
661                        |  '\\' '\"'  { $$ = '\"'; }                        |  '\\' '\"'  { $$ = '\"'; }
662                        |  '\\' '\\'  { $$ = '\\'; }                        |  '\\' '\\'  { $$ = '\\'; }
663                          |  '\\' '/'   { $$ = '/';  }
664                        |  '\\' 'n'   { $$ = '\n'; }                        |  '\\' 'n'   { $$ = '\n'; }
665                        |  '\\' 'r'   { $$ = '\r'; }                        |  '\\' 'r'   { $$ = '\r'; }
666                        |  '\\' 'f'   { $$ = '\f'; }                        |  '\\' 'f'   { $$ = '\f'; }
# Line 976  QUIT                  :  'Q''U''I''T' Line 1002  QUIT                  :  'Q''U''I''T'
1002   * Will be called when an error occured (usually syntax error).   * Will be called when an error occured (usually syntax error).
1003   */   */
1004  void yyerror(const char* s) {  void yyerror(const char* s) {
1005      dmsg(2,("LSCPParser: %s\n", s));      yyparse_param_t* param = GetCurrentYaccSession();
1006        String msg = s
1007            + (" (line:"   + ToString(param->iLine+1))
1008            + ( ",column:" + ToString(param->iColumn))
1009            + ")";
1010        dmsg(2,("LSCPParser: %s\n", msg.c_str()));
1011        sLastError = msg;
1012  }  }
1013    
1014  /**  /**
# Line 985  void yyerror(const char* s) { Line 1017  void yyerror(const char* s) {
1017  void restart(yyparse_param_t* pparam, int& yychar) {  void restart(yyparse_param_t* pparam, int& yychar) {
1018      bytes = 0;      bytes = 0;
1019      ptr   = 0;      ptr   = 0;
1020        sLastError = "";
1021  }  }

Legend:
Removed from v.1245  
changed lines
  Added in v.1332

  ViewVC Help
Powered by ViewVC