Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.

Commit message:
The JSON parser now reports different start/end line/col for invalid numbers, 
literals, and string literals.

Requested reviews:
  Paul J. Lucas (paul-lucas)

For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/174785

The JSON parser now reports different start/end line/col for invalid numbers, 
literals, and string literals.
-- 
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/174785
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'include/zorba/internal/diagnostic.h'
--- include/zorba/internal/diagnostic.h	2013-06-15 18:13:33 +0000
+++ include/zorba/internal/diagnostic.h	2013-07-15 15:07:34 +0000
@@ -17,11 +17,14 @@
 #ifndef ZORBA_INTERNAL_DIAGNOSTIC_H
 #define ZORBA_INTERNAL_DIAGNOSTIC_H
 
+// standard
 #include <string>
 #include <vector>
 
+// Zorba
 #include <zorba/diagnostic.h>
 
+// local
 #include "ztd.h"
 
 namespace zorba {
@@ -177,7 +180,6 @@
   /**
    * Sets the %location information.
    *
-   * @param file The name of the file where the error occurred.
    * @param line The line number of the file where the error occurred.
    * @param column The column number, if any, of the file where the error
    * occurred.
@@ -185,15 +187,50 @@
    * @param column_end The column number, if any, where the error ends.
    * occurred.
    */
-  void set( char const *file, line_type line, column_type column = 0,
-            line_type line_end = 0, column_type column_end = 0 ) {
-    file_ = file;
+  void set( line_type line, column_type column = 0, line_type line_end = 0,
+            column_type column_end = 0 ) {
     line_ = line;
     column_ = column;
     line_end_ = line_end;
     column_end_ = column_end;
   }
 
+  /**
+   * Sets the %location information.
+   *
+   * @param file The name of the file where the error occurred.
+   * @param line The line number of the file where the error occurred.
+   * @param column The column number, if any, of the file where the error
+   * occurred.
+   * @param line_end The end line of the file where the error occured.
+   * @param column_end The column number, if any, where the error ends.
+   * occurred.
+   */
+  void set( char const *file, line_type line, column_type column = 0,
+            line_type line_end = 0, column_type column_end = 0 ) {
+    file_ = file;
+    set( line, column, line_end, column_end );
+  }
+
+  /**
+   * Sets the %location information.
+   *
+   * @tparam StringType The string type for \a file.
+   * @param file The name of the file where the error occurred.
+   * @param line The line number of the file where the error occurred.
+   * @param column The column number, if any, of the file where the error
+   * occurred.
+   * @param line_end The end line of the file where the error occured.
+   * @param column_end The column number, if any, where the error ends.
+   * occurred.
+   */
+  template<class StringType>
+  typename std::enable_if<ZORBA_HAS_C_STR(StringType),void>::type
+  set( StringType const &file, line_type line, column_type column = 0,
+       line_type line_end = 0, column_type column_end = 0 ) {
+    set( file.c_str(), line, column, line_end, column_end );
+  }
+
 private:
   std::string file_;
   line_type line_;

=== modified file 'src/util/json_parser.cpp'
--- src/util/json_parser.cpp	2013-06-19 14:39:43 +0000
+++ src/util/json_parser.cpp	2013-07-15 15:07:34 +0000
@@ -193,6 +193,10 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
+inline void lexer::set_loc() {
+  cur_loc_.set( line_, col_, line_, col_ );
+}
+
 lexer::lexer( istream &in ) :
   in_( &in ),
   line_( 1 ),
@@ -221,7 +225,7 @@
 
 bool lexer::next( token *t ) {
   while ( true ) {
-    cur_loc_ = cur_loc();
+    set_loc();
     char c;
     if ( !get_char( &c ) )
       return false;
@@ -344,7 +348,7 @@
     if ( !get_char( &c ) || c != *s )
       throw illegal_literal( cur_loc_ );
   }
-  if ( peek_char( &c ) && ascii::is_alnum( c ) )
+  if ( peek_char( &c ) && (ascii::is_alnum( c ) || c == '_') )
     throw illegal_literal( cur_loc_ );
 
   return tt;
@@ -432,7 +436,7 @@
   location const start_loc( cur_loc_ );
 
   while ( true ) {
-    cur_loc_ = cur_loc();
+    set_loc();
     char c;
     if ( !get_char( &c ) )
       throw unterminated_string( start_loc );
@@ -481,10 +485,12 @@
 }
 
 void lexer::set_loc( char const *file, line_type line, column_type col ) {
-  if ( file )
-    file_ = file;
   line_ = line;
   col_ = col;
+  if ( file ) {
+    file_ = file;
+    cur_loc_.set( file, line_, col_, line_, col_ );
+  }
 }
 
 ///////////////////////////////////////////////////////////////////////////////

=== modified file 'src/util/json_parser.h'
--- src/util/json_parser.h	2013-06-19 14:39:43 +0000
+++ src/util/json_parser.h	2013-07-15 15:07:34 +0000
@@ -499,16 +499,13 @@
   void set_loc( char const *file, line_type line, column_type col );
 
 private:
-  location cur_loc() const {
-    return location( file_, line_, col_ );
-  }
-
   bool get_char( char* = nullptr );
   bool peek_char( char* );
   unicode::code_point parse_codepoint();
   token::type parse_literal( char, token::value_type* );
   token::numeric_type parse_number( char, token::value_type* );
   void parse_string( token::value_type* );
+  void set_loc();
 
   std::istream *in_;
   std::string file_;

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to