ALDT (Arnulf's LaTeX Documentation Tool)

Check-in [55cf454cd6]
Login

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

Overview
Comment:fixes and new code
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:55cf454cd650e7b468c54d6178d40568d8b81a24
User & Date: arnulf 2012-08-29 17:34:03
Context
2012-08-29
19:23
fixes and new code check-in: f41e96b23b user: arnulf tags: trunk
17:34
fixes and new code check-in: 55cf454cd6 user: arnulf tags: trunk
2012-08-26
20:19
fixes check-in: 5d7b8549ff user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Parse.tcl.

32
33
34
35
36
37
38

39
40
41

42
43
44
45
46
47
48
...
102
103
104
105
106
107
108
109
110


111







112



113
114
115
116
117
118
119
...
127
128
129
130
131
132
133
134










135
136
137
138










139
140
141














142

143
144
145
146
147
148
149
150
151
152
153
154








155
156
157
158
159
160
161


162
163
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
...
203
204
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
...
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
...
454
455
456
457
458
459
460






































































461
462
463
464
465
466
467
...
483
484
485
486
487
488
489









490
491
492
493
494
495
496
...
553
554
555
556
557
558
559










560
561
562
563
564
565
566
...
590
591
592
593
594
595
596

597
598
599
600
601
602
603
  public  method parseScript {}
  private method parseTagName {}
  private method parseWordSep {}
  private method parseEol {}
  private method parseSubBrace {}
  private method parseSubQuote {}
  private method parseSubBracket {}

  private method parseBrace {}
  private method parseListBrace {}
  private method parseBracket {}

  private method parseString {}
  private method parseComment {}
  public method getText {}
  public method getToken {}
  public method getParseInfo {}
  public method getParseResult {}
  public method getEof {}
................................................................................
      $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 {


        $parse_info setComment false







        return [parseTagName]



      }
      }
    " " -
    "\t" -
    "\r" {
      if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"]} {
        return [parseWordSep]
................................................................................
      $parse_info setComment true
      if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"]} {
        return [parseEol]
      } else {
        return [parseString]
      }
      }
    "\{" {   ; # For TCL \}










      $parse_info setComment false
      return [parseBrace]
      }
    "\[" {  ; # for TCL ]










      $parse_info setComment false
      return [parseBracket]
      }














    "$" {

       $parse_info setComment false
       if {[parseVar] == false} {
         $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
         $parse_info setLen [expr {[$parse_info getLen] - 1}]
         $parse_info setLine [$parse_info getLineNo]
         $parse_info setToken [::Parser::Token::string2Token "TOKEN_STR"]
         return false
      } else {
         return true
      }
      }
    "#" {








      if {[$parse_info getComment]} {
        return [parseComment]
      } else {
        return [parseString]
      }
      }
    default {


      $parse_info setComment false
      set ret [parseString]
      return $ret
      }
    }
  }
}

# ==================== parseWordSep ===================================== */
::itcl::body Parse::parseWordSep {} {

  $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 {
................................................................................
}

# ==================== 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"]

  feedChar
  while {[$parse_info getLen] > 0} {
    switch [$parse_info getCur] {
    "\{" -
    "\[" -

    "\t" -

    "\n" -
    " " {
      $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
      break
      }
    default {

      feedChar




      }
    }
  }
  return true
}

# ==================== parseEol ===================================== 
................................................................................
      feedChar
    } else {
      $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"
        }
................................................................................
      feedChar
    }
    $parse_result setMissing "\["
    $parse_result setMissingLine $line;
    $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
    return true
  }







































































  #* ==================== parseBrace ===================================== */
::itcl::body Parse::parseBrace {} {
    $parse_info setStart [expr {[$parse_info getIndex] + 1}]
    $parse_info setLine [$parse_info getLineNo]
    $parse_info setToken [::Parser::Token::string2Token "TOKEN_BRACE"]
    parseSubBrace
................................................................................
::itcl::body Parse::parseBracket {} {
    $parse_info setStart [expr {[$parse_info getIndex] + 1}]
    $parse_info setLine [$parse_info getLineNo]
    $parse_info setToken [::Parser::Token::string2Token "TOKEN_BRACKET"]
    parseSubBracket
    return true
  }










  # ==================== parseString =====================================
::itcl::body Parse::parseString {} {
#puts "ParseString![$parse_info getCur]![$parse_info getLen]![$parse_info getState] != PARSER_STATE_QUOTE!"
    set is_special_char false ; # used for correct eof handling, if no statement and char is
                                # there i.e. contents of [list] parsing 
    switch [::Parser::Token::token2String [$parse_info getToken]] {
................................................................................
            $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 "\n"} {
            $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
          }
          feedChar
        }
        }
      "(" {
................................................................................
        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
        }

      "$" -
      "\[" {
        $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"]







>



>







 







|

>
>
|
>
>
>
>
>
>
>
|
>
>
>







 







|
>
>
>
>
>
>
>
>
>
>



|
>
>
>
>
>
>
>
>
>
>



>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
|
|
|
|
|
|
|

|


|
>
>
>
>
>
>
>
>







>
>










>







 







>





>

>






>
|
>
>
>
>







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>







 







>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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
226
227
228
229
230
231
232
233
234
235
236
237
238
...
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
...
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
...
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
...
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
...
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
...
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
  public  method parseScript {}
  private method parseTagName {}
  private method parseWordSep {}
  private method parseEol {}
  private method parseSubBrace {}
  private method parseSubQuote {}
  private method parseSubBracket {}
  private method parseSubParen {}
  private method parseBrace {}
  private method parseListBrace {}
  private method parseBracket {}
  private method parseParen {}
  private method parseString {}
  private method parseComment {}
  public method getText {}
  public method getToken {}
  public method getParseInfo {}
  public method getParseResult {}
  public method getEof {}
................................................................................
      $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
        }
        return [parseString];
      }
      }
    " " -
    "\t" -
    "\r" {
      if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"]} {
        return [parseWordSep]
................................................................................
      $parse_info setComment true
      if {[$parse_info getState] eq [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"]} {
        return [parseEol]
      } else {
        return [parseString]
      }
      }
    "\{" {
      if {[$parse_info getArgument]} {
        if {![$parse_info getWordSep]} {
          # we have to simulate a TOKEN_WORD_SEP here so 
          # EvalStatement will use the optional and mandatory arguments
          # as those and not as a combined string!!
          set ret [parseWordSep]
          return $ret
        }
      }
      $parse_info setWordSep false
      $parse_info setComment false
      return [parseBrace]
      }
    "\[" {
      if {[$parse_info getArgument]} {
        if {![$parse_info getWordSep]} {
          # we have to simulate a TOKEN_WORD_SEP here so 
          # EvalStatement will use the optional and mandatory arguments
          # as those and not as a combined string!!
          set ret [parseWordSep]
          return $ret
        }
      }
      $parse_info setWordSep false
      $parse_info setComment false
      return [parseBracket]
      }
    "\(" {
      if {[$parse_info getArgument]} {
        if {![$parse_info getWordSep]} {
          # we have to simulate a TOKEN_WORD_SEP here so 
          # EvalStatement will use the optional and mandatory arguments
          # as those and not as a combined string!!
          set ret [parseWordSep]
          return $ret
        }
      }
      $parse_info setWordSep false
      $parse_info setComment false
      return [parseParen]
      }
    "$" {
      $parse_info setWordSep false
      $parse_info setComment false
      if {[parseVar] == false} {
        $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
        $parse_info setLen [expr {[$parse_info getLen] - 1}]
        $parse_info setLine [$parse_info getLineNo]
        $parse_info setToken [::Parser::Token::string2Token "TOKEN_STR"]
        return true
      } else {
        return true
      }
      }
    "&" {
      $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 {
................................................................................
}

# ==================== 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
  feedChar
  while {[$parse_info getLen] > 0} {
    switch [$parse_info getCur] {
    "\{" -
    "\[" -
    "\(" -
    "\t" -
    "\r" -
    "\n" -
    " " {
      $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
      break
      }
    default {
      if {([$parse_info getCur] eq "_") || ([string is alnum [$parse_info getCur]])} {
        feedChar
      } else {
        $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
        break
      }
      }
    }
  }
  return true
}

# ==================== parseEol ===================================== 
................................................................................
      feedChar
    } else {
      $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"
        }
................................................................................
      feedChar
    }
    $parse_result setMissing "\["
    $parse_result setMissingLine $line;
    $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
    return true
  }

  #* ==================== parseSubParen =====================================
  #**
  #* Parses a (string, string, ...) expression starting at parse.index.
  #*
  #* Positions the parser at the end of the command expression,
  #* sets parse.end and possibly parse.missing.

::itcl::body Parse::parseSubParen {} {
    set level 1
    set startOfWord true
    set line [$parse_info getLine]

    # 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}];
        }
      "\)" {
        set level [expr {$level - 1}]
        if {$level == 0} {
          $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
 #puts "bb![getText]![$parse_info getLen]![$parse_info getText]!"
          if {[$parse_info getLen] > 0} {
            feedChar
          }
          return true
        }
        }
      "\"" {
        if {$startOfWord} {
          parseSubQuote
          continue
        }
        }
      "\{" {       ; # for Tcl \}
        [parseSubBrace]
#puts "parseSubBracket!"
        set startOfWord false
        continue
        }
      "\[" {       ; # for Tcl \]
        [parseSubBracket]
#puts "parseSubBracket!"
        set startOfWord false
        continue
        }
      "\n" {
        $parse_info setLineNo [expr {[$parse_info getLineNo] + 1}]
        break
        }
      }
      set startOfWord [string is space [$parse_info getCur]]
      feedChar
    }
    $parse_result setMissing "\("
    $parse_result setMissingLine $line;
    $parse_info setEnd [expr {[$parse_info getIndex] - 1}]
    return true
  }

  #* ==================== parseBrace ===================================== */
::itcl::body Parse::parseBrace {} {
    $parse_info setStart [expr {[$parse_info getIndex] + 1}]
    $parse_info setLine [$parse_info getLineNo]
    $parse_info setToken [::Parser::Token::string2Token "TOKEN_BRACE"]
    parseSubBrace
................................................................................
::itcl::body Parse::parseBracket {} {
    $parse_info setStart [expr {[$parse_info getIndex] + 1}]
    $parse_info setLine [$parse_info getLineNo]
    $parse_info setToken [::Parser::Token::string2Token "TOKEN_BRACKET"]
    parseSubBracket
    return true
  }

  #* ==================== parseParen ===================================== */
::itcl::body Parse::parseParen {} {
    $parse_info setStart [expr {[$parse_info getIndex] + 1}]
    $parse_info setLine [$parse_info getLineNo]
    $parse_info setToken [::Parser::Token::string2Token "TOKEN_PAREN"]
    parseSubParen
    return true
  }

  # ==================== parseString =====================================
::itcl::body Parse::parseString {} {
#puts "ParseString![$parse_info getCur]![$parse_info getLen]![$parse_info getState] != PARSER_STATE_QUOTE!"
    set is_special_char false ; # used for correct eof handling, if no statement and char is
                                # there i.e. contents of [list] parsing 
    switch [::Parser::Token::token2String [$parse_info getToken]] {
................................................................................
            $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
        }
        }
      "(" {
................................................................................
        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
        }
      "&" -
      "$" -
      "\[" {
        $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"]

Changes to ParseInfo.tcl.

11
12
13
14
15
16
17


18
19
20
21
22
23
24
25
26
27
28
29



30
31


32
33
34
35
36
37
38
..
49
50
51
52
53
54
55






56
57
58
59
60


61
62
63
64
65
66
67
68
69
70
71



72
























73
74
75
76
77
78
79
...
163
164
165
166
167
168
169
170


171






















# *
# * Copyright 2012 Arnulf P. Wiedemann
#=====================================================

namespace eval ::Parser {

::itcl::class ParseInfo {


  public variable text      ; # program being parsed
  public variable len       ; # Remaining length
  public variable start
  public variable end       ; # Returned token is at start-end in 'text'.
  public variable index;    ; # index of the point of the program we are parsing
  public variable cur;      ; # current charcter handled in parsing
  public variable token;    ; # Token type
  public variable eof;      ; # true if EOF condition is true.
  public variable state;    ; # Parser state
  public variable line;     ; # Line number of the returned token
  public variable line_no;  ; # Current line number
  public variable comment;  ; # true if the next chars may be a comment.




  constructor {code len l_no} {}


  public method setText {val}
  public method getText {}
  public method setLen {val}
  public method getLen {}
  public method setStart {val}
  public method getStart {}
  public method setEnd {val}
................................................................................
  public method getState {}
  public method setLine {val}
  public method getLine {}
  public method setLineNo {val}
  public method getLineNo {}
  public method setComment {val}
  public method getComment {}







}

::itcl::body ParseInfo::constructor {code code_len l_no} {
puts "ParseInfo::constructor!$code!$code_len!$l_no!"


    set text    $code
    set len     $code_len
    set start   0
    set end     0
    set line_no $l_no
    set index   -1
    set eof     false
    set line    0
    set token   [::Parser::Token::string2Token "TOKEN_NONE"]
    set state   [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"]
    set comment true



    set cur     0
























}

::itcl::body ParseInfo::setText {val} {
  set text $val
}

::itcl::body ParseInfo::getText {} {
................................................................................
::itcl::body ParseInfo::setComment {val} {
  set comment $val
}

::itcl::body ParseInfo::getComment {} {
  return $comment
}



}





























>
>




|
|
|
|
|
|
|
|
>
>
>


>
>







 







>
>
>
>
>
>





>
>
|
|
|
|
|
|
|
|
|
|
|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 








>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
..
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
...
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
232
233
234
235
236
237
# *
# * Copyright 2012 Arnulf P. Wiedemann
#=====================================================

namespace eval ::Parser {

::itcl::class ParseInfo {
  public common oid 0
  public variable id
  public variable text      ; # program being parsed
  public variable len       ; # Remaining length
  public variable start
  public variable end       ; # Returned token is at start-end in 'text'.
  public variable index     ; # index of the point of the program we are parsing
  public variable cur       ; # current charcter handled in parsing
  public variable token     ; # Token type
  public variable eof       ; # true if EOF condition is true.
  public variable state     ; # Parser state
  public variable line      ; # Line number of the returned token
  public variable line_no   ; # Current line number
  public variable comment   ; # true if the next chars may be a comment.
  public variable argument  ; # true if the next chars may be an optional or mandatory argument.
  public variable tagname   ; # true if we had a tagName and we are parsing the optional or mandatory arguments.
  public variable wordsep   ; # true if we had a WORD_SEP should be parsed next.

  constructor {code len l_no} {}
  public method mySelf {}
  public method toDebugString {}
  public method setText {val}
  public method getText {}
  public method setLen {val}
  public method getLen {}
  public method setStart {val}
  public method getStart {}
  public method setEnd {val}
................................................................................
  public method getState {}
  public method setLine {val}
  public method getLine {}
  public method setLineNo {val}
  public method getLineNo {}
  public method setComment {val}
  public method getComment {}
  public method setArgument {val}
  public method getArgument {}
  public method setTagName {val}
  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
    set index       -1
    set eof         false
    set line        0
    set token       [::Parser::Token::string2Token "TOKEN_NONE"]
    set state       [::Parser::Token::string2ParserState "PARSER_STATE_DEFAULT"]
    set comment     true
    set argument    false
    set tagname     false
    set wordsep     false
    set cur         0
}

::itcl::body ParseInfo::mySelf {} {
  set str "ParseInfo!$id"
}

::itcl::body ParseInfo::toDebugString {} {
  set str "[mySelf]!"
  append str "text: $text\n"
  append str "len: $len\n"
  append str "start: $start\n"
  append str "end: $end\n"
  append str "line_no: $line_no\n"
  append str "index: $index\n"
  append str "eof: $eof\n"
  append str "line: $line\n"
  append str "token: [::Parser::Token::token2String $token]\n"
  append str "state: [::Parser::Token::parserState2String $state]\n"
  append str "comment: $comment\n"
  append str "argument: $argument\n"
  append str "tagname: $tagname\n"
  append str "wordsep: $wordsep\n"
  append str "cur: $cur\n"
  return $str
}

::itcl::body ParseInfo::setText {val} {
  set text $val
}

::itcl::body ParseInfo::getText {} {
................................................................................
::itcl::body ParseInfo::setComment {val} {
  set comment $val
}

::itcl::body ParseInfo::getComment {} {
  return $comment
}

::itcl::body ParseInfo::setArgument {val} {
  set argument $val
}

::itcl::body ParseInfo::getArgument {} {
  return $argument
}

::itcl::body ParseInfo::setTagName {val} {
  set tagname $val
}

::itcl::body ParseInfo::getTagName {} {
  return $tagname
}

::itcl::body ParseInfo::setWordSep {val} {
  set wordsep $val
}

::itcl::body ParseInfo::getWordSep {} {
  return $wordsep
}

}

Changes to Token.tcl.

48
49
50
51
52
53
54



55
56
57
58
59
60
61
..
65
66
67
68
69
70
71



72
73
74
75
76
77
78
  set token2string(9) "TOKEN_LINE"
  set token2string(10) "TOKEN_WORD"
  set token2string(17) "TOKEN_COMMENT"
  set token2string(18) "TOKEN_BRACE"
  set token2string(19) "TOKEN_QUOTE"
  set token2string(20) "TOKEN_QUOTE_ESC"
  set token2string(21) "TOKEN_TAG_NAME"




  set string2token(TOKEN_NONE) 0
  set string2token(TOKEN_STR) 1
  set string2token(TOKEN_ESC) 2
  set string2token(TOKEN_VAR) 3
  set string2token(TOKEN_VAR_ARRAY_NAME) 4
  set string2token(TOKEN_BRACKET) 5
................................................................................
  set string2token(TOKEN_LINE) 9
  set string2token(TOKEN_WORD) 10
  set string2token(TOKEN_COMMENT) 17
  set string2token(TOKEN_BRACE) 18
  set string2token(TOKEN_QUOTE) 19
  set string2token(TOKEN_QUOTE_ESC) 20
  set string2token(TOKEN_TAG_NAME) 21



}

::itcl::body Token::token2String {val} {
  if {[info exists token2string($val)]} {
    return $token2string($val)
  } else {
puts stderr "token2String no such token!$val!"







>
>
>







 







>
>
>







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
..
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  set token2string(9) "TOKEN_LINE"
  set token2string(10) "TOKEN_WORD"
  set token2string(17) "TOKEN_COMMENT"
  set token2string(18) "TOKEN_BRACE"
  set token2string(19) "TOKEN_QUOTE"
  set token2string(20) "TOKEN_QUOTE_ESC"
  set token2string(21) "TOKEN_TAG_NAME"
  set token2string(22) "TOKEN_PAREN"
  set token2string(23) "TOKEN_LINE_SEP"
  set token2string(24) "TOKEN_AMPERSAND"

  set string2token(TOKEN_NONE) 0
  set string2token(TOKEN_STR) 1
  set string2token(TOKEN_ESC) 2
  set string2token(TOKEN_VAR) 3
  set string2token(TOKEN_VAR_ARRAY_NAME) 4
  set string2token(TOKEN_BRACKET) 5
................................................................................
  set string2token(TOKEN_LINE) 9
  set string2token(TOKEN_WORD) 10
  set string2token(TOKEN_COMMENT) 17
  set string2token(TOKEN_BRACE) 18
  set string2token(TOKEN_QUOTE) 19
  set string2token(TOKEN_QUOTE_ESC) 20
  set string2token(TOKEN_TAG_NAME) 21
  set string2token(TOKEN_PAREN) 22
  set string2token(TOKEN_LINE_SEP) 23
  set string2token(TOKEN_AMPERSAND) 24
}

::itcl::body Token::token2String {val} {
  if {[info exists token2string($val)]} {
    return $token2string($val)
  } else {
puts stderr "token2String no such token!$val!"