/[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 1695 by schoenebeck, Sat Feb 16 01:09:33 2008 UTC revision 2523 by schoenebeck, Sun Feb 23 19:10:36 2014 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 - 2008 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2014 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 34  Line 34 
34  #include "lscpparser.h"  #include "lscpparser.h"
35  #include "lscpserver.h"  #include "lscpserver.h"
36  #include "lscpevent.h"  #include "lscpevent.h"
37    #include "lscpsymbols.h"
38    #include <algorithm>
39    #include "lscp.h"
40    
41    namespace LinuxSampler {
42    
43  // to save us typing work in the rules action definitions  // to save us typing work in the rules action definitions
44  #define LSCPSERVER ((yyparse_param_t*) yyparse_param)->pServer  #define LSCPSERVER ((yyparse_param_t*) yyparse_param)->pServer
45  #define SESSION_PARAM ((yyparse_param_t*) yyparse_param)  #define SESSION_PARAM ((yyparse_param_t*) yyparse_param)
46  #define INCREMENT_LINE { SESSION_PARAM->iLine++; SESSION_PARAM->iColumn = 0; }  #define INCREMENT_LINE { SESSION_PARAM->iLine++; SESSION_PARAM->iColumn = 0; sParsed.clear(); }
47    
48  // clears input buffer  // clears input buffer
49  void restart(yyparse_param_t* pparam, int& yychar);  void restart(yyparse_param_t* pparam, int& yychar);
50  #define RESTART restart((yyparse_param_t*) YYPARSE_PARAM, yychar)  #define RESTART restart((yyparse_param_t*) YYPARSE_PARAM, yychar)
51    
 // we provide our own version of yyerror() so we don't have to link against the yacc library  
 void yyerror(const char* s);  
   
52  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
53  static int bytes = 0;  // current number of characters in the input buffer  static int bytes = 0;  // current number of characters in the input buffer
54  static int ptr   = 0;  // current position in the input buffer  static int ptr   = 0;  // current position in the input buffer
55  static String sLastError; // error message of the last error occured  static String sLastError; // error message of the last error occured
56    static String sParsed; ///< Characters of current line which have already been shifted (consumed/parsed) by the parser.
57    
58  // external reference to the function which actually reads from the socket  // external reference to the function which actually reads from the socket
59  extern int GetLSCPCommand( void *buf, int max_size);  extern int GetLSCPCommand( void *buf, int max_size);
# Line 64  inline bool isExtendedAsciiChar(const ch Line 67  inline bool isExtendedAsciiChar(const ch
67      return (c < 0);      return (c < 0);
68  }  }
69    
70    // returns true if the given character is between between a to z.
71    inline bool isLowerCaseAlphaChar(const char c) {
72        return c >= 'a' && c <= 'z';
73    }
74    
75    // converts the given (expected) lower case character to upper case
76    inline char alphaCharToUpperCase(const char c) {
77        return (c - 'a') + 'A';
78    }
79    
80  // custom scanner function which reads from the socket  // custom scanner function which reads from the socket
81  // (bison expects it to return the numerical ID of the next  // (bison expects it to return the numerical ID of the next
82  // "recognized token" from the input stream)  // "recognized token" from the input stream)
# Line 81  int yylex(YYSTYPE* yylval) { Line 94  int yylex(YYSTYPE* yylval) {
94      const char c = buf[ptr++];      const char c = buf[ptr++];
95      // increment current reading position (just for verbosity / messages)      // increment current reading position (just for verbosity / messages)
96      GetCurrentYaccSession()->iColumn++;      GetCurrentYaccSession()->iColumn++;
97        sParsed += c;
98      // we have to handle "normal" and "extended" ASCII characters separately      // we have to handle "normal" and "extended" ASCII characters separately
99      if (isExtendedAsciiChar(c)) {      if (isExtendedAsciiChar(c)) {
100          // workaround for characters with ASCII code higher than 127          // workaround for characters with ASCII code higher than 127
# Line 101  int octalsToNumber(char oct_digit0, char Line 115  int octalsToNumber(char oct_digit0, char
115      return atoi(d2)*8*8 + atoi(d1)*8 + atoi(d0);      return atoi(d2)*8*8 + atoi(d1)*8 + atoi(d0);
116  }  }
117    
118    }
119    
120    using namespace LinuxSampler;
121    
122    static std::set<String> yyExpectedSymbols();
123    
124    /**
125     * Will be called when an error occured (usually syntax error).
126     *
127     * We provide our own version of yyerror() so we a) don't have to link against
128     * the yacc library and b) can render more helpful syntax error messages.
129     */
130    void yyerror(void* x, const char* s) {
131        yyparse_param_t* param = GetCurrentYaccSession();
132    
133        // get the text part already parsed (of current line)
134        const bool bContainsLineFeed =
135            sParsed.find('\r') != std::string::npos ||
136            sParsed.find('\n') != std::string::npos;
137        // remove potential line feed characters
138        if (bContainsLineFeed) {
139            for (size_t p = sParsed.find('\r'); p != std::string::npos;
140                 p = sParsed.find('\r')) sParsed.erase(p);
141            for (size_t p = sParsed.find('\n'); p != std::string::npos;
142                 p = sParsed.find('\n')) sParsed.erase(p);
143        }
144    
145        // start assembling the error message with Bison's own message
146        String txt = s;
147    
148        // append exact position info of syntax error
149        txt += (" (line:"  + ToString(param->iLine+1)) +
150               (",column:" + ToString(param->iColumn)) + ")";
151    
152        // append the part of the lined that has already been parsed
153        txt += ". Context: \"" + sParsed;
154        if (txt.empty() || bContainsLineFeed)
155            txt += "^";
156        else
157            txt.insert(txt.size() - 1, "^");
158        txt += "...\"";
159    
160        // append the non-terminal symbols expected now/next
161        std::set<String> expectedSymbols = yyExpectedSymbols();
162        for (std::set<String>::const_iterator it = expectedSymbols.begin();
163             it != expectedSymbols.end(); ++it)
164        {
165            if (it == expectedSymbols.begin())
166                txt += " -> Should be: " + *it;
167            else
168                txt += " | " + *it;
169        }
170    
171        dmsg(2,("LSCPParser: %s\n", txt.c_str()));
172        sLastError = txt;
173    }
174    
175  %}  %}
176    
177  // reentrant parser  // reentrant parser
178  %pure_parser  %pure-parser
179    
180    %parse-param {void* yyparse_param}
181    
182    // After entering the yyparse() function, store references to the parser's
183    // state stack, so that we can create more helpful syntax error messages than
184    // Bison (2.x) could do.
185    %initial-action {
186        yyparse_param_t* p = (yyparse_param_t*) yyparse_param;
187        p->ppStackBottom = &yyss;
188        p->ppStackTop    = &yyssp;
189    }
190    
191  // tell bison to spit out verbose syntax error messages  // tell bison to spit out verbose syntax error messages
192  %error-verbose  %error-verbose
# Line 112  int octalsToNumber(char oct_digit0, char Line 194  int octalsToNumber(char oct_digit0, char
194  %token <Char> EXT_ASCII_CHAR  %token <Char> EXT_ASCII_CHAR
195    
196  %type <Char> char char_base alpha_char digit digit_oct digit_hex escape_seq escape_seq_octal escape_seq_hex  %type <Char> char char_base alpha_char digit digit_oct digit_hex escape_seq escape_seq_octal escape_seq_hex
197  %type <Dotnum> dotnum volume_value boolean  %type <Dotnum> real dotnum volume_value boolean control_value
198  %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 effect_index effect_instance effect_chain chain_pos input_control midi_input_channel_index midi_input_port_index midi_map midi_bank midi_prog midi_ctrl
199  %type <String> string string_escaped text text_escaped text_escaped_base stringval stringval_escaped digits param_val_list param_val query_val filename db_path 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 format_instruction  %type <String> string string_escaped text text_escaped text_escaped_base stringval stringval_escaped digits param_val_list param_val query_val filename module effect_system db_path map_name entry_name fx_send_name effect_name engine_name line statement command add_instruction create_instruction destroy_instruction get_instruction list_instruction load_instruction send_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 format_instruction append_instruction insert_instruction
200  %type <FillResponse> buffer_size_type  %type <FillResponse> buffer_size_type
201  %type <KeyValList> key_val_list query_val_list  %type <KeyValList> key_val_list query_val_list
202  %type <LoadMode> instr_load_mode  %type <LoadMode> instr_load_mode
# Line 136  int octalsToNumber(char oct_digit0, char Line 218  int octalsToNumber(char oct_digit0, char
218    
219  // GRAMMAR_BNF_BEGIN - do NOT delete or modify this line !!!  // GRAMMAR_BNF_BEGIN - do NOT delete or modify this line !!!
220    
221  input                 : line LF  input                 :  line   { INCREMENT_LINE; if (!$1.empty()) LSCPSERVER->AnswerClient($1); return LSCP_DONE; }
222                        | line CR LF                        |  error  { INCREMENT_LINE; LSCPSERVER->AnswerClient("ERR:0:" + sLastError + "\r\n"); RESTART; return LSCP_SYNTAX_ERROR; }
223                        ;                        ;
224    
225  line                  :  /* epsilon (empty line ignored) */ { INCREMENT_LINE; return LSCP_DONE; }  line                  :  statement LF     { $$ = $1; }
226                        |  comment  { INCREMENT_LINE; return LSCP_DONE; }                        |  statement CR LF  { $$ = $1; }
227                        |  command  { INCREMENT_LINE; LSCPSERVER->AnswerClient($1); return LSCP_DONE; }                        ;
228                        |  error    { INCREMENT_LINE; LSCPSERVER->AnswerClient("ERR:0:" + sLastError + "\r\n"); RESTART; return LSCP_SYNTAX_ERROR; }  
229    statement             :  /* epsilon (empty statement/line ignored) */  { $$ = ""; }
230                          |  comment  { $$ = ""; }
231                          |  command
232                        ;                        ;
233    
234  comment               :  '#'  comment               :  '#'
# Line 172  command               :  ADD SP add_inst Line 257  command               :  ADD SP add_inst
257                        |  COPY SP copy_instruction              { $$ = $3;                                                }                        |  COPY SP copy_instruction              { $$ = $3;                                                }
258                        |  EDIT SP edit_instruction              { $$ = $3;                                                }                        |  EDIT SP edit_instruction              { $$ = $3;                                                }
259                        |  FORMAT SP format_instruction          { $$ = $3;                                                }                        |  FORMAT SP format_instruction          { $$ = $3;                                                }
260                          |  SEND SP send_instruction              { $$ = $3;                                                }
261                          |  APPEND SP append_instruction          { $$ = $3;                                                }
262                          |  INSERT SP insert_instruction          { $$ = $3;                                                }
263                        |  RESET                                 { $$ = LSCPSERVER->ResetSampler();                        }                        |  RESET                                 { $$ = LSCPSERVER->ResetSampler();                        }
264                        |  QUIT                                  { LSCPSERVER->AnswerClient("Bye!\r\n"); return LSCP_QUIT; }                        |  QUIT                                  { LSCPSERVER->AnswerClient("Bye!\r\n"); return LSCP_QUIT; }
265                        ;                        ;
266    
267  add_instruction       :  CHANNEL                               { $$ = LSCPSERVER->AddChannel();                  }  add_instruction       :  CHANNEL                               { $$ = LSCPSERVER->AddChannel();                  }
268                          |  CHANNEL SP MIDI_INPUT SP sampler_channel SP device_index                           { $$ = LSCPSERVER->AddChannelMidiInput($5,$7);    }
269                          |  CHANNEL SP MIDI_INPUT SP sampler_channel SP device_index SP midi_input_port_index  { $$ = LSCPSERVER->AddChannelMidiInput($5,$7,$9); }
270                        |  DB_INSTRUMENT_DIRECTORY SP db_path    { $$ = LSCPSERVER->AddDbInstrumentDirectory($3);  }                        |  DB_INSTRUMENT_DIRECTORY SP db_path    { $$ = LSCPSERVER->AddDbInstrumentDirectory($3);  }
271                        |  DB_INSTRUMENTS SP NON_MODAL SP scan_mode SP db_path SP filename         { $$ = LSCPSERVER->AddDbInstruments($5,$7,$9, true);  }                        |  DB_INSTRUMENTS SP NON_MODAL SP scan_mode SP db_path SP filename                        { $$ = LSCPSERVER->AddDbInstruments($5,$7,$9, true);        }
272                        |  DB_INSTRUMENTS SP scan_mode SP db_path SP filename                      { $$ = LSCPSERVER->AddDbInstruments($3,$5,$7);        }                        |  DB_INSTRUMENTS SP NON_MODAL SP scan_mode SP FILE_AS_DIR SP db_path SP filename         { $$ = LSCPSERVER->AddDbInstruments($5,$9,$11, true, true); }
273                        |  DB_INSTRUMENTS SP NON_MODAL SP db_path SP filename                      { $$ = LSCPSERVER->AddDbInstruments($5,$7, -1, true); }                        |  DB_INSTRUMENTS SP scan_mode SP db_path SP filename                                     { $$ = LSCPSERVER->AddDbInstruments($3,$5,$7);              }
274                        |  DB_INSTRUMENTS SP NON_MODAL SP db_path SP filename SP instrument_index  { $$ = LSCPSERVER->AddDbInstruments($5,$7,$9, true);  }                        |  DB_INSTRUMENTS SP scan_mode SP FILE_AS_DIR SP db_path SP filename                      { $$ = LSCPSERVER->AddDbInstruments($3,$7,$9, false, true); }
275                        |  DB_INSTRUMENTS SP db_path SP filename                                   { $$ = LSCPSERVER->AddDbInstruments($3,$5);           }                        |  DB_INSTRUMENTS SP NON_MODAL SP db_path SP filename                                     { $$ = LSCPSERVER->AddDbInstruments($5,$7, -1, true);       }
276                        |  DB_INSTRUMENTS SP db_path SP filename SP instrument_index               { $$ = LSCPSERVER->AddDbInstruments($3,$5,$7);        }                        |  DB_INSTRUMENTS SP NON_MODAL SP db_path SP filename SP instrument_index                 { $$ = LSCPSERVER->AddDbInstruments($5,$7,$9, true);        }
277                          |  DB_INSTRUMENTS SP db_path SP filename                                                  { $$ = LSCPSERVER->AddDbInstruments($3,$5);                 }
278                          |  DB_INSTRUMENTS SP db_path SP filename SP instrument_index                              { $$ = LSCPSERVER->AddDbInstruments($3,$5,$7);              }
279                        |  MIDI_INSTRUMENT_MAP                   { $$ = LSCPSERVER->AddMidiInstrumentMap();                }                        |  MIDI_INSTRUMENT_MAP                   { $$ = LSCPSERVER->AddMidiInstrumentMap();                }
280                        |  MIDI_INSTRUMENT_MAP SP map_name       { $$ = LSCPSERVER->AddMidiInstrumentMap($3);              }                        |  MIDI_INSTRUMENT_MAP SP map_name       { $$ = LSCPSERVER->AddMidiInstrumentMap($3);              }
281                          |  SEND_EFFECT_CHAIN SP device_index     { $$ = LSCPSERVER->AddSendEffectChain($3);                }
282                        ;                        ;
283    
284  subscribe_event       :  AUDIO_OUTPUT_DEVICE_COUNT             { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_audio_device_count);   }  subscribe_event       :  AUDIO_OUTPUT_DEVICE_COUNT             { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_audio_device_count);   }
# Line 214  subscribe_event       :  AUDIO_OUTPUT_DE Line 307  subscribe_event       :  AUDIO_OUTPUT_DE
307                        |  TOTAL_STREAM_COUNT                    { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_total_stream_count);   }                        |  TOTAL_STREAM_COUNT                    { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_total_stream_count);   }
308                        |  TOTAL_VOICE_COUNT                     { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_total_voice_count);    }                        |  TOTAL_VOICE_COUNT                     { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_total_voice_count);    }
309                        |  GLOBAL_INFO                           { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_global_info);          }                        |  GLOBAL_INFO                           { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_global_info);          }
310                          |  EFFECT_INSTANCE_COUNT                 { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_fx_instance_count);    }
311                          |  EFFECT_INSTANCE_INFO                  { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_fx_instance_info);     }
312                          |  SEND_EFFECT_CHAIN_COUNT               { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_send_fx_chain_count);  }
313                          |  SEND_EFFECT_CHAIN_INFO                { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_send_fx_chain_info);   }
314                        ;                        ;
315    
316  unsubscribe_event     :  AUDIO_OUTPUT_DEVICE_COUNT             { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_audio_device_count);   }  unsubscribe_event     :  AUDIO_OUTPUT_DEVICE_COUNT             { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_audio_device_count);   }
# Line 242  unsubscribe_event     :  AUDIO_OUTPUT_DE Line 339  unsubscribe_event     :  AUDIO_OUTPUT_DE
339                        |  TOTAL_STREAM_COUNT                    { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_total_stream_count);   }                        |  TOTAL_STREAM_COUNT                    { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_total_stream_count);   }
340                        |  TOTAL_VOICE_COUNT                     { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_total_voice_count);    }                        |  TOTAL_VOICE_COUNT                     { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_total_voice_count);    }
341                        |  GLOBAL_INFO                           { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_global_info);          }                        |  GLOBAL_INFO                           { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_global_info);          }
342                          |  EFFECT_INSTANCE_COUNT                 { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_fx_instance_count);    }
343                          |  EFFECT_INSTANCE_INFO                  { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_fx_instance_info);     }
344                          |  SEND_EFFECT_CHAIN_COUNT               { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_send_fx_chain_count);  }
345                          |  SEND_EFFECT_CHAIN_INFO                { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_send_fx_chain_info);   }
346                        ;                        ;
347    
348  map_instruction       :  MIDI_INSTRUMENT SP modal_arg midi_map SP midi_bank SP midi_prog SP engine_name SP filename SP instrument_index SP volume_value { $$ = LSCPSERVER->AddOrReplaceMIDIInstrumentMapping($4,$6,$8,$10,$12,$14,$16,MidiInstrumentMapper::DONTCARE,"",$3); }  map_instruction       :  MIDI_INSTRUMENT SP modal_arg midi_map SP midi_bank SP midi_prog SP engine_name SP filename SP instrument_index SP volume_value { $$ = LSCPSERVER->AddOrReplaceMIDIInstrumentMapping($4,$6,$8,$10,$12,$14,$16,MidiInstrumentMapper::DONTCARE,"",$3); }
# Line 254  unmap_instruction     :  MIDI_INSTRUMENT Line 355  unmap_instruction     :  MIDI_INSTRUMENT
355                        ;                        ;
356    
357  remove_instruction    :  CHANNEL SP sampler_channel                   { $$ = LSCPSERVER->RemoveChannel($3);                      }  remove_instruction    :  CHANNEL SP sampler_channel                   { $$ = LSCPSERVER->RemoveChannel($3);                      }
358                          |  CHANNEL SP MIDI_INPUT SP sampler_channel                                           { $$ = LSCPSERVER->RemoveChannelMidiInput($5);       }
359                          |  CHANNEL SP MIDI_INPUT SP sampler_channel SP device_index                           { $$ = LSCPSERVER->RemoveChannelMidiInput($5,$7);    }
360                          |  CHANNEL SP MIDI_INPUT SP sampler_channel SP device_index SP midi_input_port_index  { $$ = LSCPSERVER->RemoveChannelMidiInput($5,$7,$9); }
361                        |  MIDI_INSTRUMENT_MAP SP midi_map              { $$ = LSCPSERVER->RemoveMidiInstrumentMap($3);            }                        |  MIDI_INSTRUMENT_MAP SP midi_map              { $$ = LSCPSERVER->RemoveMidiInstrumentMap($3);            }
362                        |  MIDI_INSTRUMENT_MAP SP ALL                   { $$ = LSCPSERVER->RemoveAllMidiInstrumentMaps();          }                        |  MIDI_INSTRUMENT_MAP SP ALL                   { $$ = LSCPSERVER->RemoveAllMidiInstrumentMaps();          }
363                          |  SEND_EFFECT_CHAIN SP device_index SP effect_chain  { $$ = LSCPSERVER->RemoveSendEffectChain($3,$5);     }
364                          |  SEND_EFFECT_CHAIN SP EFFECT SP device_index SP effect_chain SP chain_pos  { $$ = LSCPSERVER->RemoveSendEffectChainEffect($5,$7,$9); }
365                          |  FX_SEND SP EFFECT SP sampler_channel SP fx_send_id  { $$ = LSCPSERVER->SetFxSendEffect($5,$7,-1,-1);    }
366                        |  DB_INSTRUMENT_DIRECTORY SP FORCE SP db_path  { $$ = LSCPSERVER->RemoveDbInstrumentDirectory($5, true);  }                        |  DB_INSTRUMENT_DIRECTORY SP FORCE SP db_path  { $$ = LSCPSERVER->RemoveDbInstrumentDirectory($5, true);  }
367                        |  DB_INSTRUMENT_DIRECTORY SP db_path           { $$ = LSCPSERVER->RemoveDbInstrumentDirectory($3);        }                        |  DB_INSTRUMENT_DIRECTORY SP db_path           { $$ = LSCPSERVER->RemoveDbInstrumentDirectory($3);        }
368                        |  DB_INSTRUMENT SP db_path                     { $$ = LSCPSERVER->RemoveDbInstrument($3);                 }                        |  DB_INSTRUMENT SP db_path                     { $$ = LSCPSERVER->RemoveDbInstrument($3);                 }
369                        ;                        ;
370    
371  get_instruction       :  AVAILABLE_ENGINES                                                          { $$ = LSCPSERVER->GetAvailableEngines();                          }  get_instruction       :  AVAILABLE_ENGINES                                                          { $$ = LSCPSERVER->GetAvailableEngines();                          }
372                          |  AVAILABLE_EFFECTS                                                          { $$ = LSCPSERVER->GetAvailableEffects();                          }
373                          |  EFFECT_INSTANCES                                                           { $$ = LSCPSERVER->GetEffectInstances();                           }
374                          |  EFFECT SP INFO SP effect_index                                             { $$ = LSCPSERVER->GetEffectInfo($5);                              }
375                          |  EFFECT_INSTANCE SP INFO SP effect_instance                                 { $$ = LSCPSERVER->GetEffectInstanceInfo($5);                      }
376                          |  EFFECT_INSTANCE_INPUT_CONTROL SP INFO SP effect_instance SP input_control  { $$ = LSCPSERVER->GetEffectInstanceInputControlInfo($5,$7);       }
377                          |  SEND_EFFECT_CHAINS SP device_index                                         { $$ = LSCPSERVER->GetSendEffectChains($3);                        }
378                          |  SEND_EFFECT_CHAIN SP INFO SP device_index SP effect_chain                  { $$ = LSCPSERVER->GetSendEffectChainInfo($5,$7);                  }
379                        |  AVAILABLE_MIDI_INPUT_DRIVERS                                               { $$ = LSCPSERVER->GetAvailableMidiInputDrivers();                 }                        |  AVAILABLE_MIDI_INPUT_DRIVERS                                               { $$ = LSCPSERVER->GetAvailableMidiInputDrivers();                 }
380                        |  MIDI_INPUT_DRIVER SP INFO SP string                                        { $$ = LSCPSERVER->GetMidiInputDriverInfo($5);                     }                        |  MIDI_INPUT_DRIVER SP INFO SP string                                        { $$ = LSCPSERVER->GetMidiInputDriverInfo($5);                     }
381                        |  MIDI_INPUT_DRIVER_PARAMETER SP INFO SP string SP string                    { $$ = LSCPSERVER->GetMidiInputDriverParameterInfo($5, $7);        }                        |  MIDI_INPUT_DRIVER_PARAMETER SP INFO SP string SP string                    { $$ = LSCPSERVER->GetMidiInputDriverParameterInfo($5, $7);        }
# Line 303  get_instruction       :  AVAILABLE_ENGIN Line 417  get_instruction       :  AVAILABLE_ENGIN
417                        |  DB_INSTRUMENT SP INFO SP db_path                                           { $$ = LSCPSERVER->GetDbInstrumentInfo($5);                        }                        |  DB_INSTRUMENT SP INFO SP db_path                                           { $$ = LSCPSERVER->GetDbInstrumentInfo($5);                        }
418                        |  DB_INSTRUMENTS_JOB SP INFO SP number                                       { $$ = LSCPSERVER->GetDbInstrumentsJobInfo($5);                    }                        |  DB_INSTRUMENTS_JOB SP INFO SP number                                       { $$ = LSCPSERVER->GetDbInstrumentsJobInfo($5);                    }
419                        |  VOLUME                                                                     { $$ = LSCPSERVER->GetGlobalVolume();                              }                        |  VOLUME                                                                     { $$ = LSCPSERVER->GetGlobalVolume();                              }
420                          |  VOICES                                                                     { $$ = LSCPSERVER->GetGlobalMaxVoices();                           }
421                          |  STREAMS                                                                    { $$ = LSCPSERVER->GetGlobalMaxStreams();                          }
422                        |  FILE SP INSTRUMENTS SP filename                                            { $$ = LSCPSERVER->GetFileInstruments($5);                         }                        |  FILE SP INSTRUMENTS SP filename                                            { $$ = LSCPSERVER->GetFileInstruments($5);                         }
423                        |  FILE SP INSTRUMENT SP INFO SP filename SP instrument_index                 { $$ = LSCPSERVER->GetFileInstrumentInfo($7,$9);                   }                        |  FILE SP INSTRUMENT SP INFO SP filename SP instrument_index                 { $$ = LSCPSERVER->GetFileInstrumentInfo($7,$9);                   }
424                        ;                        ;
# Line 312  set_instruction       :  AUDIO_OUTPUT_DE Line 428  set_instruction       :  AUDIO_OUTPUT_DE
428                        |  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);        }
429                        |  MIDI_INPUT_PORT_PARAMETER SP number SP number SP string '=' NONE                 { $$ = LSCPSERVER->SetMidiInputPortParameter($3, $5, $7, "");      }                        |  MIDI_INPUT_PORT_PARAMETER SP number SP number SP string '=' NONE                 { $$ = LSCPSERVER->SetMidiInputPortParameter($3, $5, $7, "");      }
430                        |  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);      }
431                          |  EFFECT_INSTANCE_INPUT_CONTROL SP VALUE SP effect_instance SP input_control SP control_value  { $$ = LSCPSERVER->SetEffectInstanceInputControlValue($5, $7, $9); }
432                        |  CHANNEL SP set_chan_instruction                                                  { $$ = $3;                                                         }                        |  CHANNEL SP set_chan_instruction                                                  { $$ = $3;                                                         }
433                        |  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);               }
434                        |  FX_SEND SP NAME SP sampler_channel SP fx_send_id SP fx_send_name                 { $$ = LSCPSERVER->SetFxSendName($5,$7,$9);                        }                        |  FX_SEND SP NAME SP sampler_channel SP fx_send_id SP fx_send_name                 { $$ = LSCPSERVER->SetFxSendName($5,$7,$9);                        }
435                        |  FX_SEND SP AUDIO_OUTPUT_CHANNEL SP sampler_channel SP fx_send_id SP audio_channel_index SP audio_channel_index  { $$ = LSCPSERVER->SetFxSendAudioOutputChannel($5,$7,$9,$11); }                        |  FX_SEND SP AUDIO_OUTPUT_CHANNEL SP sampler_channel SP fx_send_id SP audio_channel_index SP audio_channel_index  { $$ = LSCPSERVER->SetFxSendAudioOutputChannel($5,$7,$9,$11); }
436                        |  FX_SEND SP MIDI_CONTROLLER SP sampler_channel SP fx_send_id SP midi_ctrl         { $$ = LSCPSERVER->SetFxSendMidiController($5,$7,$9);              }                        |  FX_SEND SP MIDI_CONTROLLER SP sampler_channel SP fx_send_id SP midi_ctrl         { $$ = LSCPSERVER->SetFxSendMidiController($5,$7,$9);              }
437                        |  FX_SEND SP LEVEL SP sampler_channel SP fx_send_id SP volume_value                { $$ = LSCPSERVER->SetFxSendLevel($5,$7,$9);                       }                        |  FX_SEND SP LEVEL SP sampler_channel SP fx_send_id SP volume_value                { $$ = LSCPSERVER->SetFxSendLevel($5,$7,$9);                       }
438                          |  FX_SEND SP EFFECT SP sampler_channel SP fx_send_id SP effect_chain SP chain_pos  { $$ = LSCPSERVER->SetFxSendEffect($5,$7,$9,$11);                  }
439                        |  DB_INSTRUMENT_DIRECTORY SP NAME SP db_path SP stringval_escaped                  { $$ = LSCPSERVER->SetDbInstrumentDirectoryName($5,$7);            }                        |  DB_INSTRUMENT_DIRECTORY SP NAME SP db_path SP stringval_escaped                  { $$ = LSCPSERVER->SetDbInstrumentDirectoryName($5,$7);            }
440                        |  DB_INSTRUMENT_DIRECTORY SP DESCRIPTION SP db_path SP stringval_escaped           { $$ = LSCPSERVER->SetDbInstrumentDirectoryDescription($5,$7);     }                        |  DB_INSTRUMENT_DIRECTORY SP DESCRIPTION SP db_path SP stringval_escaped           { $$ = LSCPSERVER->SetDbInstrumentDirectoryDescription($5,$7);     }
441                        |  DB_INSTRUMENT SP NAME SP db_path SP stringval_escaped                            { $$ = LSCPSERVER->SetDbInstrumentName($5,$7);                     }                        |  DB_INSTRUMENT SP NAME SP db_path SP stringval_escaped                            { $$ = LSCPSERVER->SetDbInstrumentName($5,$7);                     }
442                        |  DB_INSTRUMENT SP DESCRIPTION SP db_path SP stringval_escaped                     { $$ = LSCPSERVER->SetDbInstrumentDescription($5,$7);              }                        |  DB_INSTRUMENT SP DESCRIPTION SP db_path SP stringval_escaped                     { $$ = LSCPSERVER->SetDbInstrumentDescription($5,$7);              }
443                          |  DB_INSTRUMENT SP FILE_PATH SP filename SP filename                               { $$ = LSCPSERVER->SetDbInstrumentFilePath($5,$7);                 }
444                        |  ECHO SP boolean                                                                  { $$ = LSCPSERVER->SetEcho((yyparse_param_t*) yyparse_param, $3);  }                        |  ECHO SP boolean                                                                  { $$ = LSCPSERVER->SetEcho((yyparse_param_t*) yyparse_param, $3);  }
445                          |  SHELL SP INTERACT SP boolean                                                     { $$ = LSCPSERVER->SetShellInteract((yyparse_param_t*) yyparse_param, $5); }
446                          |  SHELL SP AUTO_CORRECT SP boolean                                                 { $$ = LSCPSERVER->SetShellAutoCorrect((yyparse_param_t*) yyparse_param, $5); }
447                        |  VOLUME SP volume_value                                                           { $$ = LSCPSERVER->SetGlobalVolume($3);                            }                        |  VOLUME SP volume_value                                                           { $$ = LSCPSERVER->SetGlobalVolume($3);                            }
448                          |  VOICES SP number                                                                 { $$ = LSCPSERVER->SetGlobalMaxVoices($3);                         }
449                          |  STREAMS SP number                                                                { $$ = LSCPSERVER->SetGlobalMaxStreams($3);                        }
450                        ;                        ;
451    
452  create_instruction    :  AUDIO_OUTPUT_DEVICE SP string SP key_val_list  { $$ = LSCPSERVER->CreateAudioOutputDevice($3,$5); }  create_instruction    :  AUDIO_OUTPUT_DEVICE SP string SP key_val_list  { $$ = LSCPSERVER->CreateAudioOutputDevice($3,$5); }
# Line 332  create_instruction    :  AUDIO_OUTPUT_DE Line 455  create_instruction    :  AUDIO_OUTPUT_DE
455                        |  MIDI_INPUT_DEVICE SP string                    { $$ = LSCPSERVER->CreateMidiInputDevice($3);      }                        |  MIDI_INPUT_DEVICE SP string                    { $$ = LSCPSERVER->CreateMidiInputDevice($3);      }
456                        |  FX_SEND SP sampler_channel SP midi_ctrl        { $$ = LSCPSERVER->CreateFxSend($3,$5);            }                        |  FX_SEND SP sampler_channel SP midi_ctrl        { $$ = LSCPSERVER->CreateFxSend($3,$5);            }
457                        |  FX_SEND SP sampler_channel SP midi_ctrl SP fx_send_name  { $$ = LSCPSERVER->CreateFxSend($3,$5,$7); }                        |  FX_SEND SP sampler_channel SP midi_ctrl SP fx_send_name  { $$ = LSCPSERVER->CreateFxSend($3,$5,$7); }
458                          |  EFFECT_INSTANCE SP effect_index                { $$ = LSCPSERVER->CreateEffectInstance($3);       }
459                          |  EFFECT_INSTANCE SP effect_system SP module SP effect_name  { $$ = LSCPSERVER->CreateEffectInstance($3,$5,$7); }
460                        ;                        ;
461    
462  reset_instruction     :  CHANNEL SP sampler_channel  { $$ = LSCPSERVER->ResetChannel($3); }  reset_instruction     :  CHANNEL SP sampler_channel  { $$ = LSCPSERVER->ResetChannel($3); }
# Line 345  find_instruction      :  DB_INSTRUMENTS Line 470  find_instruction      :  DB_INSTRUMENTS
470                        |  DB_INSTRUMENTS SP db_path SP query_val_list                               { $$ = LSCPSERVER->FindDbInstruments($3,$5, true);            }                        |  DB_INSTRUMENTS SP db_path SP query_val_list                               { $$ = LSCPSERVER->FindDbInstruments($3,$5, true);            }
471                        |  DB_INSTRUMENT_DIRECTORIES SP NON_RECURSIVE SP db_path SP query_val_list   { $$ = LSCPSERVER->FindDbInstrumentDirectories($5,$7, false); }                        |  DB_INSTRUMENT_DIRECTORIES SP NON_RECURSIVE SP db_path SP query_val_list   { $$ = LSCPSERVER->FindDbInstrumentDirectories($5,$7, false); }
472                        |  DB_INSTRUMENT_DIRECTORIES SP db_path SP query_val_list                    { $$ = LSCPSERVER->FindDbInstrumentDirectories($3,$5, true);  }                        |  DB_INSTRUMENT_DIRECTORIES SP db_path SP query_val_list                    { $$ = LSCPSERVER->FindDbInstrumentDirectories($3,$5, true);  }
473                          |  LOST SP DB_INSTRUMENT_FILES                                               { $$ = LSCPSERVER->FindLostDbInstrumentFiles();                 }
474                        ;                        ;
475    
476  move_instruction      :  DB_INSTRUMENT_DIRECTORY SP db_path SP db_path    { $$ = LSCPSERVER->MoveDbInstrumentDirectory($3,$5); }  move_instruction      :  DB_INSTRUMENT_DIRECTORY SP db_path SP db_path    { $$ = LSCPSERVER->MoveDbInstrumentDirectory($3,$5); }
# Line 358  copy_instruction      :  DB_INSTRUMENT_D Line 484  copy_instruction      :  DB_INSTRUMENT_D
484  destroy_instruction   :  AUDIO_OUTPUT_DEVICE SP number  { $$ = LSCPSERVER->DestroyAudioOutputDevice($3); }  destroy_instruction   :  AUDIO_OUTPUT_DEVICE SP number  { $$ = LSCPSERVER->DestroyAudioOutputDevice($3); }
485                        |  MIDI_INPUT_DEVICE SP number    { $$ = LSCPSERVER->DestroyMidiInputDevice($3);   }                        |  MIDI_INPUT_DEVICE SP number    { $$ = LSCPSERVER->DestroyMidiInputDevice($3);   }
486                        |  FX_SEND SP sampler_channel SP fx_send_id  { $$ = LSCPSERVER->DestroyFxSend($3,$5); }                        |  FX_SEND SP sampler_channel SP fx_send_id  { $$ = LSCPSERVER->DestroyFxSend($3,$5); }
487                          |  EFFECT_INSTANCE SP number      { $$ = LSCPSERVER->DestroyEffectInstance($3);    }
488                        ;                        ;
489    
490  load_instruction      :  INSTRUMENT SP load_instr_args  { $$ = $3; }  load_instruction      :  INSTRUMENT SP load_instr_args  { $$ = $3; }
491                        |  ENGINE SP load_engine_args     { $$ = $3; }                        |  ENGINE SP load_engine_args     { $$ = $3; }
492                        ;                        ;
493    
494    append_instruction    :  SEND_EFFECT_CHAIN SP EFFECT SP device_index SP effect_chain SP effect_instance  { $$ = LSCPSERVER->AppendSendEffectChainEffect($5,$7,$9); }
495                          ;
496    
497    insert_instruction    :  SEND_EFFECT_CHAIN SP EFFECT SP device_index SP effect_chain SP chain_pos SP effect_instance  { $$ = LSCPSERVER->InsertSendEffectChainEffect($5,$7,$9,$11); }
498                          ;
499    
500  set_chan_instruction  :  AUDIO_OUTPUT_DEVICE SP sampler_channel SP device_index                                              { $$ = LSCPSERVER->SetAudioOutputDevice($5, $3);      }  set_chan_instruction  :  AUDIO_OUTPUT_DEVICE SP sampler_channel SP device_index                                              { $$ = LSCPSERVER->SetAudioOutputDevice($5, $3);      }
501                        |  AUDIO_OUTPUT_CHANNEL SP sampler_channel SP audio_channel_index SP audio_channel_index               { $$ = LSCPSERVER->SetAudioOutputChannel($5, $7, $3); }                        |  AUDIO_OUTPUT_CHANNEL SP sampler_channel SP audio_channel_index SP audio_channel_index               { $$ = LSCPSERVER->SetAudioOutputChannel($5, $7, $3); }
502                        |  AUDIO_OUTPUT_TYPE SP sampler_channel SP audio_output_type_name                                      { $$ = LSCPSERVER->SetAudioOutputType($5, $3);        }                        |  AUDIO_OUTPUT_TYPE SP sampler_channel SP audio_output_type_name                                      { $$ = LSCPSERVER->SetAudioOutputType($5, $3);        }
# Line 401  buffer_size_type      :  BYTES       { $ Line 534  buffer_size_type      :  BYTES       { $
534  list_instruction      :  AUDIO_OUTPUT_DEVICES                               { $$ = LSCPSERVER->GetAudioOutputDevices();              }  list_instruction      :  AUDIO_OUTPUT_DEVICES                               { $$ = LSCPSERVER->GetAudioOutputDevices();              }
535                        |  MIDI_INPUT_DEVICES                                 { $$ = LSCPSERVER->GetMidiInputDevices();                }                        |  MIDI_INPUT_DEVICES                                 { $$ = LSCPSERVER->GetMidiInputDevices();                }
536                        |  CHANNELS                                           { $$ = LSCPSERVER->ListChannels();                       }                        |  CHANNELS                                           { $$ = LSCPSERVER->ListChannels();                       }
537                          |  CHANNEL SP MIDI_INPUTS SP sampler_channel          { $$ = LSCPSERVER->ListChannelMidiInputs($5);            }
538                        |  AVAILABLE_ENGINES                                  { $$ = LSCPSERVER->ListAvailableEngines();               }                        |  AVAILABLE_ENGINES                                  { $$ = LSCPSERVER->ListAvailableEngines();               }
539                          |  AVAILABLE_EFFECTS                                  { $$ = LSCPSERVER->ListAvailableEffects();               }
540                          |  EFFECT_INSTANCES                                   { $$ = LSCPSERVER->ListEffectInstances();                }
541                          |  SEND_EFFECT_CHAINS SP number                       { $$ = LSCPSERVER->ListSendEffectChains($3);             }
542                        |  AVAILABLE_MIDI_INPUT_DRIVERS                       { $$ = LSCPSERVER->ListAvailableMidiInputDrivers();      }                        |  AVAILABLE_MIDI_INPUT_DRIVERS                       { $$ = LSCPSERVER->ListAvailableMidiInputDrivers();      }
543                        |  AVAILABLE_AUDIO_OUTPUT_DRIVERS                     { $$ = LSCPSERVER->ListAvailableAudioOutputDrivers();    }                        |  AVAILABLE_AUDIO_OUTPUT_DRIVERS                     { $$ = LSCPSERVER->ListAvailableAudioOutputDrivers();    }
544                        |  MIDI_INSTRUMENTS SP midi_map                       { $$ = LSCPSERVER->ListMidiInstrumentMappings($3);       }                        |  MIDI_INSTRUMENTS SP midi_map                       { $$ = LSCPSERVER->ListMidiInstrumentMappings($3);       }
# Line 415  list_instruction      :  AUDIO_OUTPUT_DE Line 552  list_instruction      :  AUDIO_OUTPUT_DE
552                        |  FILE SP INSTRUMENTS SP filename                    { $$ = LSCPSERVER->ListFileInstruments($5);              }                        |  FILE SP INSTRUMENTS SP filename                    { $$ = LSCPSERVER->ListFileInstruments($5);              }
553                        ;                        ;
554    
555    send_instruction      :  CHANNEL SP MIDI_DATA SP string SP sampler_channel SP number SP number  { $$ = LSCPSERVER->SendChannelMidiData($5, $7, $9, $11); }
556                          ;
557    
558  load_instr_args       :  filename SP instrument_index SP sampler_channel               { $$ = LSCPSERVER->LoadInstrument($1, $3, $5);       }  load_instr_args       :  filename SP instrument_index SP sampler_channel               { $$ = LSCPSERVER->LoadInstrument($1, $3, $5);       }
559                        |  NON_MODAL SP filename SP instrument_index SP sampler_channel  { $$ = LSCPSERVER->LoadInstrument($3, $5, $7, true); }                        |  NON_MODAL SP filename SP instrument_index SP sampler_channel  { $$ = LSCPSERVER->LoadInstrument($3, $5, $7, true); }
560                        ;                        ;
# Line 427  instr_load_mode       :  ON_DEMAND Line 567  instr_load_mode       :  ON_DEMAND
567                        |  PERSISTENT      { $$ = MidiInstrumentMapper::PERSISTENT;     }                        |  PERSISTENT      { $$ = MidiInstrumentMapper::PERSISTENT;     }
568                        ;                        ;
569    
570    effect_instance           : number
571                              ;
572    
573  device_index              :  number  device_index              :  number
574                            ;                            ;
575    
# Line 462  volume_value              :  dotnum Line 605  volume_value              :  dotnum
605                            |  number  { $$ = $1; }                            |  number  { $$ = $1; }
606                            ;                            ;
607    
608    control_value             :  real
609                              ;
610    
611  sampler_channel           :  number  sampler_channel           :  number
612                            ;                            ;
613    
# Line 496  entry_name                :  stringval_e Line 642  entry_name                :  stringval_e
642  fx_send_name              :  stringval_escaped  fx_send_name              :  stringval_escaped
643                            ;                            ;
644    
645    effect_name               :  stringval_escaped
646                              ;
647    
648    effect_index              :  number
649                              ;
650    
651    effect_chain              :  number
652                              ;
653    
654    chain_pos                 :  number
655                              ;
656    
657    input_control             :  number
658                              ;
659    
660  param_val_list            :  param_val  param_val_list            :  param_val
661                            |  param_val_list','param_val  { $$ = $1 + "," + $3; }                            |  param_val_list','param_val  { $$ = $1 + "," + $3; }
662                            ;                            ;
# Line 504  param_val_list            :  param_val Line 665  param_val_list            :  param_val
665  param_val                 :  string            { $$ = "\'" + $1 + "\'"; }  param_val                 :  string            { $$ = "\'" + $1 + "\'"; }
666                            |  stringval         { $$ = "\'" + $1 + "\'"; }                            |  stringval         { $$ = "\'" + $1 + "\'"; }
667                            |  number            { std::stringstream ss; ss << "\'" << $1 << "\'"; $$ = ss.str(); }                            |  number            { std::stringstream ss; ss << "\'" << $1 << "\'"; $$ = ss.str(); }
668                            |  dotnum            { std::stringstream ss; ss << "\'" << $1 << "\'"; $$ = ss.str(); }                            |  dotnum            { std::stringstream ss; ss << "\'" << $1 << "\'"; $$ = ss.str(); } //TODO: maybe better using 'real' instead of 'number' and 'dotnum' rules
669                            ;                            ;
670    
671  query_val_list            :  string '=' query_val                    { $$[$1] = $3;          }  query_val_list            :  string '=' query_val                    { $$[$1] = $3;          }
# Line 520  scan_mode                 :  RECURSIVE Line 681  scan_mode                 :  RECURSIVE
681                            |  FLAT           { $$ = "FLAT"; }                            |  FLAT           { $$ = "FLAT"; }
682                            ;                            ;
683    
684    effect_system             :  string
685                              ;
686    
687    module                    :  filename
688                              ;
689    
690  // GRAMMAR_BNF_END - do NOT delete or modify this line !!!  // GRAMMAR_BNF_END - do NOT delete or modify this line !!!
691    
692    
# Line 534  dotnum                :      digits '.' Line 701  dotnum                :      digits '.'
701                        |  '-' digits '.' digits  { std::stringstream ss("-" + $2 + "." + $4); ss.imbue(std::locale::classic()); ss >> $$; }                        |  '-' digits '.' digits  { std::stringstream ss("-" + $2 + "." + $4); ss.imbue(std::locale::classic()); ss >> $$; }
702                        ;                        ;
703    
704    real                  :      digits '.' digits  { std::stringstream ss($1 + "." + $3); ss.imbue(std::locale::classic()); ss >> $$; }
705                          |  '+' digits '.' digits  { std::stringstream ss($2 + "." + $4); ss.imbue(std::locale::classic()); ss >> $$; }
706                          |  '-' digits '.' digits  { std::stringstream ss("-" + $2 + "." + $4); ss.imbue(std::locale::classic()); ss >> $$; }
707                          |      digits             { std::stringstream ss($1); ss.imbue(std::locale::classic()); ss >> $$;                  }
708                          |  '+' digits             { std::stringstream ss($2); ss.imbue(std::locale::classic()); ss >> $$;                  }
709                          |  '-' digits             { std::stringstream ss("-" + $2); ss.imbue(std::locale::classic()); ss >> $$;            }
710                          ;
711    
712    
713  digits                :  digit         { $$ = $1;      }  digits                :  digit         { $$ = $1;      }
714                        |  digits digit  { $$ = $1 + $2; }                        |  digits digit  { $$ = $1 + $2; }
# Line 722  CLEAR                 :  'C''L''E''A''R' Line 897  CLEAR                 :  'C''L''E''A''R'
897  FIND                  :  'F''I''N''D'  FIND                  :  'F''I''N''D'
898                        ;                        ;
899    
900    FILE_AS_DIR           :  'F''I''L''E''_''A''S''_''D''I''R'
901                          ;
902    
903  MOVE                  :  'M''O''V''E'  MOVE                  :  'M''O''V''E'
904                        ;                        ;
905    
# Line 758  REMOVE                :  'R''E''M''O''V' Line 936  REMOVE                :  'R''E''M''O''V'
936  SET                   :  'S''E''T'  SET                   :  'S''E''T'
937                        ;                        ;
938    
939    SHELL                 :  'S''H''E''L''L'
940                          ;
941    
942    INTERACT              :  'I''N''T''E''R''A''C''T'
943                          ;
944    
945    AUTO_CORRECT          :  'A''U''T''O''_''C''O''R''R''E''C''T'
946                          ;
947    
948    APPEND                :  'A''P''P''E''N''D'
949                          ;
950    
951    INSERT                :  'I''N''S''E''R''T'
952                          ;
953    
954  SUBSCRIBE             :  'S''U''B''S''C''R''I''B''E'  SUBSCRIBE             :  'S''U''B''S''C''R''I''B''E'
955                        ;                        ;
956    
# Line 815  DB_INSTRUMENT_COUNT           :  'D''B'' Line 1008  DB_INSTRUMENT_COUNT           :  'D''B''
1008  DB_INSTRUMENT_INFO            :  'D''B''_''I''N''S''T''R''U''M''E''N''T''_''I''N''F''O'  DB_INSTRUMENT_INFO            :  'D''B''_''I''N''S''T''R''U''M''E''N''T''_''I''N''F''O'
1009                                ;                                ;
1010    
1011    DB_INSTRUMENT_FILES           :  'D''B''_''I''N''S''T''R''U''M''E''N''T''_''F''I''L''E''S'
1012                                  ;
1013    
1014  DB_INSTRUMENTS_JOB_INFO       :  'D''B''_''I''N''S''T''R''U''M''E''N''T''S''_''J''O''B''_''I''N''F''O'  DB_INSTRUMENTS_JOB_INFO       :  'D''B''_''I''N''S''T''R''U''M''E''N''T''S''_''J''O''B''_''I''N''F''O'
1015                                ;                                ;
1016    
# Line 857  TOTAL_VOICE_COUNT_MAX:  'T''O''T''A''L'' Line 1053  TOTAL_VOICE_COUNT_MAX:  'T''O''T''A''L''
1053  GLOBAL_INFO          :  'G''L''O''B''A''L''_''I''N''F''O'  GLOBAL_INFO          :  'G''L''O''B''A''L''_''I''N''F''O'
1054                       ;                       ;
1055    
1056    EFFECT_INSTANCE_COUNT   :  'E''F''F''E''C''T''_''I''N''S''T''A''N''C''E''_''C''O''U''N''T'
1057                            ;
1058    
1059    EFFECT_INSTANCE_INFO    :  'E''F''F''E''C''T''_''I''N''S''T''A''N''C''E''_''I''N''F''O'
1060                            ;
1061    
1062    SEND_EFFECT_CHAIN_COUNT :  'S''E''N''D''_''E''F''F''E''C''T''_''C''H''A''I''N''_''C''O''U''N''T'
1063                            ;
1064    
1065    SEND_EFFECT_CHAIN_INFO  :  'S''E''N''D''_''E''F''F''E''C''T''_''C''H''A''I''N''_''I''N''F''O'
1066                            ;
1067    
1068  INSTRUMENT           :  'I''N''S''T''R''U''M''E''N''T'  INSTRUMENT           :  'I''N''S''T''R''U''M''E''N''T'
1069                       ;                       ;
1070    
# Line 899  AUDIO_OUTPUT_CHANNEL  :  'A''U''D''I''O' Line 1107  AUDIO_OUTPUT_CHANNEL  :  'A''U''D''I''O'
1107  AUDIO_OUTPUT_TYPE     :  'A''U''D''I''O''_''O''U''T''P''U''T''_''T''Y''P''E'  AUDIO_OUTPUT_TYPE     :  'A''U''D''I''O''_''O''U''T''P''U''T''_''T''Y''P''E'
1108                        ;                        ;
1109    
1110    AVAILABLE_EFFECTS :  'A''V''A''I''L''A''B''L''E''_''E''F''F''E''C''T''S'
1111                      ;
1112    
1113    EFFECT :  'E''F''F''E''C''T'
1114           ;
1115    
1116    EFFECT_INSTANCE :  'E''F''F''E''C''T''_''I''N''S''T''A''N''C''E'
1117                    ;
1118    
1119    EFFECT_INSTANCES :  'E''F''F''E''C''T''_''I''N''S''T''A''N''C''E''S'
1120                     ;
1121    
1122    EFFECT_INSTANCE_INPUT_CONTROL :  'E''F''F''E''C''T''_''I''N''S''T''A''N''C''E''_''I''N''P''U''T''_''C''O''N''T''R''O''L'
1123                                  ;
1124    
1125    SEND_EFFECT_CHAIN :  'S''E''N''D''_''E''F''F''E''C''T''_''C''H''A''I''N'
1126                      ;
1127    
1128    SEND_EFFECT_CHAINS :  'S''E''N''D''_''E''F''F''E''C''T''_''C''H''A''I''N''S'
1129                       ;
1130    
1131  AVAILABLE_MIDI_INPUT_DRIVERS  :  'A''V''A''I''L''A''B''L''E''_''M''I''D''I''_''I''N''P''U''T''_''D''R''I''V''E''R''S'  AVAILABLE_MIDI_INPUT_DRIVERS  :  'A''V''A''I''L''A''B''L''E''_''M''I''D''I''_''I''N''P''U''T''_''D''R''I''V''E''R''S'
1132                                ;                                ;
1133    
# Line 944  MIDI_INPUT_TYPE       :  'M''I''D''I''_' Line 1173  MIDI_INPUT_TYPE       :  'M''I''D''I''_'
1173  MIDI_INPUT            :  'M''I''D''I''_''I''N''P''U''T'  MIDI_INPUT            :  'M''I''D''I''_''I''N''P''U''T'
1174                        ;                        ;
1175    
1176    MIDI_INPUTS           :  'M''I''D''I''_''I''N''P''U''T''S'
1177                          ;
1178    
1179  MIDI_CONTROLLER       :  'M''I''D''I''_''C''O''N''T''R''O''L''L''E''R'  MIDI_CONTROLLER       :  'M''I''D''I''_''C''O''N''T''R''O''L''L''E''R'
1180                        ;                        ;
1181    
1182    SEND                  :  'S''E''N''D'
1183                          ;
1184    
1185  FX_SEND               :  'F''X''_''S''E''N''D'  FX_SEND               :  'F''X''_''S''E''N''D'
1186                        ;                        ;
1187    
# Line 986  RECURSIVE                  :  'R''E''C'' Line 1221  RECURSIVE                  :  'R''E''C''
1221  NON_RECURSIVE              :  'N''O''N''_''R''E''C''U''R''S''I''V''E'  NON_RECURSIVE              :  'N''O''N''_''R''E''C''U''R''S''I''V''E'
1222                             ;                             ;
1223    
1224    LOST                       :  'L''O''S''T'
1225                               ;
1226    
1227    FILE_PATH                  :  'F''I''L''E''_''P''A''T''H'
1228                               ;
1229    
1230  SERVER                :  'S''E''R''V''E''R'  SERVER                :  'S''E''R''V''E''R'
1231                        ;                        ;
1232    
# Line 995  VOLUME                :  'V''O''L''U''M' Line 1236  VOLUME                :  'V''O''L''U''M'
1236  LEVEL                 :  'L''E''V''E''L'  LEVEL                 :  'L''E''V''E''L'
1237                        ;                        ;
1238    
1239    VALUE                 :  'V''A''L''U''E'
1240                          ;
1241    
1242  MUTE                  :  'M''U''T''E'  MUTE                  :  'M''U''T''E'
1243                        ;                        ;
1244    
1245  SOLO                  :  'S''O''L''O'  SOLO                  :  'S''O''L''O'
1246                        ;                        ;
1247    
1248    VOICES                :  'V''O''I''C''E''S'
1249                          ;
1250    
1251    STREAMS               :  'S''T''R''E''A''M''S'
1252                          ;
1253    
1254  BYTES                 :  'B''Y''T''E''S'  BYTES                 :  'B''Y''T''E''S'
1255                        ;                        ;
1256    
# Line 1016  EDIT                  :  'E''D''I''T' Line 1266  EDIT                  :  'E''D''I''T'
1266  FORMAT                :  'F''O''R''M''A''T'  FORMAT                :  'F''O''R''M''A''T'
1267                        ;                        ;
1268    
1269    MIDI_DATA             :  'M''I''D''I''_''D''A''T''A'
1270                          ;
1271    
1272  RESET                 :  'R''E''S''E''T'  RESET                 :  'R''E''S''E''T'
1273                        ;                        ;
1274    
# Line 1033  QUIT                  :  'Q''U''I''T' Line 1286  QUIT                  :  'Q''U''I''T'
1286    
1287  %%  %%
1288    
1289    // TODO: actually would be fine to have the following bunch of source code in a separate file, however those functions are a) accessing private Bison tables like yytable and b) including the functions from another file here would make the line numbers incorrect on compile errors in auto generated lscpparser.cpp
1290    
1291  /**  /**
1292   * Will be called when an error occured (usually syntax error).   * Additional informations of a grammar symbol.
1293     */
1294    struct BisonSymbolInfo {
1295        bool isTerminalSymbol; ///< Whether the symbol is a terminal or non-termianl symbol. NOTE: Read comment regarding this in _isRuleTerminalSymbol() !!
1296        String nextExpectedChars; ///< According to current parser position: sequence of characters expected next for satisfying this grammar symbol.
1297    };
1298    
1299    #if HAVE_BISON_MAJ >= 3 // Bison 3.x or younger ...
1300    
1301    /**
1302     * Must ONLY be called just before a so called "reduce" parser action:
1303     * Returns true if the grammar rule, which is just about to be "reduced", is a
1304     * terminal symbol (in *our* terms).
1305     *
1306     * Please note that the term "terminal symbol" is a bit confusingly used in
1307     * this source code here around. In Bison's terms, "terminal symbols" are (more
1308     * or less) just the numbers returned by the YYLEX function. Since we decided
1309     * though to use a convenient solution without a separate lexer, and all its
1310     * caveats, all numbers by the yylex() function here are just the ASCII
1311     * numbers of the individual characters received. Based on that however, one
1312     * single character is not what one would intuitively expect of being a
1313     * "terminal symbol", because it is simply too primitive.
1314     *
1315     * So in this LSCP parser source code a "terminal symbol" rather means a
1316     * keyword like "CREATE" or "GET". In the grammal definition above, those are
1317     * however defined as grammar rules (non-terminals in Bison's terms). So this
1318     * function decides like this: if the given grammar rule just contains
1319     * individual characters on the right side of its grammar rule, then it is a
1320     * "terminal symbol" in *our* terms.
1321     *
1322     * @param rule - Bison grammar rule number
1323     * @param stack - reflecting current Bison parser state
1324     */
1325    inline static bool _isRuleTerminalSymbol(int rule, const std::vector<YYTYPE_INT16>& stack) {
1326        int nrhs = yyr2[rule];
1327        for (int i = 0; i < nrhs; ++i)
1328            if (yystos[*(stack.end() - nrhs + i)] >= YYNTOKENS) return false;
1329        return true;
1330    }
1331    
1332    /**
1333     * Must ONLY be called just before a so called "reduce" parser action: Returns
1334     * additional informations to the given grammar rule that is about to be
1335     * "reduced".
1336     *
1337     * @param rule - Bison grammar rule number
1338     * @param stack - reflecting current Bison parser state
1339     * @param nextExpectedChars - must already be filled with the characters
1340     *                            expected to be coming next
1341   */   */
1342  void yyerror(const char* s) {  inline static BisonSymbolInfo _symbolInfoForRule(int rule, const std::vector<YYTYPE_INT16>& stack, const String& nextExpectedChars) {
1343        BisonSymbolInfo info;
1344        info.isTerminalSymbol = _isRuleTerminalSymbol(rule, stack);
1345        if (info.isTerminalSymbol) info.nextExpectedChars  = nextExpectedChars;
1346        return info;
1347    }
1348    
1349    #else // Bison 2.x or older ...
1350    
1351    /**
1352     * Returns true if the given grammar @a rule is a terminal symbol (in *our*
1353     * terms).
1354     *
1355     * Please note that the term "terminal symbol" is a bit confusingly used in
1356     * this source code here around. In Bison's terms, "terminal symbols" are (more
1357     * or less) just the numbers returned by the YYLEX function. Since we decided
1358     * though to use a convenient solution without a separate lexer, and all its
1359     * caveats, all numbers by the yylex() function here are just the ASCII
1360     * numbers of the individual characters received. Based on that however, one
1361     * single character is not what one would intuitively expect of being a
1362     * "terminal symbol", because it is simply too primitive.
1363     *
1364     * So in this LSCP parser source code a "terminal symbol" rather means a
1365     * keyword like "CREATE" or "GET". In the grammal definition above, those are
1366     * however defined as grammar rules (non-terminals in Bison's terms). So this
1367     * function decides like this: if the given grammar rule just contains
1368     * individual characters on the right side of its grammar rule, then it is a
1369     * "terminal symbol" in *our* terms.
1370     *
1371     * @param rule - Bison grammar rule number
1372     */
1373    inline static bool _isRuleTerminalSymbol(int rule) {
1374        for (int i = yyprhs[rule]; yyrhs[i] != -1; ++i)
1375            if (yyrhs[i] >= YYNTOKENS) return false;
1376        return true;
1377    }
1378    
1379    /**
1380     * Returns additional informations to the given grammar @a rule.
1381     *
1382     * @param rule - grammar rule index to retrieve informations about
1383     * @param nextExpectedChars - must already be filled with the characters
1384     *                            expected to be coming next
1385     */
1386    inline static BisonSymbolInfo _symbolInfoForRule(int rule, const String& nextExpectedChars) {
1387        BisonSymbolInfo info;
1388        info.isTerminalSymbol = _isRuleTerminalSymbol(rule);
1389        if (info.isTerminalSymbol) info.nextExpectedChars  = nextExpectedChars;
1390        return info;
1391    }
1392    
1393    #endif // HAVE_BISON_MAJ >= 3
1394    
1395    /**
1396     * Returns the human readable name of the given @a token.
1397     */
1398    inline static String _tokenName(int token) {
1399        String s = yytname[token];
1400        // remove leading and trailing apostrophes that Bison usually adds to
1401        // ASCII characters used directly in grammar rules
1402        if (s.empty()) return s;
1403        if (s[0] == '\'') s.erase(0, 1);
1404        if (s.empty()) return s;
1405        if (s[s.size() - 1] == '\'') s.erase(s.size() - 1);
1406        return s;
1407    }
1408    
1409    /**
1410     * Assumes the given @a token is exactly one character and returns that
1411     * character. This must be changed in future, i.e. in case Unicode characters
1412     * will be introduced in the LSCP grammar one day.
1413     */
1414    inline static char _tokenChar(int token) {
1415        String s = _tokenName(token);
1416        if (s == "\\n") return '\n';
1417        if (s == "\\r") return '\r';
1418        return _tokenName(token)[0];
1419    }
1420    
1421    /**
1422     * Implements Bison's so called "reduce" action, according to Bison's LALR(1)
1423     * parser algorithm.
1424     */
1425    inline static int _yyReduce(std::vector<YYTYPE_INT16>& stack, const int& rule) {
1426        if (stack.empty()) throw 1; // severe error
1427        const int len = yyr2[rule];
1428        stack.resize(stack.size() - len);
1429        YYTYPE_INT16 newState = yypgoto[yyr1[rule] - YYNTOKENS] + stack.back();
1430        if (0 <= newState && newState <= YYLAST && yycheck[newState] == stack.back())
1431            newState = yytable[newState];
1432        else
1433            newState = yydefgoto[yyr1[rule] - YYNTOKENS];
1434        stack.push_back(newState);
1435        return newState;
1436    }
1437    
1438    /**
1439     * Implements Bison's so called "default reduce" action, according to Bison's
1440     * LALR(1) parser algorithm.
1441     */
1442    inline static int _yyDefaultReduce(std::vector<YYTYPE_INT16>& stack) {
1443        if (stack.empty()) throw 2; // severe error
1444        int rule = yydefact[stack.back()];
1445        if (rule <= 0 || rule >= YYNRULES) throw 3; // no rule, something is wrong
1446        return _yyReduce(stack, rule);
1447    }
1448    
1449    static bool yyValid(std::vector<YYTYPE_INT16>& stack, char ch);
1450    
1451    #define DEBUG_BISON_SYNTAX_ERROR_WALKER 0
1452    
1453    /**
1454     * Tries to find the next expected grammar symbols according to the given
1455     * precise parse position & state represented by @a stack, according to Bison's
1456     * LALR(1) parser algorithm.
1457     *
1458     * This function is given a Bison parser state stack, reflecting the parser's
1459     * entire state at a certain point, i.e. when a syntax error occured. This
1460     * function will then walk ahead the potential parse tree starting from the
1461     * current head of the given state stack. This function will call itself
1462     * recursively to scan the individual parse tree branches. As soon as it hits
1463     * on the next non-terminal grammar symbol in one parse tree branch, it adds the
1464     * found non-terminal symbol to @a expectedSymbols and aborts scanning the
1465     * respective tree branch further. If any local parser state is reached a second
1466     * time, the respective parse tree is aborted to avoid any endless recursion.
1467     *
1468     * @param stack - current Bison (yacc) state stack to be examined
1469     * @param expectedSymbols - will be filled with next expected grammar symbols
1470     * @param nextExpectedChars - just for internal purpose, due to the recursive
1471     *                            implementation of this function, do supply an
1472     *                            empty character for this argument
1473     * @param depth - just for internal debugging purposes
1474     */
1475    static void walkAndFillExpectedSymbols(
1476        std::vector<YYTYPE_INT16>& stack,
1477        std::map<String,BisonSymbolInfo>& expectedSymbols,
1478        String& nextExpectedChars, int depth = 0)
1479    {
1480    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1481        printf("\n");
1482        for (int i = 0; i < depth; ++i) printf("\t");
1483        printf("State stack:");
1484        for (int i = 0; i < stack.size(); ++i) {
1485            printf(" %d", stack[i]);
1486        }
1487        printf("\n");
1488    #endif
1489        startLabel:
1490    
1491        if (stack.empty()) {
1492    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1493            for (int i = 0; i < depth; ++i) printf("\t");
1494            printf("(EMPTY STACK)\n");
1495    #endif
1496            return;
1497        }
1498    
1499        int state = stack[stack.size() - 1];
1500        int n = yypact[state];
1501        if (n == YYPACT_NINF) { // default reduction required ...
1502            // get default reduction rule for this state
1503            n = yydefact[state];
1504            if (n <= 0 || n >= YYNRULES) {
1505    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1506                for (int i = 0; i < depth; ++i) printf("\t");
1507                printf("(EMPTY RULE)\n");
1508    #endif
1509                return; // no rule, something is wrong
1510            }
1511    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1512            for (int i = 0; i < depth; ++i) printf("\t");
1513            printf("(default reduction)\n");
1514    #endif
1515            if (!nextExpectedChars.empty() || !_isRuleTerminalSymbol(n, stack)) {
1516                // Return the new resolved expected symbol (left-hand symbol of grammar
1517                // rule), then we're done in this state. (If the same symbol can be
1518                // matched on different ways, then it is non-terminal symbol.)
1519                bool ambigious =
1520                    expectedSymbols.count(yytname[yyr1[n]]) &&
1521                    expectedSymbols[yytname[yyr1[n]]].nextExpectedChars != nextExpectedChars;
1522                #if HAVE_BISON_MAJ >= 3
1523                expectedSymbols[yytname[yyr1[n]]] = _symbolInfoForRule(n, stack, nextExpectedChars);
1524                #else
1525                expectedSymbols[yytname[yyr1[n]]] = _symbolInfoForRule(n, nextExpectedChars);
1526                #endif
1527                if (ambigious)
1528                    expectedSymbols[yytname[yyr1[n]]].isTerminalSymbol = false;
1529    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1530                for (int i = 0; i < depth; ++i) printf("\t");
1531                printf("(empty expectedChars. sym = %s)\n", yytname[yyr1[n]]);
1532    #endif
1533                return;
1534            }
1535            _yyReduce(stack, n);
1536            goto startLabel;
1537        }
1538        if (!(YYPACT_NINF < n && n <= YYLAST)) {
1539    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1540            for (int i = 0; i < depth; ++i) printf("\t");
1541            printf("(invalid action B)\n");
1542    #endif
1543            return;
1544        }
1545    
1546        // Check for duplicate states, if duplicates exist return
1547        // (this check is necessary since the introduction of the yyValid() call
1548        // below, which does not care about duplicates).
1549        for (int i = 0; i < stack.size(); ++i)
1550            for (int k = i + 1; k < stack.size(); ++k)
1551                if (stack[i] == stack[k])
1552                    return;
1553    
1554    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1555        for (int i = 0; i < depth; ++i) printf("\t");
1556        printf("Expected tokens:");
1557    #endif
1558        int begin = n < 0 ? -n : 0;
1559        //int checklim = YYLAST - n + 1;
1560        int end = YYNTOKENS;//checklim < YYNTOKENS ? checklim : YYNTOKENS;
1561        int rule, action, stackSize, nextExpectedCharsLen;
1562        for (int token = begin; token < end; ++token) {
1563            if (token <= YYTERROR) continue;
1564            if (yytname[token] == String("$undefined")) continue;
1565            if (yytname[token] == String("EXT_ASCII_CHAR")) continue;
1566            //if (yycheck[n + token] != token) goto default_reduction;
1567            if (yycheck[n + token] != token) { // default reduction suggested ...
1568                // If we are here, it means the current token in the loop would not
1569                // cause a "shift", however we don't already know whether this token
1570                // is valid or not. Because there might be several reductions
1571                // involved until one can determine whether the token causes an
1572                // error or is valid. So we use this heavy check instead:
1573                std::vector<YYTYPE_INT16> stackCopy = stack; // copy required, since reduction will take place
1574                if (!yyValid(stackCopy, _tokenChar(token))) continue; // invalid token
1575    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1576                printf(" ETdr(%s)", yytname[token]);
1577    #endif
1578                // the token is valid, "stackCopy" has been reduced accordingly
1579                // and now do recurse ...
1580                nextExpectedChars += _tokenName(token);
1581                nextExpectedCharsLen = nextExpectedChars.size();
1582                walkAndFillExpectedSymbols( //FIXME: could cause stack overflow (should be a loop instead), is probably fine with our current grammar though
1583                    stackCopy, expectedSymbols, nextExpectedChars, depth + 1
1584                );
1585                nextExpectedChars.resize(nextExpectedCharsLen); // restore 'nextExpectedChars'
1586                continue;
1587            }
1588    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1589            printf(" ET(%s)", yytname[token]);
1590    #endif
1591    
1592            action = yytable[n + token];
1593            if (action == 0 || action == YYTABLE_NINF) {
1594    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1595                printf(" (invalid action A) "); fflush(stdout);
1596    #endif
1597                continue; // error, ignore
1598            }
1599            if (action < 0) { // reduction with rule -action required ...
1600    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1601                printf(" (reduction) "); fflush(stdout);
1602    #endif
1603                rule = -action;
1604                goto reduce;
1605            }
1606            if (action == YYFINAL) {
1607    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1608                printf(" (ACCEPT) "); fflush(stdout);
1609    #endif
1610                continue; // "accept" state, we don't care about it here
1611            }
1612    
1613            // "shift" required ...
1614    
1615            if (std::find(stack.begin(), stack.end(), action) != stack.end()) {
1616    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1617                printf(" (duplicate state %d) ", action); fflush(stdout);
1618    #endif
1619                continue; // duplicate state, ignore it to avoid endless recursions
1620            }
1621    
1622            // "shift" / push the new state on the state stack and call this
1623            // function recursively, and restore the stack after the recurse return
1624            stackSize = stack.size();
1625            nextExpectedCharsLen = nextExpectedChars.size();
1626            stack.push_back(action);
1627            nextExpectedChars += _tokenName(token);
1628            walkAndFillExpectedSymbols( //FIXME: could cause stack overflow (should be a loop instead), is probably fine with our current grammar though
1629                stack, expectedSymbols, nextExpectedChars, depth + 1
1630            );
1631            stack.resize(stackSize); // restore stack
1632            nextExpectedChars.resize(nextExpectedCharsLen); // restore 'nextExpectedChars'
1633            continue;
1634    
1635        //default_reduction: // resolve default reduction for this state
1636        //    printf(" (default red.) "); fflush(stdout);
1637        //    rule = yydefact[state];
1638    
1639        reduce: // "reduce" required
1640    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1641            printf(" (reduce by %d) ", rule); fflush(stdout);
1642    #endif
1643            if (rule == 0 || rule >= YYNRULES) {
1644    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1645                printf(" (invalid rule) "); fflush(stdout);
1646    #endif
1647                continue; // invalid rule, something is wrong
1648            }
1649            // Store the left-hand symbol of the grammar rule. (If the same symbol
1650            // can be matched on different ways, then it is non-terminal symbol.)
1651            bool ambigious =
1652                expectedSymbols.count(yytname[yyr1[rule]]) &&
1653                expectedSymbols[yytname[yyr1[rule]]].nextExpectedChars != nextExpectedChars;
1654            #if HAVE_BISON_MAJ >= 3
1655            expectedSymbols[yytname[yyr1[rule]]] = _symbolInfoForRule(rule, stack, nextExpectedChars);
1656            #else
1657            expectedSymbols[yytname[yyr1[rule]]] = _symbolInfoForRule(rule, nextExpectedChars);
1658            #endif
1659            if (ambigious)
1660                expectedSymbols[yytname[yyr1[n]]].isTerminalSymbol = false;
1661    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1662            printf(" (SYM %s) ", yytname[yyr1[rule]]); fflush(stdout);
1663    #endif
1664        }
1665    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1666        printf("\n");
1667    #endif
1668    }
1669    
1670    #define DEBUG_PUSH_PARSE 0
1671    
1672    /**
1673     * Implements parsing exactly one character (given by @a c), continueing at the
1674     * parser position reflected by @a stack. The @a stack will hold the new parser
1675     * state after this call.
1676     *
1677     * This function is implemented according to Bison's LALR(1) parser algorithm.
1678     */
1679    static bool yyPushParse(std::vector<YYTYPE_INT16>& stack, char ch) {
1680        startLabel:
1681    
1682    #if DEBUG_PUSH_PARSE
1683        //printf("\n");
1684        //for (int i = 0; i < depth; ++i) printf("\t");
1685        printf("State stack:");
1686        for (int i = 0; i < stack.size(); ++i) {
1687            printf(" %d", stack[i]);
1688        }
1689        printf(" char='%c'(%d)\n", ch, (int)ch);
1690    #endif
1691    
1692        if (stack.empty()) return false;
1693    
1694        int state = stack.back();
1695        int n = yypact[state];
1696        if (n == YYPACT_NINF) { // default reduction required ...
1697    #if DEBUG_PUSH_PARSE
1698            printf("(def reduce 1)\n");
1699    #endif
1700            state = _yyDefaultReduce(stack);
1701            goto startLabel;
1702        }
1703        if (!(YYPACT_NINF < n && n <= YYLAST)) return false;
1704    
1705        YYTYPE_INT16 token = (ch == YYEOF) ? YYEOF : yytranslate[ch];
1706        n += token;
1707        if (n < 0 || YYLAST < n || yycheck[n] != token) {
1708    #if DEBUG_PUSH_PARSE
1709            printf("(def reduce 2) n=%d token=%d\n", n, token);
1710    #endif
1711            state = _yyDefaultReduce(stack);
1712            goto startLabel;
1713        }
1714        int action = yytable[n]; // yytable[yypact[state] + token]
1715        if (action == 0 || action == YYTABLE_NINF) throw 4;
1716        if (action < 0) {
1717    #if DEBUG_PUSH_PARSE
1718            printf("(reduce)\n");
1719    #endif
1720            int rule = -action;
1721            state = _yyReduce(stack, rule);
1722            goto startLabel;
1723        }
1724        if (action == YYFINAL) return true; // final state reached
1725    
1726    #if DEBUG_PUSH_PARSE
1727        printf("(push)\n");
1728    #endif
1729        // push new state
1730        state = action;
1731        stack.push_back(state);
1732        return true;
1733    }
1734    
1735    /**
1736     * Returns true if parsing ahead with given character @a ch is syntactically
1737     * valid according to the LSCP grammar, it returns false if it would create a
1738     * parse error.
1739     *
1740     * The @a stack will reflect the new parser state after this call.
1741     *
1742     * This is just a wrapper ontop of yyPushParse() which converts parser
1743     * exceptions thrown by yyPushParse() into negative return value.
1744     */
1745    static bool yyValid(std::vector<YYTYPE_INT16>& stack, char ch) {
1746        try {
1747            return yyPushParse(stack, ch);
1748        } catch (int i) {
1749    #if DEBUG_PUSH_PARSE
1750            printf("exception %d\n", i);
1751    #endif
1752            return false;
1753        } catch (...) {
1754            return false;
1755        }
1756    }
1757    
1758    /**
1759     * Returns the amount of correct characters of given @a line from the left,
1760     * according to the LSCP grammar.
1761     *
1762     * @param stack - a Bison symbol state stack to work with
1763     * @param line  - the input line to check
1764     * @param bAutoCorrect - if true: try to correct obvious, trivial syntax errors
1765     */
1766    static int yyValidCharacters(std::vector<YYTYPE_INT16>& stack, String& line, bool bAutoCorrect) {
1767        int i;
1768        for (i = 0; i < line.size(); ++i) {
1769            // since we might check the same parser state twice against the current
1770            // char here below, and since the state stack might be altered
1771            // (i.e. shifted or reduced) on syntax errors, we have to backup the
1772            // current state stack and restore it on syntax errors below
1773            std::vector<YYTYPE_INT16> stackCopy = stack;
1774            if (yyValid(stackCopy, line[i])) {
1775                stack = stackCopy;
1776                continue;
1777            }
1778            if (bAutoCorrect) {
1779                // try trivial corrections, i.e. upper case character instead of
1780                // lower case, subline instead of space and vice versa
1781                char c;
1782                if      (line[i] == ' ') c = '_';
1783                else if (line[i] == '_') c = ' ';
1784                else if (isLowerCaseAlphaChar(line[i]))
1785                    c = alphaCharToUpperCase(line[i]);
1786                else return i;
1787                if (yyValid(stack, c)) {
1788                    line[i] = c;
1789                    continue;
1790                }
1791            }
1792            return i;
1793        }
1794        return i;
1795    }
1796    
1797    /**
1798     * Should only be called on syntax errors: returns a set of non-terminal
1799     * symbols expected to appear now/next, just at the point where the syntax
1800     * error appeared.
1801     *
1802     * @returns names of the non-terminal symbols expected at this parse position
1803     */
1804    static std::set<String> yyExpectedSymbols() {
1805        std::map<String,BisonSymbolInfo> expectedSymbols;
1806      yyparse_param_t* param = GetCurrentYaccSession();      yyparse_param_t* param = GetCurrentYaccSession();
1807      String msg = s      YYTYPE_INT16* ss = (*param->ppStackBottom);
1808          + (" (line:"   + ToString(param->iLine+1))      YYTYPE_INT16* sp = (*param->ppStackTop);
1809          + ( ",column:" + ToString(param->iColumn))      int iStackSize   = sp - ss + 1;
1810          + ")";      // copy and wrap parser's state stack into a convenient STL container
1811      dmsg(2,("LSCPParser: %s\n", msg.c_str()));      std::vector<YYTYPE_INT16> stack;
1812      sLastError = msg;      for (int i = 0; i < iStackSize; ++i) {
1813            stack.push_back(ss[i]);
1814        }
1815        String notUsedHere;
1816        // do the actual parser work
1817        walkAndFillExpectedSymbols(stack, expectedSymbols, notUsedHere);
1818    
1819        // convert expectedSymbols to the result set
1820        std::set<String> result;
1821        for (std::map<String,BisonSymbolInfo>::const_iterator it = expectedSymbols.begin();
1822             it != expectedSymbols.end(); ++it) result.insert(it->first);
1823        return result;
1824    }
1825    
1826    #define DEBUG_YY_AUTO_COMPLETE 0
1827    
1828    /**
1829     * A set of parser state stacks. This type is used in yyAutoComplete() to keep
1830     * track of all previous parser states, for detecting a parser state stack that
1831     * has already been before. Because if yyAutoComplete() reaches the exactly same
1832     * parser state stack again, it means there is an endless recursion in that
1833     * part of the grammar tree branch and shall not be evaluated any further,
1834     * because it would end up in an endless loop otherwise.
1835     *
1836     * This solution consumes a lot of memory, but unfortunately there is no other
1837     * easy way to solve it. With our grammar and today's memory heap & memory stack
1838     * it should be fine though.
1839     */
1840    typedef std::set< std::vector<YYTYPE_INT16> > YYStackHistory;
1841    
1842    /**
1843     * Generates and returns an auto completion string for the current parser
1844     * state given by @a stack.
1845     *
1846     * Regarding @a history argument: read the description on YYStackHistory for the
1847     * purpose behind this argument.
1848     *
1849     * @param stack - current Bison (yacc) state stack to create auto completion for
1850     * @param history - only for internal purpose, keeps a history of all previous parser state stacks
1851     * @param depth - just for internal debugging purposes
1852     * @returns auto completion for current, given parser state
1853     */
1854    static String yyAutoComplete(std::vector<YYTYPE_INT16>& stack, YYStackHistory& history, int depth = 0) {
1855        std::map<String,BisonSymbolInfo> expectedSymbols;
1856        String notUsedHere;
1857        walkAndFillExpectedSymbols(stack, expectedSymbols, notUsedHere);
1858        if (expectedSymbols.size() == 1) {
1859            String name          = expectedSymbols.begin()->first;
1860            BisonSymbolInfo info = expectedSymbols.begin()->second;
1861    #if DEBUG_YY_AUTO_COMPLETE
1862            for (int q = 0; q < depth; ++q) printf("  ");
1863            printf("(%d) Suggested Sub Completion (sz=%d): type=%s %s -> '%s'\n", depth, expectedSymbols.size(), (info.isTerminalSymbol) ? "T" : "NT", name.c_str(), info.nextExpectedChars.c_str());
1864    #endif
1865            if (info.nextExpectedChars.empty() || !info.isTerminalSymbol) return "";
1866            // parse forward with the suggested auto completion
1867            std::vector<YYTYPE_INT16> stackCopy = stack;
1868            yyValidCharacters(stackCopy, info.nextExpectedChars, false);
1869            // detect endless recursion
1870            if (history.count(stackCopy)) return "";
1871            history.insert(stackCopy);
1872            // recurse and return the expanded auto completion with maximum length
1873            return info.nextExpectedChars + yyAutoComplete(stackCopy, history, depth + 1);
1874        } else if (expectedSymbols.size() == 0) {
1875    #if DEBUG_YY_AUTO_COMPLETE
1876            for (int q = 0; q < depth; ++q) printf("  ");
1877            printf("(%d) No sub suggestion.\n", depth);
1878    #endif
1879            return "";
1880        } else if (expectedSymbols.size() > 1) {
1881    #if DEBUG_YY_AUTO_COMPLETE
1882            for (int q = 0; q < depth; ++q) printf("  ");
1883            printf("(%d) Multiple sub possibilities (before expansion):", depth);
1884            for (std::map<String,BisonSymbolInfo>::const_iterator it = expectedSymbols.begin();
1885                 it != expectedSymbols.end(); ++it)
1886            {
1887                printf(" %s (..%s)", it->first.c_str(), it->second.nextExpectedChars.c_str());
1888            }
1889            printf("\n");
1890    #endif
1891            // check if any of the possibilites is a non-terminal symbol, if so, we
1892            // have no way for auto completion at this point
1893            for (std::map<String,BisonSymbolInfo>::const_iterator it = expectedSymbols.begin();
1894                 it != expectedSymbols.end(); ++it)
1895            {
1896                if (!it->second.isTerminalSymbol) {
1897    #if DEBUG_YY_AUTO_COMPLETE
1898                    for (int q = 0; q < depth; ++q) printf("  ");
1899                    printf("(%d) Non-terminal exists. Stop.", depth);
1900    #endif
1901                    return "";
1902                }
1903            }
1904    #if 0 // commented out for now, since practically irrelevant and VERY slow ...
1905            // all possibilities are terminal symbols, so expand all possiblities to
1906            // maximum length with a recursive call for each possibility
1907            for (std::map<String,BisonSymbolInfo>::iterator it = expectedSymbols.begin();
1908                 it != expectedSymbols.end(); ++it)
1909            {
1910                if (it->second.nextExpectedChars.empty() || !it->second.isTerminalSymbol) continue;
1911                // parse forward with this particular suggested auto completion
1912                std::vector<YYTYPE_INT16> stackCopy = stack;
1913                yyValidCharacters(stackCopy, it->second.nextExpectedChars, false);
1914                // detect endless recursion
1915                if (history.count(stackCopy)) continue;
1916                history.insert(stackCopy);
1917                // recurse and return the total possible auto completion for this
1918                // grammar tree branch
1919                it->second.nextExpectedChars += yyAutoComplete(stackCopy, history, depth + 1);
1920            }
1921    #endif
1922            // try to find the longest common string all possibilities start with
1923            // (from the left)
1924            String sCommon;
1925            for (int i = 0; true; ++i) {
1926                char c;
1927                for (std::map<String,BisonSymbolInfo>::const_iterator it = expectedSymbols.begin();
1928                     it != expectedSymbols.end(); ++it)
1929                {
1930                    if (i >= it->second.nextExpectedChars.size())
1931                        goto commonSearchEndLabel;
1932                    if (it == expectedSymbols.begin())
1933                        c = it->second.nextExpectedChars[i];
1934                    if (c != it->second.nextExpectedChars[i])
1935                        goto commonSearchEndLabel;
1936                    if (it == --expectedSymbols.end())
1937                        sCommon += c;
1938                }
1939            }
1940            commonSearchEndLabel:
1941    #if DEBUG_YY_AUTO_COMPLETE
1942            for (int q = 0; q < depth; ++q) printf("  ");
1943            printf("(%d) Multiple sub possibilities (after expansion):", depth);
1944            for (std::map<String,BisonSymbolInfo>::const_iterator it = expectedSymbols.begin();
1945                 it != expectedSymbols.end(); ++it)
1946            {
1947                printf(" %s (..%s)", it->first.c_str(), it->second.nextExpectedChars.c_str());
1948            }
1949            printf("\n");
1950            for (int q = 0; q < depth; ++q) printf("  ");
1951            printf("(%d) Common sub possibility: '%s'\n", depth, sCommon.c_str());
1952    #endif
1953            return sCommon;
1954        }
1955        return ""; // just pro forma, should never happen though
1956    }
1957    
1958    /**
1959     * Just a convenience wrapper on top of the actual yyAutoComplete()
1960     * implementation. See description above for details.
1961     */
1962    static String yyAutoComplete(std::vector<YYTYPE_INT16>& stack) {
1963        YYStackHistory history;
1964        return yyAutoComplete(stack, history);
1965    }
1966    
1967    namespace LinuxSampler {
1968    
1969    #define DEBUG_SHELL_INTERACTION 0
1970    
1971    /**
1972     * If LSP shell mode is enabled for the respective LSCP client connection, then
1973     * this function is called on every new byte received from that client. It will
1974     * check the current total input line and reply to the LSCP shell for providing
1975     * colored syntax highlighting and potential auto completion in the shell.
1976     *
1977     * It also performs auto correction of obvious & trivial syntax mistakes if
1978     * requested.
1979     *
1980     * The return value of this function will be sent to the client. It contains one
1981     * line specially formatted for the LSCP shell, which can easily be processed by
1982     * the client/shell for gettings its necessary informations like which part of
1983     * the current command line is syntactically correct, which part is incorrect,
1984     * what could be auto completed right now, etc.
1985     *
1986     * @returns LSCP shell response line to be returned to the client
1987     */
1988    String lscpParserProcessShellInteraction(String& line, yyparse_param_t* param) {
1989        // first, determine how many characters (starting from the left) of the
1990        // given input line are already syntactically correct
1991        std::vector<YYTYPE_INT16> stack;
1992        stack.push_back(0); // every Bison symbol stack starts with state zero
1993        String l = line + '\n'; // '\n' to pretend ENTER as if the line was now complete
1994        int n = yyValidCharacters(stack, l, param->bShellAutoCorrect);
1995    
1996        // if auto correction is enabled, apply the auto corrected string to
1997        // intput/output string 'line'
1998        if (param->bShellAutoCorrect) {
1999            int nMin = (n < line.length()) ? n : line.length();
2000            line.replace(0, nMin, l.substr(0, nMin));
2001        }
2002    
2003        // generate an info string that will be sent to the LSCP shell for letting
2004        // it know which part is correct, which one is wrong, where is the cursor, etc.
2005        String result = line;
2006        result.insert(n <= result.length() ? n : result.length(), LSCP_SHK_GOOD_FRONT);
2007        int code = (n > line.length()) ? LSCP_SHU_COMPLETE : (n < line.length()) ?
2008                   LSCP_SHU_SYNTAX_ERR : LSCP_SHU_INCOMPLETE;
2009        result = "SHU:" + ToString(code) + ":" + result + LSCP_SHK_CURSOR;
2010        //if (n > line.length()) result += " [OK]";
2011    
2012        // get a clean parser stack to the last valid parse position
2013        // (due to the appended '\n' character above, and on syntax errors, the
2014        // state stack might be in undesired, i.e. reduced state)
2015        stack.clear();
2016        stack.push_back(0); // every Bison symbol stack starts with state zero
2017        l = line.substr(0, n);
2018        if (!l.empty()) yyValidCharacters(stack, l, param->bShellAutoCorrect);
2019    
2020        // generate auto completion suggestion (based on the current parser stack)
2021        String sSuggestion = yyAutoComplete(stack);
2022        if (!sSuggestion.empty()) result += LSCP_SHK_SUGGEST_BACK + sSuggestion;
2023    
2024    #if DEBUG_SHELL_INTERACTION
2025        printf("%s\n", result.c_str());
2026    #endif
2027    
2028        return result;
2029  }  }
2030    
2031  /**  /**
# Line 1053  void restart(yyparse_param_t* pparam, in Line 2035  void restart(yyparse_param_t* pparam, in
2035      bytes = 0;      bytes = 0;
2036      ptr   = 0;      ptr   = 0;
2037      sLastError = "";      sLastError = "";
2038        sParsed = "";
2039    }
2040    
2041  }  }

Legend:
Removed from v.1695  
changed lines
  Added in v.2523

  ViewVC Help
Powered by ViewVC