Changeset 844


Ignore:
Timestamp:
Dec 19, 2010, 6:26:34 AM (8 years ago)
Author:
cameron
Message:

Unify line/column reporting.

Location:
proto/parabix2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • proto/parabix2/pablo_template.c

    r842 r844  
    6969
    7070
    71 static 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));
     71static inline void ReportError(const char * error_msg, int error_pos_in_block) {
     72  int error_line, error_column;
     73  tracker.get_Line_and_Column(error_pos_in_block, error_line, error_column);
     74  fprintf(stderr, "%s at line %i, column %i\n", error_msg, error_line, error_column);
    7675}
    7776
  • proto/parabix2/parabix2.py

    r681 r844  
    2626
    2727import sys
     28
     29
     30#
     31#
     32#  Prolog/DTD Processing
     33
     34#  Comments, PIs, DTD
     35#
     36#  REX Shallow Parsing
     37#    * DocTypeSPE = '<!DOCTYPE' DocTypeCE?
     38#    * DocTypeCE = DT_IdentSE S? ('[' DT_ItemSE* ']' S?)? '>'?
     39#    * QuoteSE = '"' [^"]* '"' | "'" [^']* "'"
     40#    * DT_IdentSE = S Name (S (Name | QuoteSE))*
     41#    * DocTypeItem ::= MarkupDeclaration | PI | Comment | PEReference | S
     42#    *  MarkupDeclaration ::= '<!' DeclType DeclBody '>'
     43#    * DeclType ::= 'ELEMENT' | 'ATTLIST' | 'ENTITY' | 'NOTATION'
     44#    * PEReference ::= '%' Name ';'
     45#    * MarkupDeclCE = ([^]"'><]+ | QuoteSE)* '>'
     46#
     47
     48# Parse from <! in parallel?  - but < allowed in entity value system literal
     49
     50
     51       
     52        Prolog_Cursor_0 = 1
     53        Prolog_Cursor_1 = ScanTo(Prolog_Cursor_0, LAngleFollow)
     54        Prolog_Cursor = Prolog_Cursor & (lex.CtCD_start | lex.PI_start)
     55        While Prolog_Cursor:
     56                PI_2 = Prolog_Cursor & lex.PI_start
     57                CD_Ct_3 = bitutil.Advance(Prolog_Cursor & ~PI_Cursor)
     58                # Comment parsing
     59                Comment_3 = CD_Ct_3 & lex.Hyphen
     60                DocType_3 = CD_Ct_3 & ~ lex.Hyphen
     61                Ct_starts |= Comment_3
     62                Comment_4 = bitutil.Advance(Ct_3)
     63                Comment_errors |= Comment_4 & ~ lex.Hyphen
     64                Comment_5 = bitutil.Advance(Comment_Cursor)
     65                Comment_end_scan |= Comment_Cursor
     66                Comment_close = bitutil.Advance(bitutil.ScanThru(Comment_5, Comment_end_scan))
     67                Ct_ends |= Ct_close
     68                # PI parsing
     69                PI_3 = bitutil.Advance(PI_Cursor)
     70                PI_namestarts |= PI_3
     71                PI_name_end = bitutil.ScanThru(PI_3, lex.NameScan)
     72                PI_name_ends |= PI_name_end
     73                PI_close = bitutil.ScanThru(PI_name_end, PI_end_scan)
     74                PI_ends |= PI_close
     75               
     76        # DOCTYPE parsing
     77        DocType_10 = bitutil.ScanTo(DocType_3, lex.WS)
     78
     79
     80
     81
     82                Prolog_Cursor = bitutil.ScanTo(bitutil.Advance(Ct_ends, Ct_starts)
     83
     84       
     85
     86
     87
     88
     89
     90
     91
     92
    2893
    2994
  • proto/parabix2/src/LineColTracker.h

    r843 r844  
    2727    inline void AdvanceBlock();
    2828    inline void StoreNewlines(BitBlock newline);
     29    void get_Line_and_Column(int pos_in_block, int & line, int & column);
    2930  private:
    3031    BitBlock BitParallelCounter[MAX_COUNTER_BITS];
     
    4243  blocks_after_last_newline_block = 0;
    4344  last_block_with_newline = simd_const_1(1);
    44   newline_counts = 1;
     45  newline_counts = 0;
    4546}
    4647
     
    6465    blocks_after_last_newline_block++;
    6566}
    66 
    67 int LineColTracker::getLineNumber(int mark_pos){
    68   int lines = 1;
    69   cur_newline = simd_andc(cur_newline, sisd_sfl(simd_const_1(1),sisd_from_int(mark_pos)));
    70  
    71   for(int i=MAX_COUNTER_BITS-1;i<=0;i++)
    72     lines = lines*2 +  bitblock_bit_count(BitParallelCounter[i]);
    73  
    74   if(bitblock_has_bit(cur_newline))
    75     return lines + bitblock_bit_count(cur_newline);
    76   else
    77     return lines;
    78 }
    7967#endif
    80 
    81 int LineColTracker::getColNumber(int mark_pos){
    82   cur_newline = simd_andc(cur_newline, sisd_sfl(simd_const_1(1),sisd_from_int(mark_pos)));
    83   if(bitblock_has_bit(cur_newline))
    84     return mark_pos - (BLOCK_SIZE-count_backward_zeroes(cur_newline))+1;
    85   else
    86     return BLOCK_SIZE*blocks_after_last_newline_block +
    87           count_backward_zeroes(last_block_with_newline) + mark_pos+1;
    88 }
    8968
    9069#ifdef BITBLOCK_BIT_COUNT
     
    9978    blocks_after_last_newline_block++;
    10079}
     80#endif
    10181
    102 int LineColTracker::getLineNumber(int mark_pos){
    103   cur_newline = simd_andc(cur_newline, sisd_sfl(simd_const_1(1),sisd_from_int(mark_pos)));
     82void LineColTracker::get_Line_and_Column(int pos_in_block, int & line, int & column) {
     83  cur_newline = simd_andc(cur_newline, sisd_sfl(simd_const_1(1),sisd_from_int(pos_in_block)));
     84  if(bitblock_has_bit(cur_newline))
     85    column = pos_in_block - (BLOCK_SIZE-count_backward_zeroes(cur_newline))+1;
     86  else
     87    column = BLOCK_SIZE*blocks_after_last_newline_block +
     88             count_backward_zeroes(last_block_with_newline) + pos_in_block+1;
     89
     90#ifndef BITBLOCK_BIT_COUNT
     91  int lines = 0;
     92  for(int i=MAX_COUNTER_BITS-1;i>=0;i--)
     93    lines = lines*2 + bitblock_bit_count(BitParallelCounter[i]);
     94  newline_counts = lines;
     95#endif
    10496 
    10597  if(bitblock_has_bit(cur_newline))
    106     return newline_counts + bitblock_bit_count(cur_newline);
     98    line = newline_counts + bitblock_bit_count(cur_newline) + 1;
    10799  else
    108     return newline_counts;
     100    line = newline_counts + 1;
     101
    109102}
    110 #endif
    111103
    112104
    113105
    114 
    115 
Note: See TracChangeset for help on using the changeset viewer.