Changeset 1230 for proto/parabix2


Ignore:
Timestamp:
Jul 28, 2011, 7:22:06 AM (8 years ago)
Author:
cameron
Message:

Inline error reporting in parabix2_pablo.py

Location:
proto/parabix2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • proto/parabix2/pablo_template.cpp

    r972 r1230  
    2626#include "TagMatcher.h"
    2727#include "LineColTracker.h"
     28
    2829
    2930#ifdef BUFFER_PROFILING
     
    4546int buffer_last;
    4647char * source;
     48
     49
    4750LineColTracker tracker;
     51
     52static inline void ReportError(const char * error_msg, int error_pos_in_block) {
     53  int error_line, error_column;
     54  tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
     55  fprintf(stderr, "%s at line %i, column %i\n", error_msg, error_line, error_column);
     56}
     57
     58class ErrorTracker {
     59public:
     60        ErrorTracker() { noted_pos_in_block = -1;}
     61
     62        inline void NoteError(const char * error_msg, BitBlock err_strm) {
     63          int pos_in_block = count_forward_zeroes(err_strm);
     64          if ((noted_pos_in_block == -1) || (noted_pos_in_block > pos_in_block)) {
     65            noted_pos_in_block = pos_in_block;
     66            noted_error = error_msg;
     67          }
     68        }
     69
     70        inline void If_Error_Report_First() {
     71          if (noted_pos_in_block > -1) {
     72                  int error_line, error_column;
     73                  ReportError(noted_error, noted_pos_in_block);
     74                  exit(-1);
     75          }
     76        }
     77 
     78private:
     79  const char * noted_error;
     80  int noted_pos_in_block;       
     81};
     82
     83
    4884TagMatcher matcher;
    4985BitBlock EOF_mask = simd_const_1(1);
    5086
     87ErrorTracker error_tracker;
    5188
    5289static inline int StreamScan(ScanBlock * stream, int blk_count, int ProcessPos(int)) {
     
    66103}
    67104
    68 
    69 static inline void ReportError(const char * error_msg, int error_pos_in_block) {
    70   int error_line, error_column;
    71   tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
    72   fprintf(stderr, "%s at line %i, column %i\n", error_msg, error_line, error_column);
    73 }
    74105
    75106
     
    253284                }
    254285
    255                 if (bitblock_has_bit(check_streams.error_mask)) {
    256                   int errpos = count_forward_zeroes(check_streams.error_mask);
    257                   ReportError("error found", errpos);
    258               exit(-1);
    259                 }
     286                error_tracker.If_Error_Report_First();
    260287
    261288                matcher.store_streams(check_streams.tag_marks, check_streams.name_follows, check_streams.misc_mask, chars_avail);
  • proto/parabix2/parabix2_pablo.py

    r1225 r1230  
    4545  xF4_scope = 0
    4646  xEF_scope = 0
    47  
    48   FFFE_FFFF = 0
    49   error = 0
    5047
    5148class Lex ():
     
    7774        Hex = 0
    7875        WS = 0
    79         error = 0
    8076
    8177class Scope1 ():
     
    9793        PI_ends = 0
    9894        CtCDPI_mask = 0
    99         error = 0
    10095
    10196class Ref_Callouts():
     
    106101        HexRef_starts = 0
    107102        HexRef_ends = 0
    108         error = 0
    109103
    110104class Tag_Callouts():
     
    118112        EmptyTag_marks = 0
    119113        EndTag_marks = 0
    120         error = 0
    121114       
    122115class Basis_bits():     
     
    137130        name_follows = 0
    138131        att_refs = 0
    139         error_mask = 0
    140132
    141133class Xml_names():
     
    235227        temp65 = (temp64 & temp60);
    236228        lex.Hex = (temp62 | temp65);
    237         lex.error = x00_x1F &~ lex.WS
     229        lex_error = x00_x1F &~ lex.WS
     230        if lex_error & EOF_mask:
     231                error_tracker.NoteError("Error: illegal character", lex_error)
     232               
    238233       
    239234        ### Validate_utf8(basis_bits, u8):
    240235        u8.unibyte = (~basis_bits.bit_0);
    241236        u8.suffix = 0
    242         u8.error = 0
    243         u8.FFFE_FFFF = 0
     237        u8_error = 0
     238        u8_FFFE_FFFF = 0
    244239        u8anyscope = 0 #local
    245240        if basis_bits.bit_0:
     
    256251                temp71 = (u8.prefix4 & temp70);
    257252                u8.badprefix = (temp68 | temp71);
    258                 u8.error = u8.badprefix
     253                u8_error = u8.badprefix
    259254                u8.scope22 = bitutil.Advance(u8.prefix2)
    260255                u8anyscope = u8.scope22
     
    292287                        u8error4 = u8.xF4_scope & u8.x90_xBF
    293288       
    294                         u8.error |= u8error1 | u8error2 | u8error3 | u8error4
     289                        u8_error |= u8error1 | u8error2 | u8error3 | u8error4
    295290
    296291                        EF_BF_pending = bitutil.Advance(u8.xEF_scope & u8.xBF)
    297292
    298                         u8.FFFE_FFFF = (EF_BF_pending & (u8.xBE | u8.xBF))
    299         u8mismatch = u8anyscope ^ u8.suffix
    300         u8.error |= u8mismatch
     293                        u8_FFFE_FFFF = (EF_BF_pending & (u8.xBE | u8.xBF))
     294                u8mismatch = u8anyscope ^ u8.suffix
     295                u8_error |= u8mismatch | u8_FFFE_FFFF
     296                if u8_error:
     297                        error_tracker.NoteError("UTF-8 error found", (u8_error))
     298                       
    301299       
    302300def Add_scope_streams(lex, scope1):
     
    324322        ctCDPI_Callouts.PI_ends = 0
    325323        ctCDPI_Callouts.CtCDPI_mask = 0
    326         ctCDPI_Callouts.error = 0
     324        ctCDPI_error = 0
    327325        CtCDPI_starts = 0
    328326        Ct_errors = 0
     
    371369                ctCDPI_Callouts.CtCDPI_mask = bitutil.Advance(ctCDPI_Callouts.CD_ends | ctCDPI_Callouts.Ct_ends | ctCDPI_Callouts.PI_ends) - CtCDPI_starts             
    372370                #ctCDPI_Callouts.error = Ct_ends & ~lex.RAngle | Ct_starts & ~ lex.Hyphen
    373                 ctCDPI_Callouts.error = Ct_errors | ctCDPI_Callouts.Ct_ends & ~lex.RAngle
    374                 ctCDPI_Callouts.error |= bitutil.Advance(ctCDPI_Callouts.PI_name_ends & ~ lex.WS) & ~ PI_end
    375                 ctCDPI_Callouts.error |= ctCDPI_Callouts.PI_name_starts & ctCDPI_Callouts.PI_name_ends
     371                ctCDPI_error = Ct_errors | ctCDPI_Callouts.Ct_ends & ~lex.RAngle
     372                ctCDPI_error |= bitutil.Advance(ctCDPI_Callouts.PI_name_ends & ~ lex.WS) & ~ PI_end
     373                ctCDPI_error |= ctCDPI_Callouts.PI_name_starts & ctCDPI_Callouts.PI_name_ends
    376374                # If any of the Comment, CDATA or PI markups are unterminated, it is an error.
    377                 ctCDPI_Callouts.error |= ctCDPI_Callouts.CtCDPI_mask &~ EOF_mask
     375                ctCDPI_error |= ctCDPI_Callouts.CtCDPI_mask &~ EOF_mask
     376       
     377        if ctCDPI_error:
     378                error_tracker.NoteError("Error in comment, CDATA or processing instruction syntax", ctCDPI_error)
    378379               
    379380        check_streams.misc_mask = (lex.WS | lex.LAngle | (bitutil.Advance(ctCDPI_Callouts.Ct_ends | ctCDPI_Callouts.PI_ends) - (ctCDPI_Callouts.Ct_starts | ctCDPI_Callouts.PI_starts)) | CtCDPI_starts) & EOF_mask
     
    469470                EndTagEnds = bitutil.ScanThru(EndTagEnds, lex.WS)
    470471        ParseError |= EndTagEnds & ~lex.RAngle
    471         tag_Callouts.error = ParseError
     472        if ParseError:
     473                error_tracker.NoteError("Tag parsing error found", (ParseError))
     474               
    472475               
    473476        # Attribute value spans
     
    481484        ref_Callouts.HexRef_starts = 0
    482485        ref_Callouts.HexRef_ends = 0
    483         ref_Callouts.error = 0
     486        ref_error = 0
    484487
    485488        Ref1 = lex.RefStart &~ ctCDPI_Callouts.CtCDPI_mask
     
    503506                ref_ends = ref_Callouts.GenRef_ends | ref_Callouts.DecRef_ends | ref_Callouts.HexRef_ends
    504507                ref_error3 = ref_ends &~ lex.Semicolon
    505                 ref_Callouts.error = ref_error1 | ref_error2 | ref_error3
     508                ref_error = ref_error1 | ref_error2 | ref_error3
     509                if ref_error:
     510                        error_tracker.NoteError("Reference error found", (ref_error))
     511                       
     512
    506513
    507514def Validate_xml_names(ctCDPI_Callouts, ref_Callouts, tag_Callouts, lex, u8, xml_names, check_streams):
     
    521528        colon2_err = bitutil.ScanThru(local_part_start, lex.NameScan &~ lex.Colon) & lex.Colon
    522529        ncname_err = ncname_stream & lex.Colon
    523         xml_names.namespace_error = void_prefix_err | local_part_err | colon2_err | ncname_err
     530        namespace_error = void_prefix_err | local_part_err | colon2_err | ncname_err
     531        if namespace_error:
     532                error_tracker.NoteError("error found", namespace_error)
     533               
    524534                       
    525535        check_streams.non_ascii_name_starts = name_start &~lex.ASCII_name_start
     
    531541           
    532542    # Consolidate and check for errors
    533     check_streams.error_mask = lex.error & EOF_mask | u8.error | u8.FFFE_FFFF | ctCDPI_Callouts.error | tag_Callouts.error | CD_end_error | ref_Callouts.error | xml_names.namespace_error
     543    if CD_end_error:
     544                error_tracker.NoteError("Error: ]]> in text", CD_end_error)
     545               
    534546
    535547    check_streams.tag_marks = tag_Callouts.EmptyTag_marks | tag_Callouts.ElemName_starts | tag_Callouts.EndTag_marks | tag_Callouts.AttName_starts
Note: See TracChangeset for help on using the changeset viewer.