ALDT (Arnulf's LaTeX Documentation Tool)

Check-in [eaf5e42fca]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:fixes for parsing
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:eaf5e42fca0008b0cded831b2dbb19b17d0f20ef
User & Date: arnulf 2012-09-01 16:20:05
Context
2012-09-01
18:46
fixes and new code check-in: b040be3522 user: arnulf tags: trunk
16:20
fixes for parsing check-in: eaf5e42fca user: arnulf tags: trunk
14:15
fixes check-in: fc88728dc3 user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Parse.tcl.

46
47
48
49
50
51
52


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
...
103
104
105
106
107
108
109
110
111
112
113
114
115

116
117

118
119
120
121
122
123
124
...
201
202
203
204
205
206
207

208
209

210
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
...
263
264
265
266
267
268
269
270
271
272
273
274

275
276
277
278
279
280
281
...
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
...
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
...
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
...
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
...
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
...
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824

825
826
827
828

829
830
831
832
833
834
835
...
867
868
869
870
871
872
873
874
875
876
877
878
879






880
















  public method getText {}
  public method getToken {}
  public method getParseInfo {}
  public method getParseResult {}
  public method getEof {}
  private method feedCharStart {}
  private method feedChar {}


}

::itcl::body Parse::constructor {args} {
   set debug 0
   set no_exp_parsing false
   set parse_info ""
   set parse_result ""
 }

::itcl::body Parse::parserInit {code len line_no} {
puts "parserInit!"
    set parse_info [uplevel #0 [list ::Parser::ParseInfo #auto $code $len $line_no]]
    set parse_result [uplevel #0 ::Parser::ParseResult #auto]
    $parse_info setCur "\n"
    if {$len > 0} {
      feedCharStart
    } else {
      $parse_info setEof true
................................................................................
      }
      $parse_info setEof true
      return true
    }
#puts "cur![$parse_info getCur]!"
    switch [$parse_info getCur] {
    "\\" {
      if {[lindex [$parse_info getText] [expr {[$parse_info getIndex] + 1}]] eq "\n" && [$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"]} {
        return [parseWordSep];
      } else {
        if {[lindex [$parse_info getText] [expr {[$parse_info getIndex] + 1}]] eq "\\" && [$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"]} {
          $parse_info setWordSep false
          $parse_info setComment false

          feedchar
          $parse_info setEnd [expr {[$parse_info getIndex] - 1}]

          $parse_info setToken [::Parser::Token::string2Token "TOKEN_LINE_SEP"]
          return true
        }
	if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"]} {
          $parse_info setComment false
          set ret [parseTagName]
          return $ret
................................................................................
      }
      $parse_info setComment false
      return [parseParen]
      }
    "&" {
      $parse_info setWordSep false
      $parse_info setComment false

      $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
      $parse_info setToken [::Parser::Token::string2Token "TOKEN_AMPERSAND"]

      return true
      }
    "%" {
      $parse_info setWordSep false
      if {[$parse_info getComment]} {
        return [parseComment]
      } else {
        return [parseString]
      }

      }
    default {
      $parse_info setArgument false
      $parse_info setWordSep false
      $parse_info setComment false
      set ret [parseString]
      return $ret
................................................................................
# ==================== parseWordSep ===================================== */
::itcl::body Parse::parseWordSep {} {
  $parse_info setWordSep true
  $parse_info setStart [$parse_info getIndex]
  while {([expr {[$parse_info getCur] in [list " " "\t" "\r" "\\"]}]) && ([$parse_info getLen] > 0)} {
    if {[$parse_info getCur] eq "\\"} {
      if {[$parse_info getLen] > 0} {
        if {[string range [$parse_info getText] [expr {[$parse_info getIndex] + 1}] [expr {[$parse_info getIndex] + 1}]] eq "\n"} {
          feedChar
        } else {
          break
        }
      } else {
        break
      }
................................................................................
  $parse_info setToken [::Parser::Token::string2Token "TOKEN_WORD_SEP"]
  return true
}

# ==================== parseTagName ===================================== */
::itcl::body Parse::parseTagName {} {
  $parse_info setStart [$parse_info getIndex]
  $parse_info setLine [$parse_info getLineNo]
  $parse_info setToken [::Parser::Token::string2Token "TOKEN_TAG_NAME"]
  $parse_info setArgument true
  $parse_info setWordSep true
  feedChar

  while {[$parse_info getLen] > 0} {
    switch [$parse_info getCur] {
    "\{" -
    "\[" -
    "\(" -
    "\t" -
    "\r" -
................................................................................
    # Skip the brace
    feedChar
    while {[$parse_info getLen] >= 0} {
#puts "parseSubBrace2![$parse_info getCur]![$parse_info getLen]!"
      switch [$parse_info getCur] {
      "\\" {
        if {[$parse_info getLen] > 1} {
          if {[string range [$parse_info getText] [expr {[$parse_info getIndex] + 1}] [expr {[$parse_info getIndex] + 1}]] == "\n"} {
            $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
          }
          feedChar
        }
        }
      "\{" {
	set level [expr {$level + 1}]
................................................................................
      $parse_info setEof true
      return [::Parser::Token::string2Token "TOKEN_EOL"]
    }
    while {[$parse_info getLen] > 0} {
      switch [$parse_info getCur] {
      "%" {
        if {[$parse_info getLen] > 1} {
          if {[string range [$parse_info getText] [expr {[$parse_info getIndex] + 1}] [expr {[$parse_info getIndex] + 1}]] == "\n"} {
            $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
          }
          feedChar
          set token "TOKEN_QUOTE_ESC"
        }
        }
      "\"" {
................................................................................

    # Skip the bracket
    feedChar
    while {[$parse_info getLen] >= 0} {
      switch [$parse_info getCur] {
      "\\" {
        if {[$parse_info getLen] > 1} {
          if {[string range [$parse_info getText] [expr {[$parse_info getIndex] + 1}] [expr {[$parse_info getIndex] + 1}]] == "\n"} {
            $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
          }
          feedChar
        }
        }
      "\[" {
        set level [expr {$level + 1}];
................................................................................

    # Skip the bracket
    feedChar
    while {[$parse_info getLen] >= 0} {
      switch [$parse_info getCur] {
      "\\" {
        if {[$parse_info getLen] > 1} {
          if {[string range [$parse_info getText] [expr {[$parse_info getIndex] + 1}] [expr {[$parse_info getIndex] + 1}]] == "\n"} {
            $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
          }
          feedChar
        }
        }
      "\(" {
        set level [expr {$level + 1}];
................................................................................
          $parse_result setMissingLine [$parse_info getLine]
        }
      }
    }
    $parse_info setStart [$parse_info getIndex]
    $parse_info setLine [$parse_info getLineNo]
    while {true} {
#puts "+++parseString1![string range [$parse_info getText] [$parse_info getIndex] [$parse_info getIndex]]![$parse_info getLen]!"
      if {[$parse_info getLen] <= 0} {
puts "parseString eof![$parse_info getState]!"
        $parse_info setEof true
        if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_QUOTE"]} {
          if {[$parse_info getCur] ne "\""} {
            $parse_result setMissing "\""
            return false
................................................................................
        }
        return true
      }
#puts "parseString parse_info.cur![$parse_info getCur]!"
      set is_special_char true
      switch [$parse_info getCur] {
      "\\" {
        if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"] [string range [$parse_info getText] [expr {[$parse_info getIndex] + 1}] [expr {[$parse_info getIndex] + 1}]] == "\n"} {
          $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
          if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_QUOTE"]} {
            $parse_info setToken [::Parse::token::string2Token "TOKEN_QUOTE_ESC"]
          } else {
            $parse_info setToken [::Parse::token::string2Token "TOKEN_ESC"]
          }
          return true
        }
        if {[$parse_info getLen] >= 2} {
          if {[string range [$parse_info getText] [expr {[$parse_info getIndex] + 1}] [expr {[$parse_info getIndex] + 1}]] eq "\\"} {
            $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
            if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_QUOTE"]} {
              $parse_info setToken [::Parser::Token::string2Token "TOKEN_QUOTE_ESC"]
            } else {
              $parse_info setToken [::Parser::Token::string2Token "TOKEN_ESC"]
            }
	    return true

          }
          if {[string range [$parse_info getText] [expr {[$parse_info getIndex] + 1}] [expr {[$parse_info getIndex] + 1}]] eq "\n"} {
            $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
          }
          feedChar
        }
        }
      "(" {
        # just keep going
................................................................................

  # ==================== parseComment ===================================== 
::itcl::body Parse::parseComment {} {
    $parse_info setStart [$parse_info getIndex]
    $parse_info setEnd [$parse_info getStart]
    $parse_info setLine [$parse_info getLineNo]
    $parse_info setToken [::Parser::Token::string2Token "TOKEN_COMMENT"]
#puts "parseComment![$parse_info getLen]![string range [$parse_info getText] [$parse_info getIndex] [$parse_info getIndex]]!"
    while {$parse_info getLen] > 0} {
#puts "parseComment2!"+parse_info.len+"!"+parse_info.text.charAt(parse_info.index)+"!");
      if {[$parse_info getCur] eq "\n"} {
        $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
        if {[string range [$parse_info getText] [expr {[$parse_info getIndex] - 1}] [expr {[$parse_info getIndex] - 1}] ne "\\"} {
          $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
#puts "parseComment3![$parse_info getLen]![string range [$parse_info getText] [$parse_info getIndex] [$parse_info getIndex]]!"
          feedChar
          return true
        }

      }
      feedChar
    }
    $parse_info setEnd [$parse_info getIndex]

    return true
  }


# ==================== getText ===================================== 
::itcl::body Parse::getText {} {
  return [string range [$parse_info getText] [$parse_info getStart] [$parse_info getEnd]]
................................................................................

# ==================== feedChar ===================================== 
::itcl::body Parse::feedChar {} {
  $parse_info setIndex [expr {[$parse_info getIndex] + 1}]
  $parse_info setLen [expr {[$parse_info getLen] -1}]
  if {[$parse_info getLen] < 0} {
#      throw new PanicException("End of file reached");
    puts stderr "PANIC! End of file reached"
  }
  $parse_info setCur [string range [$parse_info getText] [$parse_info getIndex] [$parse_info getIndex]]
#puts "FDCH![$parse_info getLen]![$parse_info getIndex]![$parse_info getCur]![getText]!"
}







}























>
>










|







 







|


|


>
|
|
>







 







>
|

>




|

|
|
<
>







 







|







 







<




>







 







|







 







|







 







|







 







|







 







|







 







|









|









|







 







|
|


|
<

|
<


>




>







 







|





>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
...
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223

224
225
226
227
228
229
230
231
...
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
...
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283
284
285
286
287
...
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
...
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
...
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
...
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
...
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
...
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
...
813
814
815
816
817
818
819
820
821
822
823
824

825
826

827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
...
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
  public method getText {}
  public method getToken {}
  public method getParseInfo {}
  public method getParseResult {}
  public method getEof {}
  private method feedCharStart {}
  private method feedChar {}
  private method getNextChar {}
  private method getLastChar {}
}

::itcl::body Parse::constructor {args} {
   set debug 0
   set no_exp_parsing false
   set parse_info ""
   set parse_result ""
 }

::itcl::body Parse::parserInit {code len line_no} {
#puts "parserInit!"
    set parse_info [uplevel #0 [list ::Parser::ParseInfo #auto $code $len $line_no]]
    set parse_result [uplevel #0 ::Parser::ParseResult #auto]
    $parse_info setCur "\n"
    if {$len > 0} {
      feedCharStart
    } else {
      $parse_info setEof true
................................................................................
      }
      $parse_info setEof true
      return true
    }
#puts "cur![$parse_info getCur]!"
    switch [$parse_info getCur] {
    "\\" {
      if {[getNextChar] eq "\n" && [$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"]} {
        return [parseWordSep];
      } else {
        if {[getNextChar] eq "\\" && [$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"]} {
          $parse_info setWordSep false
          $parse_info setComment false
          $parse_info setStart [$parse_info getIndex]
          feedChar
          $parse_info setEnd [$parse_info getIndex]
          feedChar
          $parse_info setToken [::Parser::Token::string2Token "TOKEN_LINE_SEP"]
          return true
        }
	if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"]} {
          $parse_info setComment false
          set ret [parseTagName]
          return $ret
................................................................................
      }
      $parse_info setComment false
      return [parseParen]
      }
    "&" {
      $parse_info setWordSep false
      $parse_info setComment false
      $parse_info setStart [$parse_info getIndex]
      $parse_info setEnd [$parse_info getIndex]
      $parse_info setToken [::Parser::Token::string2Token "TOKEN_AMPERSAND"]
      feedChar
      return true
      }
    "%" {
      $parse_info setWordSep false
#      if {[$parse_info getComment]} {
        return [parseComment]
#      } else {
#        return [parseString]

#      }
      }
    default {
      $parse_info setArgument false
      $parse_info setWordSep false
      $parse_info setComment false
      set ret [parseString]
      return $ret
................................................................................
# ==================== parseWordSep ===================================== */
::itcl::body Parse::parseWordSep {} {
  $parse_info setWordSep true
  $parse_info setStart [$parse_info getIndex]
  while {([expr {[$parse_info getCur] in [list " " "\t" "\r" "\\"]}]) && ([$parse_info getLen] > 0)} {
    if {[$parse_info getCur] eq "\\"} {
      if {[$parse_info getLen] > 0} {
        if {[getNextChar] eq "\n"} {
          feedChar
        } else {
          break
        }
      } else {
        break
      }
................................................................................
  $parse_info setToken [::Parser::Token::string2Token "TOKEN_WORD_SEP"]
  return true
}

# ==================== parseTagName ===================================== */
::itcl::body Parse::parseTagName {} {
  $parse_info setStart [$parse_info getIndex]

  $parse_info setToken [::Parser::Token::string2Token "TOKEN_TAG_NAME"]
  $parse_info setArgument true
  $parse_info setWordSep true
  feedChar
  $parse_info setLine [$parse_info getLineNo]
  while {[$parse_info getLen] > 0} {
    switch [$parse_info getCur] {
    "\{" -
    "\[" -
    "\(" -
    "\t" -
    "\r" -
................................................................................
    # Skip the brace
    feedChar
    while {[$parse_info getLen] >= 0} {
#puts "parseSubBrace2![$parse_info getCur]![$parse_info getLen]!"
      switch [$parse_info getCur] {
      "\\" {
        if {[$parse_info getLen] > 1} {
          if {[getNextChar] == "\n"} {
            $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
          }
          feedChar
        }
        }
      "\{" {
	set level [expr {$level + 1}]
................................................................................
      $parse_info setEof true
      return [::Parser::Token::string2Token "TOKEN_EOL"]
    }
    while {[$parse_info getLen] > 0} {
      switch [$parse_info getCur] {
      "%" {
        if {[$parse_info getLen] > 1} {
          if {[getNextChar] == "\n"} {
            $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
          }
          feedChar
          set token "TOKEN_QUOTE_ESC"
        }
        }
      "\"" {
................................................................................

    # Skip the bracket
    feedChar
    while {[$parse_info getLen] >= 0} {
      switch [$parse_info getCur] {
      "\\" {
        if {[$parse_info getLen] > 1} {
          if {[getNextChar] == "\n"} {
            $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
          }
          feedChar
        }
        }
      "\[" {
        set level [expr {$level + 1}];
................................................................................

    # Skip the bracket
    feedChar
    while {[$parse_info getLen] >= 0} {
      switch [$parse_info getCur] {
      "\\" {
        if {[$parse_info getLen] > 1} {
          if {[getNextChar] == "\n"} {
            $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
          }
          feedChar
        }
        }
      "\(" {
        set level [expr {$level + 1}];
................................................................................
          $parse_result setMissingLine [$parse_info getLine]
        }
      }
    }
    $parse_info setStart [$parse_info getIndex]
    $parse_info setLine [$parse_info getLineNo]
    while {true} {
#puts "+++parseString1![[$parse_info getCur]![$parse_info getLen]!"
      if {[$parse_info getLen] <= 0} {
puts "parseString eof![$parse_info getState]!"
        $parse_info setEof true
        if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_QUOTE"]} {
          if {[$parse_info getCur] ne "\""} {
            $parse_result setMissing "\""
            return false
................................................................................
        }
        return true
      }
#puts "parseString parse_info.cur![$parse_info getCur]!"
      set is_special_char true
      switch [$parse_info getCur] {
      "\\" {
        if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"] [getNextChar] == "\n"} {
          $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
          if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_QUOTE"]} {
            $parse_info setToken [::Parse::token::string2Token "TOKEN_QUOTE_ESC"]
          } else {
            $parse_info setToken [::Parse::token::string2Token "TOKEN_ESC"]
          }
          return true
        }
        if {[$parse_info getLen] >= 2} {
          if {[getNextChar] eq "\\"} {
            $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
            if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_QUOTE"]} {
              $parse_info setToken [::Parser::Token::string2Token "TOKEN_QUOTE_ESC"]
            } else {
              $parse_info setToken [::Parser::Token::string2Token "TOKEN_ESC"]
            }
	    return true

          }
          if {[getNextChar] eq "\n"} {
            $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
          }
          feedChar
        }
        }
      "(" {
        # just keep going
................................................................................

  # ==================== parseComment ===================================== 
::itcl::body Parse::parseComment {} {
    $parse_info setStart [$parse_info getIndex]
    $parse_info setEnd [$parse_info getStart]
    $parse_info setLine [$parse_info getLineNo]
    $parse_info setToken [::Parser::Token::string2Token "TOKEN_COMMENT"]
#puts "parseComment![$parse_info getLen]![$parse_info getCur]]!"
    while {[$parse_info getLen] > 0} {
#puts "parseComment2!"+parse_info.len+"!"+parse_info.text.charAt(parse_info.index)+"!");
      if {[$parse_info getCur] eq "\n"} {
        if {[getLastChar] ne "\\"} {

          $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
#puts "parseComment3![$parse_info getLen]![$parse_info getCur]!"

          return true
        }
        $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
      }
      feedChar
    }
    $parse_info setEnd [$parse_info getIndex]
#puts "parseComment4![$parse_info getLen]![$parse_info getCur]!"
    return true
  }


# ==================== getText ===================================== 
::itcl::body Parse::getText {} {
  return [string range [$parse_info getText] [$parse_info getStart] [$parse_info getEnd]]
................................................................................

# ==================== feedChar ===================================== 
::itcl::body Parse::feedChar {} {
  $parse_info setIndex [expr {[$parse_info getIndex] + 1}]
  $parse_info setLen [expr {[$parse_info getLen] -1}]
  if {[$parse_info getLen] < 0} {
#      throw new PanicException("End of file reached");
    puts stderr "PANIC! feedChar End of file reached"
  }
  $parse_info setCur [string range [$parse_info getText] [$parse_info getIndex] [$parse_info getIndex]]
#puts "FDCH![$parse_info getLen]![$parse_info getIndex]![$parse_info getCur]![getText]!"
}

# ==================== getNextChar ===================================== 
::itcl::body Parse::getNextChar {} {
   set txt [$parse_info getText]
   set idx [$parse_info getIndex]
   if {[expr {$idx + 1}] > [string length $txt]} {
    puts stderr "PANIC! getIndexNextChar End of file reached"
   }
   set start [expr {$idx + 1}]
   return [string range $txt $start $start]
}

# ==================== getLastChar ===================================== 
::itcl::body Parse::getLastChar {} {
   set txt [$parse_info getText]
   set idx [$parse_info getIndex]
   if {[expr {$idx - 1}] > [string length $txt]} {
    puts stderr "PANIC! getIndexLastChar End of file reached"
   }
   set start [expr {$idx - 1}]
   return [string range $txt $start $start]
}

}

Changes to ParseInfo.tcl.

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  public method getTagName {}
  public method setWordSep {val}
  public method getWordSep {}

}

::itcl::body ParseInfo::constructor {code code_len l_no} {
puts "ParseInfo::constructor!$code!$code_len!$l_no!"
    incr oid
    set id $oid
    set text        $code
    set len         $code_len
    set start       0
    set end         0
    set line_no     $l_no







|







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  public method getTagName {}
  public method setWordSep {val}
  public method getWordSep {}

}

::itcl::body ParseInfo::constructor {code code_len l_no} {
#puts "ParseInfo::constructor!$code!$code_len!$l_no!"
    incr oid
    set id $oid
    set text        $code
    set len         $code_len
    set start       0
    set end         0
    set line_no     $l_no

Changes to Script.tcl.

179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
...
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
    if {$debug_script_tokens > 0} {
      puts "======== Tokens ======"
      set i 0
      foreach parse_token $parse_token_list {
        if {$debug_script_tokens > 1} {
          puts "\[$i\]@![$parse_token toDebugString]!"
        } else {
          puts "\[$i\]@![$parse_token toString]"
        }
#        print("["+i+"]@"+parse_token_info.line+" "+getTokenString(parse_token_info.token)+" '"+script.text.substring(parse_token_info.start, parse_token_info.start + parse_token_info.len)+"'");
        incr i
      }
      puts "======== Tokens END ======"
    }
    # May need up to one extra script token for each EOL in the worst case
    set count [llength $parse_token_list]
    set i 0
................................................................................
    }
    set token_idx 0
    # This is the first token for the current command
    set token_list_idx 0
    set line_first_idx $token_idx
    incr token_idx
    while {$token_list_idx < [llength $parse_token_list]} {
puts "token_list_idx!$token_list_idx![llength $parse_token_list]!"
      # Look ahead to find out how many tokens make up the next word
      set word_tokens 0

      set parse_token [lindex $parse_token_list $token_list_idx]
#puts "11\[$token_list_idx\]@[$parse_token getLine] [$script getTokenString [$parse_token_info getToken]] '[string range [$script getText] [$parse_token_info getStart] ([expr {[$parse_token_info getStart] + [$parse_token_info getLen]}])]'"
      # Skip any leading separators 
      while {[$parse_token getToken] == [::Parser::Token::string2Token "TOKEN_WORD_SEP"]} {
        incr token_list_idx
        set parse_token [lindex $parse_token_list $token_list_idx]
      }
      set word_tokens [countWordTokens $token_list_idx]
puts "word_tokens!$word_tokens!"
      if {$word_tokens == 0} {
        # None, so at end of line
        if {$line_args > 0} {
          set my_token_info [lindex [$script_object getTokens] $line_first_idx]
          $my_token_info setToken [::Parser::Token::string2Token "TOKEN_LINE"]
          $my_token_info setObjPtr [$::Interp::script_line_obj_type newScriptLineObject $line_args $line_no]
          [$my_token_info getObjPtr] incrRefCount "I_SCRIPT_1"
................................................................................
          set line_no [[lindex $parse_token_list $token_list_idx] getLine]
        }
        incr line_args

        # Add each non-separator word token to the line
        while {$word_tokens > 0} {
          incr word_tokens -1
puts "word_tokens!$word_tokens!"
          set parse_token [lindex $parse_token_list $token_list_idx]
          incr token_list_idx
          set script_token [lindex [$script_object getTokens] $token_idx]
          $script_token setToken [$parse_token getToken]
          # put the token info into a new string obj in the bytes part
          $script_token setObjPtr [$::Interp::script_obj_type makeScriptObj $parse_token $text]
          [$script_token getObjPtr] incrRefCount "I_SCRIPT_3"







|

|







 







|











|







 







|







179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
...
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
    if {$debug_script_tokens > 0} {
      puts "======== Tokens ======"
      set i 0
      foreach parse_token $parse_token_list {
        if {$debug_script_tokens > 1} {
          puts "\[$i\]@![$parse_token toDebugString]!"
        } else {
          puts "\[$i\]@![$parse_token toString]![$parse_token getLine]!"
        }
#        puts "\[$i\]@[$parse_token getLine] [::Parser::Token::token2String [$parse_token getToken]] '[string range [$script getText] [$parse_token_info getStart] [expr {[$parse_token getStart] + [$parse_token getLen]}]]'"
        incr i
      }
      puts "======== Tokens END ======"
    }
    # May need up to one extra script token for each EOL in the worst case
    set count [llength $parse_token_list]
    set i 0
................................................................................
    }
    set token_idx 0
    # This is the first token for the current command
    set token_list_idx 0
    set line_first_idx $token_idx
    incr token_idx
    while {$token_list_idx < [llength $parse_token_list]} {
#puts "token_list_idx!$token_list_idx![llength $parse_token_list]!"
      # Look ahead to find out how many tokens make up the next word
      set word_tokens 0

      set parse_token [lindex $parse_token_list $token_list_idx]
#puts "11\[$token_list_idx\]@[$parse_token getLine] [$script getTokenString [$parse_token_info getToken]] '[string range [$script getText] [$parse_token_info getStart] ([expr {[$parse_token_info getStart] + [$parse_token_info getLen]}])]'"
      # Skip any leading separators 
      while {[$parse_token getToken] == [::Parser::Token::string2Token "TOKEN_WORD_SEP"]} {
        incr token_list_idx
        set parse_token [lindex $parse_token_list $token_list_idx]
      }
      set word_tokens [countWordTokens $token_list_idx]
#puts "TOK![::Parser::Token::token2String [$parse_token getToken]]!word_tokens!$word_tokens!$line_args!$line_no!"
      if {$word_tokens == 0} {
        # None, so at end of line
        if {$line_args > 0} {
          set my_token_info [lindex [$script_object getTokens] $line_first_idx]
          $my_token_info setToken [::Parser::Token::string2Token "TOKEN_LINE"]
          $my_token_info setObjPtr [$::Interp::script_line_obj_type newScriptLineObject $line_args $line_no]
          [$my_token_info getObjPtr] incrRefCount "I_SCRIPT_1"
................................................................................
          set line_no [[lindex $parse_token_list $token_list_idx] getLine]
        }
        incr line_args

        # Add each non-separator word token to the line
        while {$word_tokens > 0} {
          incr word_tokens -1
#puts "word_tokens!$word_tokens!"
          set parse_token [lindex $parse_token_list $token_list_idx]
          incr token_list_idx
          set script_token [lindex [$script_object getTokens] $token_idx]
          $script_token setToken [$parse_token getToken]
          # put the token info into a new string obj in the bytes part
          $script_token setObjPtr [$::Interp::script_obj_type makeScriptObj $parse_token $text]
          [$script_token getObjPtr] incrRefCount "I_SCRIPT_3"

Changes to StringObjType.tcl.

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  }

  # ==================== newStringObj ================================== 
  # len is in bytes -- see also newStringObjUtf8() 
::itcl::body StringObjType::newStringObj {str len where} {
    set obj_ptr [uplevel #0 ::Parser::LatexObj #auto]

puts "NEWSTR!$obj_ptr!"
    # Need to find out how many bytes the string requires 
    if {$len == -1} {
      set len [string length $str]
    }
    $obj_ptr strValue_SetCharLength $len
    $obj_ptr strValue_SetMaxLength $len
    if {$len == 0} {







|







110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  }

  # ==================== newStringObj ================================== 
  # len is in bytes -- see also newStringObjUtf8() 
::itcl::body StringObjType::newStringObj {str len where} {
    set obj_ptr [uplevel #0 ::Parser::LatexObj #auto]

#puts "NEWSTR!$obj_ptr!"
    # Need to find out how many bytes the string requires 
    if {$len == -1} {
      set len [string length $str]
    }
    $obj_ptr strValue_SetCharLength $len
    $obj_ptr strValue_SetMaxLength $len
    if {$len == 0} {

Changes to latex_parse.tcl.

344
345
346
347
348
349
350
351



352
353
354
355
356
357
358
359
360
}

buildCmdList $latex_cmds_info

::Parser::Token::Init
::Interp::Init
::LaTeX::CommandInfo::Init
set str "\\begin\[pf1\]{document}\n abc \n\\end{document}"



set script [$::Interp::string_obj_type newStringObj "$str" -1 "BASE_2"]
puts "SCRIPT![$script toDebugString]!"
$::Interp::eval_statement evalObj $script

if {0} {
set parser [::Parser::Parse #auto]
$parser parserInit $str [string length $str] 1
while {true} {
  if {[$parser isEof]} {







|
>
>
>

|







344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
}

buildCmdList $latex_cmds_info

::Parser::Token::Init
::Interp::Init
::LaTeX::CommandInfo::Init
set fname [lindex $argv 0]
set fd [open $fname r]
set str [read $fd]
close $fd
set script [$::Interp::string_obj_type newStringObj "$str" -1 "BASE_2"]
#puts "SCRIPT![$script toDebugString]!"
$::Interp::eval_statement evalObj $script

if {0} {
set parser [::Parser::Parse #auto]
$parser parserInit $str [string length $str] 1
while {true} {
  if {[$parser isEof]} {