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

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

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

revision 1245 by schoenebeck, Tue Jun 19 15:54:13 2007 UTC revision 1252 by schoenebeck, Sat Jun 23 15:54:18 2007 UTC
# Line 37  Line 37 
37    
38  // to save us typing work in the rules action definitions  // to save us typing work in the rules action definitions
39  #define LSCPSERVER ((yyparse_param_t*) yyparse_param)->pServer  #define LSCPSERVER ((yyparse_param_t*) yyparse_param)->pServer
40    #define SESSION_PARAM ((yyparse_param_t*) yyparse_param)
41    #define INCREMENT_LINE { SESSION_PARAM->iLine++; SESSION_PARAM->iColumn = 0; }
42    
43  // clears input buffer  // clears input buffer
44  void restart(yyparse_param_t* pparam, int& yychar);  void restart(yyparse_param_t* pparam, int& yychar);
# Line 48  void yyerror(const char* s); Line 50  void yyerror(const char* s);
50  static char buf[1024]; // input buffer to feed the parser with new characters  static char buf[1024]; // input buffer to feed the parser with new characters
51  static int bytes = 0;  // current number of characters in the input buffer  static int bytes = 0;  // current number of characters in the input buffer
52  static int ptr   = 0;  // current position in the input buffer  static int ptr   = 0;  // current position in the input buffer
53    static String sLastError; // error message of the last error occured
54    
55  // external reference to the function which actually reads from the socket  // external reference to the function which actually reads from the socket
56  extern int GetLSCPCommand( void *buf, int max_size);  extern int GetLSCPCommand( void *buf, int max_size);
57    
58    // external reference to the function in lscpserver.cpp which returns the
59    // current session (only works because the server runs as singleton)
60    extern yyparse_param_t* GetCurrentYaccSession();
61    
62  // returns true if supplied characters has an ASCII code of 128 or higher  // returns true if supplied characters has an ASCII code of 128 or higher
63  inline bool isExtendedAsciiChar(const char c) {  inline bool isExtendedAsciiChar(const char c) {
64      return (c < 0);      return (c < 0);
# Line 72  int yylex(YYSTYPE* yylval) { Line 79  int yylex(YYSTYPE* yylval) {
79      }      }
80      // this is the next character in the input stream      // this is the next character in the input stream
81      const char c = buf[ptr++];      const char c = buf[ptr++];
82        // increment current reading position (just for verbosity / messages)
83        GetCurrentYaccSession()->iColumn++;
84      // we have to handle "normal" and "extended" ASCII characters separately      // we have to handle "normal" and "extended" ASCII characters separately
85      if (isExtendedAsciiChar(c)) {      if (isExtendedAsciiChar(c)) {
86          // workaround for characters with ASCII code higher than 127          // workaround for characters with ASCII code higher than 127
# Line 123  int hexsToNumber(char hex_digit0, char h Line 132  int hexsToNumber(char hex_digit0, char h
132    
133  // reentrant parser  // reentrant parser
134  %pure_parser  %pure_parser
135    
136    // tell bison to spit out verbose syntax error messages
137  %error-verbose  %error-verbose
138    
139  %token <Char> EXT_ASCII_CHAR  %token <Char> EXT_ASCII_CHAR
# Line 156  input                 : line LF Line 167  input                 : line LF
167                        ;                        ;
168    
169  line                  :  /* epsilon (empty line ignored) */ { return LSCP_DONE; }  line                  :  /* epsilon (empty line ignored) */ { return LSCP_DONE; }
170                        |  comment  { return LSCP_DONE; }                        |  comment  { INCREMENT_LINE; return LSCP_DONE; }
171                        |  command  { LSCPSERVER->AnswerClient($1); return LSCP_DONE; }                        |  command  { INCREMENT_LINE; LSCPSERVER->AnswerClient($1); return LSCP_DONE; }
172                        |  error    { LSCPSERVER->AnswerClient("ERR:0:Unknown command.\r\n"); RESTART; return LSCP_SYNTAX_ERROR; }                        |  error    { INCREMENT_LINE; LSCPSERVER->AnswerClient("ERR:0:" + sLastError + "\r\n"); RESTART; return LSCP_SYNTAX_ERROR; }
173                        ;                        ;
174    
175  comment               :  '#'  comment               :  '#'
# Line 976  QUIT                  :  'Q''U''I''T' Line 987  QUIT                  :  'Q''U''I''T'
987   * Will be called when an error occured (usually syntax error).   * Will be called when an error occured (usually syntax error).
988   */   */
989  void yyerror(const char* s) {  void yyerror(const char* s) {
990      dmsg(2,("LSCPParser: %s\n", s));      yyparse_param_t* param = GetCurrentYaccSession();
991        String msg = s
992            + (" (line:"   + ToString(param->iLine+1))
993            + ( ",column:" + ToString(param->iColumn))
994            + ")";
995        dmsg(2,("LSCPParser: %s\n", msg.c_str()));
996        sLastError = msg;
997  }  }
998    
999  /**  /**
# Line 985  void yyerror(const char* s) { Line 1002  void yyerror(const char* s) {
1002  void restart(yyparse_param_t* pparam, int& yychar) {  void restart(yyparse_param_t* pparam, int& yychar) {
1003      bytes = 0;      bytes = 0;
1004      ptr   = 0;      ptr   = 0;
1005        sLastError = "";
1006  }  }

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

  ViewVC Help
Powered by ViewVC