Ignore:
Timestamp:
Dec 18, 2010, 3:45:01 PM (9 years ago)
Author:
lindanl
Message:

Report error positions with line/column

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/parabix2/pablo_template.c

    r838 r842  
    4949int buffer_last;
    5050char * source;
     51LineColTracker tracker;
    5152
    5253
     
    6869
    6970
     71static inline void ReportError(const char * errmsg, int error_pos) {
     72  fprintf(stderr, "%s at line %i, column %i\n",
     73          errmsg,
     74          tracker.getLineNumber(error_pos),
     75          tracker.getColNumber(error_pos));
     76}
     77
     78
    7079static inline int NameStrt_check(int pos) {
    7180        int block_pos = block_base + pos;
    7281        if(XML_10_UTF8_NameStrt_bytes((unsigned char*)&source[block_pos]) == 0){
    73               fprintf(stderr, "name start error found at position %i\n",block_pos+buffer_base);
     82              ReportError("name start error", pos);
    7483              exit(-1);
    7584        }
     
    8089        int block_pos = block_base + pos;
    8190        if(XML_10_UTF8_NameChar_bytes((unsigned char*)&source[block_pos]) == 0){
    82               fprintf(stderr, "name error found at position %i\n",block_pos+buffer_base);
     91              ReportError("name error", pos);
    8392              exit(-1);
    8493        }
     
    92101              // "<?xml" legal at start of file.
    93102              if ((file_pos == 2) && at_XmlDecl_start<ASCII>((unsigned char*)&source[0])) return 0;
    94               fprintf(stderr, "[Xx][Mm][Ll] illegal as PI name at position %i\n",file_pos);
     103              ReportError("[Xx][Mm][Ll] illegal as PI name", pos);
    95104              exit(-1);
    96105        }
     
    101110        int block_pos = block_base + pos;
    102111        if (!at_CDATA1<ASCII>((unsigned char*)&source[block_pos])){
    103               fprintf(stderr, "CDATA error found at position %i\n",block_pos+buffer_base);
     112              ReportError("CDATA error", pos);
    104113              exit(-1);
    105114        }
     
    111120        unsigned char* s = (unsigned char*)&source[block_pos];
    112121        if (!(at_Ref_gt<ASCII>(s)||at_Ref_lt<ASCII>(s)||at_Ref_amp<ASCII>(s)||at_Ref_quot<ASCII>(s)||at_Ref_apos<ASCII>(s))){
    113               fprintf(stderr, "Undefined Reference found at position %i\n",block_pos+buffer_base);
     122              ReportError("Undefined reference", pos);
    114123              exit(-1);
    115124        }
     
    124133          ch_val = HexVal<ASCII>(s[0]) + (ch_val<<4);
    125134          if (ch_val> 0x10FFFF ){
    126             fprintf(stderr, "Illegal character reference found at position %i\n",block_pos+buffer_base);
     135            ReportError("Illegal character reference", pos);
    127136            exit(-1);
    128137          }
     
    130139        }
    131140        if ((ch_val == 0x0) || ((ch_val | 0x7FF) == 0xDFFF)|| ((ch_val | 0x1) == 0xFFFF)){
    132           fprintf(stderr, "Illegal character reference found at position %i\n",block_pos+buffer_base);
     141          ReportError("Illegal character reference", pos);
    133142          exit(-1);
    134143        }
    135144        else if (((ch_val < 0x20) && (ch_val != 0x9) && (ch_val != 0xD) && (ch_val != 0xA))){
    136           fprintf(stderr, "Illegal XML 1.0 character reference found at position %i\n",block_pos+buffer_base);
     145          ReportError("Illegal XML 1.0 character reference", pos);
    137146          exit(-1);
    138147        }
     
    147156          ch_val = DigitVal<ASCII>(s[0]) + ch_val*10;
    148157          if (ch_val> 0x10FFFF ){
    149             fprintf(stderr, "Illegal character reference found at position %i\n",block_pos+buffer_base);
     158            ReportError("Illegal character reference", pos);
    150159            exit(-1);
    151160          }
     
    153162        }
    154163        if ((ch_val == 0x0) || ((ch_val | 0x7FF) == 0xDFFF)|| ((ch_val | 0x1) == 0xFFFF)){
    155           fprintf(stderr, "Illegal character reference found at position %i\n",block_pos+buffer_base);
     164          ReportError("Illegal character reference", pos);
    156165          exit(-1);
    157166        }
    158167        else if (((ch_val < 0x20) && (ch_val != 0x9) && (ch_val != 0xD) && (ch_val != 0xA))){
    159           fprintf(stderr, "Illegal XML 1.0 character reference found at position %i\n",block_pos+buffer_base);
     168          ReportError("Illegal XML 1.0 character reference", pos);
    160169          exit(-1);
    161170        }
     
    183192          }
    184193          if (ch_val==60){
    185             fprintf(stderr, "Attribute values contain '<' characters after reference expansion at position %i\n",block_pos+buffer_base);
     194            ReportError("Attribute values contain '<' characters after reference expansion", pos);
    186195            exit(-1);
    187196          }       
    188197        }
    189198        else if(at_Ref_lt<ASCII>(s)){
    190           fprintf(stderr, "Attribute values contain '<' characters after reference expansion at position %i\n",block_pos+buffer_base);
     199          ReportError("Attribute values contain '<' characters after reference expansion", pos);
    191200          exit(-1);
    192201        }         
     
    200209
    201210
    202   LineColTracker tracker;
    203211
    204212  BytePack U8[8];
     
    326334
    327335        if (bitblock_has_bit(error_mask)) {
    328           fprintf(stderr, "error found at line %i, column %i\n",tracker.getLineNumber(error_mask), tracker.getColNumber(error_mask));
     336          int errpos = count_forward_zeroes(error_mask);
     337          ReportError("error found", errpos);
    329338          exit(-1);
    330339        }
     
    379388       
    380389        if (bitblock_has_bit(error_mask)) {
    381           fprintf(stderr, "error found at line %i, column %i\n",tracker.getLineNumber(error_mask), tracker.getColNumber(error_mask));
     390          int errpos = count_forward_zeroes(error_mask);
     391          ReportError("error found", errpos);
    382392          exit(-1);
    383393        }
Note: See TracChangeset for help on using the changeset viewer.