/[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 2137 by schoenebeck, Mon Oct 4 12:20:23 2010 UTC revision 2515 by schoenebeck, Wed Feb 5 20:45:18 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 - 2010 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 35  Line 35 
35  #include "lscpserver.h"  #include "lscpserver.h"
36  #include "lscpevent.h"  #include "lscpevent.h"
37  #include "lscpsymbols.h"  #include "lscpsymbols.h"
38    #include <algorithm>
39    #include "lscp.h"
40    
41  namespace LinuxSampler {  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);
# Line 51  static char buf[1024]; // input buffer t Line 53  static char buf[1024]; // input buffer t
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 81  int yylex(YYSTYPE* yylval) { Line 84  int yylex(YYSTYPE* yylval) {
84      const char c = buf[ptr++];      const char c = buf[ptr++];
85      // increment current reading position (just for verbosity / messages)      // increment current reading position (just for verbosity / messages)
86      GetCurrentYaccSession()->iColumn++;      GetCurrentYaccSession()->iColumn++;
87        sParsed += c;
88      // we have to handle "normal" and "extended" ASCII characters separately      // we have to handle "normal" and "extended" ASCII characters separately
89      if (isExtendedAsciiChar(c)) {      if (isExtendedAsciiChar(c)) {
90          // workaround for characters with ASCII code higher than 127          // workaround for characters with ASCII code higher than 127
# Line 103  int octalsToNumber(char oct_digit0, char Line 107  int octalsToNumber(char oct_digit0, char
107    
108  }  }
109    
 // we provide our own version of yyerror() so we don't have to link against the yacc library  
 void yyerror(const char* s);  
   
110  using namespace LinuxSampler;  using namespace LinuxSampler;
111    
112    static std::set<String> yyExpectedSymbols();
113    
114    /**
115     * Will be called when an error occured (usually syntax error).
116     *
117     * We provide our own version of yyerror() so we a) don't have to link against
118     * the yacc library and b) can render more helpful syntax error messages.
119     */
120    void yyerror(void* x, const char* s) {
121        yyparse_param_t* param = GetCurrentYaccSession();
122    
123        // get the text part already parsed (of current line)
124        const bool bContainsLineFeed =
125            sParsed.find('\r') != std::string::npos ||
126            sParsed.find('\n') != std::string::npos;
127        // remove potential line feed characters
128        if (bContainsLineFeed) {
129            for (size_t p = sParsed.find('\r'); p != std::string::npos;
130                 p = sParsed.find('\r')) sParsed.erase(p);
131            for (size_t p = sParsed.find('\n'); p != std::string::npos;
132                 p = sParsed.find('\n')) sParsed.erase(p);
133        }
134    
135        // start assembling the error message with Bison's own message
136        String txt = s;
137    
138        // append exact position info of syntax error
139        txt += (" (line:"  + ToString(param->iLine+1)) +
140               (",column:" + ToString(param->iColumn)) + ")";
141    
142        // append the part of the lined that has already been parsed
143        txt += ". Context: \"" + sParsed;
144        if (txt.empty() || bContainsLineFeed)
145            txt += "^";
146        else
147            txt.insert(txt.size() - 1, "^");
148        txt += "...\"";
149    
150        // append the non-terminal symbols expected now/next
151        std::set<String> expectedSymbols = yyExpectedSymbols();
152        for (std::set<String>::const_iterator it = expectedSymbols.begin();
153             it != expectedSymbols.end(); ++it)
154        {
155            if (it == expectedSymbols.begin())
156                txt += " -> Should be: " + *it;
157            else
158                txt += " | " + *it;
159        }
160    
161        dmsg(2,("LSCPParser: %s\n", txt.c_str()));
162        sLastError = txt;
163    }
164    
165  %}  %}
166    
167  // reentrant parser  // reentrant parser
168  %pure_parser  %pure-parser
169    
170    %parse-param {void* yyparse_param}
171    
172    // After entering the yyparse() function, store references to the parser's
173    // state stack, so that we can create more helpful syntax error messages than
174    // Bison (2.x) could do.
175    %initial-action {
176        yyparse_param_t* p = (yyparse_param_t*) yyparse_param;
177        p->ppStackBottom = &yyss;
178        p->ppStackTop    = &yyssp;
179    }
180    
181  // tell bison to spit out verbose syntax error messages  // tell bison to spit out verbose syntax error messages
182  %error-verbose  %error-verbose
# Line 187  command               :  ADD SP add_inst Line 252  command               :  ADD SP add_inst
252                        ;                        ;
253    
254  add_instruction       :  CHANNEL                               { $$ = LSCPSERVER->AddChannel();                  }  add_instruction       :  CHANNEL                               { $$ = LSCPSERVER->AddChannel();                  }
255                          |  CHANNEL SP MIDI_INPUT SP sampler_channel SP device_index                           { $$ = LSCPSERVER->AddChannelMidiInput($5,$7);    }
256                          |  CHANNEL SP MIDI_INPUT SP sampler_channel SP device_index SP midi_input_port_index  { $$ = LSCPSERVER->AddChannelMidiInput($5,$7,$9); }
257                        |  DB_INSTRUMENT_DIRECTORY SP db_path    { $$ = LSCPSERVER->AddDbInstrumentDirectory($3);  }                        |  DB_INSTRUMENT_DIRECTORY SP db_path    { $$ = LSCPSERVER->AddDbInstrumentDirectory($3);  }
258                        |  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);        }
259                        |  DB_INSTRUMENTS SP NON_MODAL SP scan_mode SP FILE_AS_DIR SP db_path SP filename         { $$ = LSCPSERVER->AddDbInstruments($5,$9,$11, true, true); }                        |  DB_INSTRUMENTS SP NON_MODAL SP scan_mode SP FILE_AS_DIR SP db_path SP filename         { $$ = LSCPSERVER->AddDbInstruments($5,$9,$11, true, true); }
# Line 227  subscribe_event       :  AUDIO_OUTPUT_DE Line 294  subscribe_event       :  AUDIO_OUTPUT_DE
294                        |  TOTAL_STREAM_COUNT                    { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_total_stream_count);   }                        |  TOTAL_STREAM_COUNT                    { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_total_stream_count);   }
295                        |  TOTAL_VOICE_COUNT                     { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_total_voice_count);    }                        |  TOTAL_VOICE_COUNT                     { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_total_voice_count);    }
296                        |  GLOBAL_INFO                           { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_global_info);          }                        |  GLOBAL_INFO                           { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_global_info);          }
297                          |  EFFECT_INSTANCE_COUNT                 { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_fx_instance_count);    }
298                          |  EFFECT_INSTANCE_INFO                  { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_fx_instance_info);     }
299                          |  SEND_EFFECT_CHAIN_COUNT               { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_send_fx_chain_count);  }
300                          |  SEND_EFFECT_CHAIN_INFO                { $$ = LSCPSERVER->SubscribeNotification(LSCPEvent::event_send_fx_chain_info);   }
301                        ;                        ;
302    
303  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 255  unsubscribe_event     :  AUDIO_OUTPUT_DE Line 326  unsubscribe_event     :  AUDIO_OUTPUT_DE
326                        |  TOTAL_STREAM_COUNT                    { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_total_stream_count);   }                        |  TOTAL_STREAM_COUNT                    { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_total_stream_count);   }
327                        |  TOTAL_VOICE_COUNT                     { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_total_voice_count);    }                        |  TOTAL_VOICE_COUNT                     { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_total_voice_count);    }
328                        |  GLOBAL_INFO                           { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_global_info);          }                        |  GLOBAL_INFO                           { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_global_info);          }
329                          |  EFFECT_INSTANCE_COUNT                 { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_fx_instance_count);    }
330                          |  EFFECT_INSTANCE_INFO                  { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_fx_instance_info);     }
331                          |  SEND_EFFECT_CHAIN_COUNT               { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_send_fx_chain_count);  }
332                          |  SEND_EFFECT_CHAIN_INFO                { $$ = LSCPSERVER->UnsubscribeNotification(LSCPEvent::event_send_fx_chain_info);   }
333                        ;                        ;
334    
335  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 267  unmap_instruction     :  MIDI_INSTRUMENT Line 342  unmap_instruction     :  MIDI_INSTRUMENT
342                        ;                        ;
343    
344  remove_instruction    :  CHANNEL SP sampler_channel                   { $$ = LSCPSERVER->RemoveChannel($3);                      }  remove_instruction    :  CHANNEL SP sampler_channel                   { $$ = LSCPSERVER->RemoveChannel($3);                      }
345                          |  CHANNEL SP MIDI_INPUT SP sampler_channel                                           { $$ = LSCPSERVER->RemoveChannelMidiInput($5);       }
346                          |  CHANNEL SP MIDI_INPUT SP sampler_channel SP device_index                           { $$ = LSCPSERVER->RemoveChannelMidiInput($5,$7);    }
347                          |  CHANNEL SP MIDI_INPUT SP sampler_channel SP device_index SP midi_input_port_index  { $$ = LSCPSERVER->RemoveChannelMidiInput($5,$7,$9); }
348                        |  MIDI_INSTRUMENT_MAP SP midi_map              { $$ = LSCPSERVER->RemoveMidiInstrumentMap($3);            }                        |  MIDI_INSTRUMENT_MAP SP midi_map              { $$ = LSCPSERVER->RemoveMidiInstrumentMap($3);            }
349                        |  MIDI_INSTRUMENT_MAP SP ALL                   { $$ = LSCPSERVER->RemoveAllMidiInstrumentMaps();          }                        |  MIDI_INSTRUMENT_MAP SP ALL                   { $$ = LSCPSERVER->RemoveAllMidiInstrumentMaps();          }
350                        |  SEND_EFFECT_CHAIN SP device_index SP effect_chain  { $$ = LSCPSERVER->RemoveSendEffectChain($3,$5);     }                        |  SEND_EFFECT_CHAIN SP device_index SP effect_chain  { $$ = LSCPSERVER->RemoveSendEffectChain($3,$5);     }
351                        |  SEND_EFFECT_CHAIN SP EFFECT SP device_index SP effect_chain SP chain_pos  { $$ = LSCPSERVER->RemoveSendEffectChainEffect($5,$7,$9); }                        |  SEND_EFFECT_CHAIN SP EFFECT SP device_index SP effect_chain SP chain_pos  { $$ = LSCPSERVER->RemoveSendEffectChainEffect($5,$7,$9); }
352                        |  FX_SEND SP SEND_EFFECT SP sampler_channel SP fx_send_id  { $$ = LSCPSERVER->SetFxSendEffect($5,$7,-1,-1); }                        |  FX_SEND SP EFFECT SP sampler_channel SP fx_send_id  { $$ = LSCPSERVER->SetFxSendEffect($5,$7,-1,-1);    }
353                        |  DB_INSTRUMENT_DIRECTORY SP FORCE SP db_path  { $$ = LSCPSERVER->RemoveDbInstrumentDirectory($5, true);  }                        |  DB_INSTRUMENT_DIRECTORY SP FORCE SP db_path  { $$ = LSCPSERVER->RemoveDbInstrumentDirectory($5, true);  }
354                        |  DB_INSTRUMENT_DIRECTORY SP db_path           { $$ = LSCPSERVER->RemoveDbInstrumentDirectory($3);        }                        |  DB_INSTRUMENT_DIRECTORY SP db_path           { $$ = LSCPSERVER->RemoveDbInstrumentDirectory($3);        }
355                        |  DB_INSTRUMENT SP db_path                     { $$ = LSCPSERVER->RemoveDbInstrument($3);                 }                        |  DB_INSTRUMENT SP db_path                     { $$ = LSCPSERVER->RemoveDbInstrument($3);                 }
# Line 344  set_instruction       :  AUDIO_OUTPUT_DE Line 422  set_instruction       :  AUDIO_OUTPUT_DE
422                        |  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); }
423                        |  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);              }
424                        |  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);                       }
425                        |  FX_SEND SP SEND_EFFECT SP sampler_channel SP fx_send_id SP effect_chain SP chain_pos  { $$ = LSCPSERVER->SetFxSendEffect($5,$7,$9,$11);             }                        |  FX_SEND SP EFFECT SP sampler_channel SP fx_send_id SP effect_chain SP chain_pos  { $$ = LSCPSERVER->SetFxSendEffect($5,$7,$9,$11);                  }
426                        |  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);            }
427                        |  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);     }
428                        |  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);                     }
429                        |  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);              }
430                        |  DB_INSTRUMENT SP FILE_PATH SP filename SP filename                               { $$ = LSCPSERVER->SetDbInstrumentFilePath($5,$7);                 }                        |  DB_INSTRUMENT SP FILE_PATH SP filename SP filename                               { $$ = LSCPSERVER->SetDbInstrumentFilePath($5,$7);                 }
431                        |  ECHO SP boolean                                                                  { $$ = LSCPSERVER->SetEcho((yyparse_param_t*) yyparse_param, $3);  }                        |  ECHO SP boolean                                                                  { $$ = LSCPSERVER->SetEcho((yyparse_param_t*) yyparse_param, $3);  }
432                          |  SHELL SP INTERACT SP boolean                                                     { $$ = LSCPSERVER->SetShellInteract((yyparse_param_t*) yyparse_param, $5); }
433                        |  VOLUME SP volume_value                                                           { $$ = LSCPSERVER->SetGlobalVolume($3);                            }                        |  VOLUME SP volume_value                                                           { $$ = LSCPSERVER->SetGlobalVolume($3);                            }
434                        |  VOICES SP number                                                                 { $$ = LSCPSERVER->SetGlobalMaxVoices($3);                         }                        |  VOICES SP number                                                                 { $$ = LSCPSERVER->SetGlobalMaxVoices($3);                         }
435                        |  STREAMS SP number                                                                { $$ = LSCPSERVER->SetGlobalMaxStreams($3);                        }                        |  STREAMS SP number                                                                { $$ = LSCPSERVER->SetGlobalMaxStreams($3);                        }
# Line 441  buffer_size_type      :  BYTES       { $ Line 520  buffer_size_type      :  BYTES       { $
520  list_instruction      :  AUDIO_OUTPUT_DEVICES                               { $$ = LSCPSERVER->GetAudioOutputDevices();              }  list_instruction      :  AUDIO_OUTPUT_DEVICES                               { $$ = LSCPSERVER->GetAudioOutputDevices();              }
521                        |  MIDI_INPUT_DEVICES                                 { $$ = LSCPSERVER->GetMidiInputDevices();                }                        |  MIDI_INPUT_DEVICES                                 { $$ = LSCPSERVER->GetMidiInputDevices();                }
522                        |  CHANNELS                                           { $$ = LSCPSERVER->ListChannels();                       }                        |  CHANNELS                                           { $$ = LSCPSERVER->ListChannels();                       }
523                          |  CHANNEL SP MIDI_INPUTS SP sampler_channel          { $$ = LSCPSERVER->ListChannelMidiInputs($5);            }
524                        |  AVAILABLE_ENGINES                                  { $$ = LSCPSERVER->ListAvailableEngines();               }                        |  AVAILABLE_ENGINES                                  { $$ = LSCPSERVER->ListAvailableEngines();               }
525                        |  AVAILABLE_EFFECTS                                  { $$ = LSCPSERVER->ListAvailableEffects();               }                        |  AVAILABLE_EFFECTS                                  { $$ = LSCPSERVER->ListAvailableEffects();               }
526                        |  EFFECT_INSTANCES                                   { $$ = LSCPSERVER->ListEffectInstances();                }                        |  EFFECT_INSTANCES                                   { $$ = LSCPSERVER->ListEffectInstances();                }
# Line 842  REMOVE                :  'R''E''M''O''V' Line 922  REMOVE                :  'R''E''M''O''V'
922  SET                   :  'S''E''T'  SET                   :  'S''E''T'
923                        ;                        ;
924    
925    SHELL                 :  'S''H''E''L''L'
926                          ;
927    
928    INTERACT              :  'I''N''T''E''R''A''C''T'
929                          ;
930    
931  APPEND                :  'A''P''P''E''N''D'  APPEND                :  'A''P''P''E''N''D'
932                        ;                        ;
933    
# Line 950  TOTAL_VOICE_COUNT_MAX:  'T''O''T''A''L'' Line 1036  TOTAL_VOICE_COUNT_MAX:  'T''O''T''A''L''
1036  GLOBAL_INFO          :  'G''L''O''B''A''L''_''I''N''F''O'  GLOBAL_INFO          :  'G''L''O''B''A''L''_''I''N''F''O'
1037                       ;                       ;
1038    
1039    EFFECT_INSTANCE_COUNT   :  'E''F''F''E''C''T''_''I''N''S''T''A''N''C''E''_''C''O''U''N''T'
1040                            ;
1041    
1042    EFFECT_INSTANCE_INFO    :  'E''F''F''E''C''T''_''I''N''S''T''A''N''C''E''_''I''N''F''O'
1043                            ;
1044    
1045    SEND_EFFECT_CHAIN_COUNT :  'S''E''N''D''_''E''F''F''E''C''T''_''C''H''A''I''N''_''C''O''U''N''T'
1046                            ;
1047    
1048    SEND_EFFECT_CHAIN_INFO  :  'S''E''N''D''_''E''F''F''E''C''T''_''C''H''A''I''N''_''I''N''F''O'
1049                            ;
1050    
1051  INSTRUMENT           :  'I''N''S''T''R''U''M''E''N''T'  INSTRUMENT           :  'I''N''S''T''R''U''M''E''N''T'
1052                       ;                       ;
1053    
# Line 1010  EFFECT_INSTANCE_INPUT_CONTROL :  'E''F'' Line 1108  EFFECT_INSTANCE_INPUT_CONTROL :  'E''F''
1108  SEND_EFFECT_CHAIN :  'S''E''N''D''_''E''F''F''E''C''T''_''C''H''A''I''N'  SEND_EFFECT_CHAIN :  'S''E''N''D''_''E''F''F''E''C''T''_''C''H''A''I''N'
1109                    ;                    ;
1110    
 SEND_EFFECT  :  'S''E''N''D''_''E''F''F''E''C''T'  
              ;  
   
1111  SEND_EFFECT_CHAINS :  'S''E''N''D''_''E''F''F''E''C''T''_''C''H''A''I''N''S'  SEND_EFFECT_CHAINS :  'S''E''N''D''_''E''F''F''E''C''T''_''C''H''A''I''N''S'
1112                     ;                     ;
1113    
# Line 1061  MIDI_INPUT_TYPE       :  'M''I''D''I''_' Line 1156  MIDI_INPUT_TYPE       :  'M''I''D''I''_'
1156  MIDI_INPUT            :  'M''I''D''I''_''I''N''P''U''T'  MIDI_INPUT            :  'M''I''D''I''_''I''N''P''U''T'
1157                        ;                        ;
1158    
1159    MIDI_INPUTS           :  'M''I''D''I''_''I''N''P''U''T''S'
1160                          ;
1161    
1162  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'
1163                        ;                        ;
1164    
# Line 1171  QUIT                  :  'Q''U''I''T' Line 1269  QUIT                  :  'Q''U''I''T'
1269    
1270  %%  %%
1271    
1272    #define DEBUG_BISON_SYNTAX_ERROR_WALKER 0
1273    
1274  /**  /**
1275   * Will be called when an error occured (usually syntax error).   * Internal function, only called by yyExpectedSymbols(). It is given a Bison
1276     * parser state stack, reflecting the parser's entire state at a certain point,
1277     * i.e. when a syntax error occured. This function will then walk ahead the
1278     * potential parse tree starting from the current head of the given state
1279     * stack. This function will call itself recursively to scan the individual
1280     * parse tree branches. As soon as it hits on the next non-terminal grammar
1281     * symbol in one parse tree branch, it adds the found non-terminal symbol to
1282     * @a expectedSymbols and aborts scanning the respective tree branch further.
1283     * If any local parser state is reached a second time, the respective parse
1284     * tree is aborted to avoid any endless recursion.
1285     *
1286     * @param stack - Bison (yacc) state stack
1287     * @param expectedSymbols - will be filled with next expected grammar symbols
1288     * @param depth - just for internal debugging purposes
1289     */
1290    static void walkAndFillExpectedSymbols(std::vector<YYTYPE_INT16>& stack, std::set<String>& expectedSymbols, int depth = 0) {
1291    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1292        printf("\n");
1293        for (int i = 0; i < depth; ++i) printf("\t");
1294        printf("State stack:");
1295        for (int i = 0; i < stack.size(); ++i) {
1296            printf(" %d", stack[i]);
1297        }
1298        printf("\n");
1299    #endif
1300    
1301        if (stack.empty()) return;
1302    
1303        int state = stack[stack.size() - 1];
1304        int n = yypact[state];
1305        if (n == YYPACT_NINF) { // default reduction required ...
1306            // get default reduction rule for this state
1307            n = yydefact[state];
1308            if (n <= 0 || n >= YYNRULES) return; // no rule, something is wrong
1309            // return the new resolved expected symbol (left-hand symbol of grammar
1310            // rule), then we're done in this state
1311            expectedSymbols.insert(yytname[yyr1[n]]);
1312            return;
1313        }
1314        if (!(YYPACT_NINF < n && n <= YYLAST)) return;
1315    
1316    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1317        for (int i = 0; i < depth; ++i) printf("\t");
1318        printf("Expected tokens:");
1319    #endif
1320        int begin = n < 0 ? -n : 0;
1321        int checklim = YYLAST - n + 1;
1322        int end = checklim < YYNTOKENS ? checklim : YYNTOKENS;
1323        int rule, action, stackSize;
1324        for (int token = begin; token < end; ++token) {
1325            if (token == YYTERROR || yycheck[n + token] != token) continue;
1326    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1327            printf(" %s", yytname[token]);
1328    #endif
1329    
1330            //if (yycheck[n + token] != token) goto default_reduction;
1331    
1332            action = yytable[n + token];
1333            if (action == 0 || action == YYTABLE_NINF) {
1334    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1335                printf(" (invalid action) "); fflush(stdout);
1336    #endif
1337                continue; // error, ignore
1338            }
1339            if (action < 0) { // reduction with rule -action required ...
1340    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1341                printf(" (reduction) "); fflush(stdout);
1342    #endif
1343                rule = -action;
1344                goto reduce;
1345            }
1346            if (action == YYFINAL) continue; // "accept" state, we don't care about it here
1347    
1348            // "shift" required ...
1349    
1350            if (std::find(stack.begin(), stack.end(), action) != stack.end())
1351                continue; // duplicate state, ignore it to avoid endless recursions
1352    
1353            // "shift" / push the new state on the state stack and call this
1354            // function recursively, and restore the stack after the recurse return
1355            stackSize = stack.size();
1356            stack.push_back(action);
1357            walkAndFillExpectedSymbols( //FIXME: could cause stack overflow (should be a loop instead), is probably fine with our current grammar though
1358                stack, expectedSymbols, depth + 1
1359            );
1360            stack.resize(stackSize); // restore stack
1361            continue;
1362    
1363        //default_reduction: // resolve default reduction for this state
1364        //    printf(" (default red.) "); fflush(stdout);
1365        //    rule = yydefact[state];
1366    
1367        reduce: // "reduce" required
1368    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1369            printf(" (reduce by %d) ", rule); fflush(stdout);
1370    #endif
1371            if (rule == 0 || rule >= YYNRULES) continue; // invalid rule, something is wrong
1372            // store the left-hand symbol of the grammar rule
1373            expectedSymbols.insert(yytname[yyr1[rule]]);
1374    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1375            printf(" (SYM %s) ", yytname[yyr1[rule]]); fflush(stdout);
1376    #endif
1377        }
1378    #if DEBUG_BISON_SYNTAX_ERROR_WALKER
1379        printf("\n");
1380    #endif
1381    }
1382    
1383    inline static int _yyReduce(std::vector<YYTYPE_INT16>& stack, const int& rule) {
1384        if (stack.empty()) throw 1; // severe error
1385        const int len = yyr2[rule];
1386        stack.resize(stack.size() - len);
1387        YYTYPE_INT16 newState = yypgoto[yyr1[rule] - YYNTOKENS] + stack.back();
1388        if (0 <= newState && newState <= YYLAST && yycheck[newState] == stack.back())
1389            newState = yytable[newState];
1390        else
1391            newState = yydefgoto[yyr1[rule] - YYNTOKENS];
1392        stack.push_back(newState);
1393        return newState;
1394    }
1395    
1396    inline static int _yyDefaultReduce(std::vector<YYTYPE_INT16>& stack) {
1397        if (stack.empty()) throw 2; // severe error
1398        int rule = yydefact[stack.back()];
1399        if (rule <= 0 || rule >= YYNRULES) throw 3; // no rule, something is wrong
1400        return _yyReduce(stack, rule);
1401    }
1402    
1403    #define DEBUG_PUSH_PARSE 0
1404    
1405    static bool yyPushParse(std::vector<YYTYPE_INT16>& stack, char ch) {
1406        startLabel:
1407    
1408    #if DEBUG_PUSH_PARSE
1409        //printf("\n");
1410        //for (int i = 0; i < depth; ++i) printf("\t");
1411        printf("State stack:");
1412        for (int i = 0; i < stack.size(); ++i) {
1413            printf(" %d", stack[i]);
1414        }
1415        printf(" char='%c'(%d)\n", ch, (int)ch);
1416    #endif
1417    
1418        if (stack.empty()) return false;
1419    
1420        int state = stack.back();
1421        int n = yypact[state];
1422        if (n == YYPACT_NINF) { // default reduction required ...
1423    #if DEBUG_PUSH_PARSE
1424            printf("(def reduce 1)\n");
1425    #endif
1426            state = _yyDefaultReduce(stack);
1427            goto startLabel;
1428        }
1429        if (!(YYPACT_NINF < n && n <= YYLAST)) return false;
1430    
1431        YYTYPE_INT16 token = (ch == YYEOF) ? YYEOF : yytranslate[ch];
1432        n += token;
1433        if (n < 0 || YYLAST < n || yycheck[n] != token) {
1434    #if DEBUG_PUSH_PARSE
1435            printf("(def reduce 2) n=%d token=%d\n", n, token);
1436    #endif
1437            state = _yyDefaultReduce(stack);
1438            goto startLabel;
1439        }
1440        int action = yytable[n]; // yytable[yypact[state] + token]
1441        if (action == 0 || action == YYTABLE_NINF) throw 4;
1442        if (action < 0) {
1443    #if DEBUG_PUSH_PARSE
1444            printf("(reduce)\n");
1445    #endif
1446            int rule = -action;
1447            state = _yyReduce(stack, rule);
1448            goto startLabel;
1449        }
1450        if (action == YYFINAL) return true; // final state reached
1451    
1452    #if DEBUG_PUSH_PARSE
1453        printf("(push)\n");
1454    #endif
1455        // push new state
1456        state = action;
1457        stack.push_back(state);
1458        return true;
1459    }
1460    
1461    static bool yyValid(std::vector<YYTYPE_INT16>& stack, char ch) {
1462        try {
1463            return yyPushParse(stack, ch);
1464        } catch (int i) {
1465    #if DEBUG_PUSH_PARSE
1466            printf("exception %d\n", i);
1467    #endif
1468            return false;
1469        } catch (...) {
1470            return false;
1471        }
1472    }
1473    
1474    static int yyValidCharacters(std::vector<YYTYPE_INT16>& stack, const String& line) {
1475        int i;
1476        for (i = 0; i < line.size(); ++i) {
1477            if (!yyValid(stack, line[i])) return i;
1478        }
1479        return i;
1480    }
1481    
1482    /**
1483     * Should only be called on syntax errors: returns a set of non-terminal
1484     * symbols expected to appear now/next, just at the point where the syntax
1485     * error appeared.
1486   */   */
1487  void yyerror(const char* s) {  static std::set<String> yyExpectedSymbols() {
1488        std::set<String> result;
1489      yyparse_param_t* param = GetCurrentYaccSession();      yyparse_param_t* param = GetCurrentYaccSession();
1490      String msg = s      YYTYPE_INT16* ss = (*param->ppStackBottom);
1491          + (" (line:"   + ToString(param->iLine+1))      YYTYPE_INT16* sp = (*param->ppStackTop);
1492          + ( ",column:" + ToString(param->iColumn))      int iStackSize   = sp - ss + 1;
1493          + ")";      // copy and wrap parser's state stack into a convenient STL container
1494      dmsg(2,("LSCPParser: %s\n", msg.c_str()));      std::vector<YYTYPE_INT16> stack;
1495      sLastError = msg;      for (int i = 0; i < iStackSize; ++i) {
1496            stack.push_back(ss[i]);
1497        }
1498        // do the actual parser work
1499        walkAndFillExpectedSymbols(stack, result);
1500        return result;
1501  }  }
1502    
1503  namespace LinuxSampler {  namespace LinuxSampler {
1504    
1505    String lscpParserProcessShellInteraction(String& line, yyparse_param_t* param) {
1506        std::vector<YYTYPE_INT16> stack;
1507        stack.push_back(0); // every Bison symbol stack starts with zero
1508        String l = line + '\n';
1509        int n = yyValidCharacters(stack, l);
1510        String result = line;
1511        result.insert(n <= result.length() ? n : result.length(), LSCP_SHK_GOOD_FRONT);
1512        int code = (n > line.length()) ? LSCP_SHU_COMPLETE : (n < line.length()) ?
1513                   LSCP_SHU_SYNTAX_ERR : LSCP_SHU_INCOMPLETE;
1514        result = "SHU:" + ToString(code) + ":" + result;
1515        //if (n > line.length()) result += " [OK]";
1516    #if DEBUG_PUSH_PARSE
1517        printf("%s\n", result.c_str());
1518    #endif
1519        return result;
1520    }
1521    
1522  /**  /**
1523   * Clears input buffer.   * Clears input buffer.
1524   */   */
# Line 1193  void restart(yyparse_param_t* pparam, in Line 1526  void restart(yyparse_param_t* pparam, in
1526      bytes = 0;      bytes = 0;
1527      ptr   = 0;      ptr   = 0;
1528      sLastError = "";      sLastError = "";
1529        sParsed = "";
1530  }  }
1531    
1532  }  }

Legend:
Removed from v.2137  
changed lines
  Added in v.2515

  ViewVC Help
Powered by ViewVC