ALDT (Arnulf's LaTeX Documentation Tool)

Check-in [ca968628f6]
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:ca968628f66e5ad2eda31898b300730d433e7c18
User & Date: arnulf 2012-08-26 09:54:24
Context
2012-08-26
10:19
initial version check-in: c1c5d81242 user: arnulf tags: trunk
09:54
fixes and new code check-in: ca968628f6 user: arnulf tags: trunk
2012-08-25
21:18
initial version check-in: 1f9b6e521b user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Parse.tcl.

39
40
41
42
43
44
45



46
47
48
49
50
51
52
...
675
676
677
678
679
680
681















682
683
684
685
686
687
688
  private method parseBrace {}
  private method parseListBrace {}
  private method parseBracket {}
  private method parseString {}
  private method parseComment {}
  public method getText {}
  public method getToken {}



  private method feedCharStart {}
  private method feedChar {}
}

::itcl::body Parser::constructor {args} {
   set debug 0
   set no_exp_parsing false
................................................................................
  return [string range [$parse_info getText] [$parse_info getStart] [$parse_info getEnd]]
}

# ==================== getToken ===================================== 
::itcl::body Parser::getToken {} {
  return [$parse_info getToken]
}
















# ==================== feedCharStart ===================================== 
::itcl::body Parser::feedCharStart {} {
  if {[$parse_info getLen] > 0} {
    feedChar
  } else {
    $parse_info setEof true







>
>
>







 







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







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
...
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
  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 {}
  private method feedCharStart {}
  private method feedChar {}
}

::itcl::body Parser::constructor {args} {
   set debug 0
   set no_exp_parsing false
................................................................................
  return [string range [$parse_info getText] [$parse_info getStart] [$parse_info getEnd]]
}

# ==================== getToken ===================================== 
::itcl::body Parser::getToken {} {
  return [$parse_info getToken]
}

# ==================== getParseInfo ===================================== 
::itcl::body Parser::getParseInfo {} {
  return $parse_info
}

# ==================== getParseResult ===================================== 
::itcl::body Parser::getParseResult {} {
  return $parse_result
}

# ==================== getEof ===================================== 
::itcl::body Parser::getEof {} {
  return [$parse_info getEof]
}

# ==================== feedCharStart ===================================== 
::itcl::body Parser::feedCharStart {} {
  if {[$parse_info getLen] > 0} {
    feedChar
  } else {
    $parse_info setEof true

Changes to Script.tcl.

83
84
85
86
87
88
89
90
91
92
93




94
95
96
97
98
99
100
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
...
383
384
385
386
387
388
389
390



391

















  public method toString {}
  public method toDebugString {}
  public method tokenIsSep {token}
  public method scriptTokenListInit {}
  public method scriptTokenListFree {}
  public method scriptAddParseToken {start len token line text}
  public method scriptObjAddTokens {}
  public method getText {start_idx len}
  public method countWordTokens {idx}
  public method substObjAddTokens {idx}
  public method dumpToken {idx}




}

  # ==================== constructor ==================================
::itcl::body Script::constructor {} {
    incr oid
    set id $oid

................................................................................
#        print("["+i+"]@"+getTokenString(token_info.token)+"!"+script.interp.string_obj_type.getString(token_info.obj_ptr)+"!");
      }
      puts "======== Script END ======"
    }
    panic "[$script_object getLen] > $count scriptObjAddTokens: script.len > count: [$script_object getLen]!$count"
}

  # ==================== getText ================================== 
::itcl::body Script::getText {start_idx len} {
    return [string range $text $start_idx [expr {$start_idx + len}]]
}

  # ==================== countWordTokens ================================== 
  #* Counts the number of adjoining non-separator.
  #*
  #* Returns -ve if the first token is the expansion
................................................................................
  # ==================== dumpToken ==================================
::itcl::body Script::dumpToken {idx} {
    set script_token [[$script_object getTokens] getToken $idx]

#    puts "TOK \[$idx\]@[::Parser::Token::token2String [$token_info getToken]]![$string_obj_type getString [$token_info getObjPtr]]!"
    puts "TOK \[$idx\]@![$script_token toString]!"
}




}
























|



>
>
>
>







 







|
|







 








>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
...
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
  public method toString {}
  public method toDebugString {}
  public method tokenIsSep {token}
  public method scriptTokenListInit {}
  public method scriptTokenListFree {}
  public method scriptAddParseToken {start len token line text}
  public method scriptObjAddTokens {}
  public method getSubText {start_idx len}
  public method countWordTokens {idx}
  public method substObjAddTokens {idx}
  public method dumpToken {idx}
  public method setText {val}
  public method getText {}
  public method setTextLen {val}
  public method getTextLen {}
}

  # ==================== constructor ==================================
::itcl::body Script::constructor {} {
    incr oid
    set id $oid

................................................................................
#        print("["+i+"]@"+getTokenString(token_info.token)+"!"+script.interp.string_obj_type.getString(token_info.obj_ptr)+"!");
      }
      puts "======== Script END ======"
    }
    panic "[$script_object getLen] > $count scriptObjAddTokens: script.len > count: [$script_object getLen]!$count"
}

  # ==================== getSubText ================================== 
::itcl::body Script::getSubText {start_idx len} {
    return [string range $text $start_idx [expr {$start_idx + len}]]
}

  # ==================== countWordTokens ================================== 
  #* Counts the number of adjoining non-separator.
  #*
  #* Returns -ve if the first token is the expansion
................................................................................
  # ==================== dumpToken ==================================
::itcl::body Script::dumpToken {idx} {
    set script_token [[$script_object getTokens] getToken $idx]

#    puts "TOK \[$idx\]@[::Parser::Token::token2String [$token_info getToken]]![$string_obj_type getString [$token_info getObjPtr]]!"
    puts "TOK \[$idx\]@![$script_token toString]!"
}

  # ==================== setText ==================================
::itcl::body Script::setText {val} {
    set text $val
}

  # ==================== getText ==================================
::itcl::body Script::getText {} {
    return $text
}

  # ==================== setTextLen ==================================
::itcl::body Script::setTextLen {val} {
    set text_len $val
}

  # ==================== getTextLen ==================================
::itcl::body Script::getTextLen {} {
    return $text_len
}

}

Changes to ScriptObjType.tcl.

41
42
43
44
45
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
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
122
123
124
125
126
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
179
180
181
182
183
    set id $oid
    set debug 0
    set subst_debug 0
}

  # ==================== mySelf ================================== 
::itcl::body ScriptObjType::mySelf {} {
    String str = "ScriptObjType!"+id+"!";
    return str;
  }

  # ==================== toString =====================================
::itcl::body ScriptObjType::toString {} {
    return mySelf()+"!";
  }

  # ==================== toDebugString =====================================
::itcl::body ScriptObjType::toDebugString {} {
    StringBuffer str = new StringBuffer(mySelf()+"\n");
    return str.toString();
  }

  # ==================== setFromAny ==================================
::itcl::body ScriptObjType::setFromAny {obj_ptr flags} {
    Script script = new Script(interp);
    int line = 1;
    Parse parser = new Parse(interp);

//print("script sFA1!");
    script.text = interp.string_obj_type.getString(obj_ptr);
    script.text_len = interp.string_obj_type.getStringLength(obj_ptr);

//print("sFA1a!"+script.text+"!");
    /* Try to get information about filename / line number */
    if (obj_ptr.obj_type != 0 && obj_ptr.obj_type == OBJ_TYPE_SOURCE) {
      line = obj_ptr.sourceValue_GetLineNumber();
    }

    /* Initially parse the script into tokens (in tokenlist) */
    script.scriptTokenListInit();

//print("script sFA2!");
    parser.parserInit(script.text, script.text_len, line);
    while (! parser.parse_info.eof) {
      int ret = parser.parseScript();
//print("parseScript!"+getTokenString(parser.parse_info.token)+"!"+parser.getText()+"!");
      // FIXME should check ret code here !!!
      if (ret != OK) {
      }
//print("txt!"+parser.getText()+"!");
      script.scriptAddParseToken(parser.parse_info.start, parser.parse_info.end - parser.parse_info.start + 1, parser.parse_info.token, parser.parse_info.line, parser.parse_info.text);
    }
//print("script sFA3!");
    if (parser.parse_result.missing != ' ') {
      script.scriptTokenListFree();
      return ERROR;
    }

    /* Add a final EOF token */
    script.scriptAddParseToken(script.text_len, 0, TOKEN_EOF, 0, script.text);

//print("script sFA4!");
    /* Create the "real" script tokens from the initial token list */
    script.script_object.ref_count = 1;
    script.script_object.line = line;
    if (obj_ptr.obj_type != 0 && obj_ptr.obj_type == OBJ_TYPE_SOURCE) {
      script.script_object.file_name_obj = obj_ptr.sourceValue_GetFileNameObj();
    } else {
      script.script_object.file_name_obj = interp.empty_string_obj;
    }
    script.script_object.file_name_obj.incrRefCount("I_SCRIPT_OBJ_TYPE_1");
//print("script sFA5!");
    script.scriptObjAddTokens();
    /* No longer need the token list */
//print("script sFA6!");
    script.scriptTokenListFree();
    /* Free the old internal rep and set the new one. */
    obj_ptr.freeIntRep();
if (debug != 0) {
    print("SetFromAny!obj_type!"+getObjTypeString(obj_ptr.obj_type)+"!");
}
    obj_ptr.obj_type = OBJ_TYPE_SCRIPT;
//    obj_ptr.setIntRepPtr((Object)script);
    obj_ptr.scriptValue_SetScript(script);
    return OK;
  }

  # ==================== freeInternalRep =====================================
::itcl::body ScriptObjType::freeInternalRep {obj_ptr} {
    print("script freeInternalRep not yet implemented");
  }

  # ==================== duptInternalRep =====================================
::itcl::body ScriptObjType::dupInternalRep {src_ptr dup_ptr} {
    print("script dupInternalRep not yet implemented");
  }

  # ==================== makeScriptObj ==================================
::itcl::body ScriptObjType::makeScriptObj {parse_token text} {
    ApwtclObj obj_ptr;
    int idx = text.substring(parse_token.start, parse_token.start + parse_token.len).indexOf("\\");
    boolean have_backslash = idx >= 0 ? true : false;

//print("HAVEBSL!"+have_backslash+"!"+text.substring(parse_token.start, parse_token.start + parse_token.len)+"!");
    if ((parse_token.token == TOKEN_ESC || parse_token.token == TOKEN_QUOTE_ESC) && have_backslash) {
      /* Convert the backlash escapes . */
//print("HAVEBSL2!"+have_backslash+"!"+text.substring(parse_token.start, parse_token.start + parse_token.len)+"!");
      int len = parse_token.len;
      ArrayList<String> result_str = new ArrayList<String>();
      String str = text.substring(parse_token.start, parse_token.start + parse_token.len);
      len = interp.default_obj.escapeBackslash(result_str, str, len);
      str = result_str.get(0);
      obj_ptr = interp.string_obj_type.newStringObjNoAlloc(str, len, "SCRIPT_OBJ_TYPE_1");
    } else {
      /* REVISIT: Strictly, TOKEN_STR should replace <backslash><newline><whitespace>
       *         with a single space. This is currently not done.
       */
      obj_ptr = interp.string_obj_type.newStringObj(text.substring(parse_token.start, parse_token.start + parse_token.len), parse_token.len, "SCRIPT_OBJ_TYPE_2");

    }
    return obj_ptr;




  }

  # ==================== getScript ================================== 
::itcl::body ScriptObjType::getScript {obj_ptr} {
    int script_flags = 0;
    if (obj_ptr.obj_type == OBJ_TYPE_SCRIPT) {
      Script script = obj_ptr.scriptValue_GetScript();
      script_flags = script.script_object.subst_flags;
    }
    if ((obj_ptr.obj_type == 0) || (obj_ptr.obj_type != OBJ_TYPE_SCRIPT) || (script_flags != 0)) {
      if (setFromAny(obj_ptr, 0) != OK) {
        return null;
      }
    }
    return obj_ptr.scriptValue_GetScript();
  }

  # ==================== substSetFromAny ==================================
  # The subst object type reuses most of the data structures and functions
  # of the script object. Script's data structures are a bit more complex
  # for what is needed for [subst]itution tasks, but the reuse helps to
  # deal with a single data structure at the cost of some more memory







|
|




|




|
|




|
|
|

|
|
|

|
|
|
|


|
|

|
|
|
|
|
|
|

|
|

|
|
|
|


|
|

|
|
|
|
|
|

|

|
|
|
|
|
|
|
|
|
|

|
<
|
|




|




|




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




|
|
|
|

|
|
|


|







41
42
43
44
45
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
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
122

123
124
125
126
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
179
180
181
182
183
184
185
186
    set id $oid
    set debug 0
    set subst_debug 0
}

  # ==================== mySelf ================================== 
::itcl::body ScriptObjType::mySelf {} {
    set str "ScriptObjType!$id!"
    return $str;
  }

  # ==================== toString =====================================
::itcl::body ScriptObjType::toString {} {
    return "[mySelf]!"
  }

  # ==================== toDebugString =====================================
::itcl::body ScriptObjType::toDebugString {} {
    set str "[mySelf]\n"
    return $str
  }

  # ==================== setFromAny ==================================
::itcl::body ScriptObjType::setFromAny {obj_ptr flags} {
    set script [::Parser::Script #auto]
    set line 1
    set parser [::parser::Parse #auto]

#puts "script sFA1!"
    $script setText [$string_obj_type getString $obj_ptr]
    $script setTextLen [$string_obj_type getStringLength $obj_ptr]

#puts "sFA1a![$script getText]!"
    # Try to get information about filename / line number
    if {[$obj_ptr getObjType] != 0 && [$obj_ptr getObjType] == OBJ_TYPE_SOURCE} {
      set line [$obj_ptr SourceValue_GetLineNumber]
    }

    # Initially parse the script into tokens (in tokenlist) 
    $script scriptTokenListInit

#puts "script sFA2!"
    $parser parserInit [$script getText] [$script getTextLen] $line
    while {! [$parser getEof]} {
      set ret  [$parser parseScript]
#puts "parseScript![::Parser::Token::token2String [$parser getToken]![$parser getText]!"
      # FIXME should check ret code here !!!
      if {$ret != true} {
      }
#puts "txt![$parser getText]!");
      $script scriptAddParseToken [[$parser getParseInfo] getStart] [expr {[[$parser getParseInfo] getEnd] - [[$parser getParseInfo] getStart] + 1}] [[$parser getParseInfo] getToken] [[$parser getParseInfo] getLine] [[$parser getParseInfo] getText]
    }
#puts "script sFA3!");
    if {[$parser getParseResult] getMissing] != " "} {
      $script scriptTokenListFree
      return false
    }

    # Add a final EOF token 
    $script scriptAddParseToken [$script getTextLen] 0 "TOKEN_EOF" 0 [$script getText]

#puts "script sFA4!"
    # Create the "real" script tokens from the initial token list
    [$script getScriptObject] setRefCount 1
    [$script getScriptObject] setLine $line
    if {[$obj_ptr getObjType] != 0 && [$obj_ptr getObjType] == "OBJ_TYPE_SOURCE"} {
      [$script getScriptObject] setFileNameObj [$obj_ptr sourceValue_GetFileNameObj]
    } else {
      [$script getScriptObject] setFileNameObj $empty_string_obj]
    }
    [[$script getScriptObject] getFileNameObj] incrRefCount "I_SCRIPT_OBJ_TYPE_1"
#puts "script sFA5!"
    $script scriptObjAddTokens
    # No longer need the token list
#puts "script sFA6!"
    $script scriptTokenListFree
    # Free the old internal rep and set the new one.
    $obj_ptr freeIntRep
if {$debug != 0} {
    puts "SetFromAny!obj_type![getObjTypeString [$obj_ptr getObjType]]!"
}
    $obj_ptr setObjType OBJ_TYPE_SCRIPT

    $obj_ptr scriptValue_SetScript $script
    return true
  }

  # ==================== freeInternalRep =====================================
::itcl::body ScriptObjType::freeInternalRep {obj_ptr} {
    puts "script freeInternalRep not yet implemented"
  }

  # ==================== duptInternalRep =====================================
::itcl::body ScriptObjType::dupInternalRep {src_ptr dup_ptr} {
    puts "script dupInternalRep not yet implemented"
  }

  # ==================== makeScriptObj ==================================
::itcl::body ScriptObjType::makeScriptObj {parse_token text} {
    set obj_ptr ""
    set idx [string index [string range $text [$parse_token getStart] [expr {[$parse_token getStart] + [$parse_token getLen]}]] "\\"]
    if {$idx > 0} {
      set have_backslash true
    } else {
      set have_backslash true
    }

#puts "HAVEBSL!$have_backslash![string range $text [$parse_token getStart] [expr {[$parse_token getStart] + [$parse_token getLen]}]i]!"
    if {([$parse_token getToken] == [::Parser::Token::string2Token "TOKEN_ESC"] || [$parse_token getToken] == [::Parser::Token::string2Token "TOKEN_QUOTE_ESC"]) && $have_backslash} {
      # Convert the backlash escapes 
#puts ("HAVEBSL2!$have_backslash![string range $text [$parse_token getStart] [expr {[$parse_token getStart] + [$parse_token getLen]}]]!"
      set len [$parse_token getLen]
      set result_str [list]
      set str [string range $text [$parse_token getStart] [expr {[$parse_token getStart] + [$parse_token getLen]}]];
      set len [$default_obj escapeBackslash $result_str $str $len]
      set str [lindex $result_str 0]
      set obj_ptr [$string_obj_type newStringObjNoAlloc $str $len "SCRIPT_OBJ_TYPE_1"]
    } else {
      # REVISIT: Strictly, TOKEN_STR should replace <backslash><newline><whitespace>
      #         with a single space. This is currently not done.
     
      set obj_ptr [$string_obj_type newStringObj [string range $text [$parse_token getStart] [expr {[$parse_tokengetStart] + [$parse_token getLen]}]] [$parse_token getLen] "SCRIPT_OBJ_TYPE_2"]

    }
    return $obj_ptr;
  }

  # ==================== getScript ================================== 
::itcl::body ScriptObjType::getScript {obj_ptr} {
    set script_flags 0
    if {[$obj_ptr getObjType] == OBJ_TYPE_SCRIPT} {
      set script [$obj_ptr scriptValue_GetScript]
      set script_flags [[$script getScriptObject] getSubstFlags]
    }
    if {[$obj_ptr getObjType] == 0) || ([$obj_ptr getObjType] != OBJ_TYPE_SCRIPT) || ($script_flags != 0)} {
      if {[setFromAny $obj_ptr 0] != true} {
        return [list]
      }
    }
    return [$obj_ptr scriptValue_GetScript]
  }

  # ==================== substSetFromAny ==================================
  # The subst object type reuses most of the data structures and functions
  # of the script object. Script's data structures are a bit more complex
  # for what is needed for [subst]itution tasks, but the reuse helps to
  # deal with a single data structure at the cost of some more memory

Changes to latex_parse.tcl.

19
20
21
22
23
24
25

26
27
28
29
30
31
32
source ./ParseInfo.tcl
source ./ParseResult.tcl
source ./Parse.tcl
source ./ParseToken.tcl
source ./ScriptToken.tcl
source ./ScriptObject.tcl
source ./Script.tcl

source ./latex_parse_fcn.tcl
source ./latex_cmds.tcl

global gState
global gCmds
global gPackages
global gCurr







>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
source ./ParseInfo.tcl
source ./ParseResult.tcl
source ./Parse.tcl
source ./ParseToken.tcl
source ./ScriptToken.tcl
source ./ScriptObject.tcl
source ./Script.tcl
source ./ScriptObjType.tcl
source ./latex_parse_fcn.tcl
source ./latex_cmds.tcl

global gState
global gCmds
global gPackages
global gCurr