Tcl Library Source Code

Changes On Branch pt-fixes2-ssoberni
Login

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

Changes In Branch pt-fixes2-ssoberni Excluding Merge-Ins

This is equivalent to a diff from 744a6b43a2 to f94401b3e2

2018-02-09
05:40
Merged PT work to release. check-in: 720355a2d8 user: aku tags: tcllib-1-19-rc
05:35
Merged PT work to trunk. check-in: 3a942ffbf3 user: aku tags: trunk
2018-02-08
22:55
Avoid extra [expr] calls in TclOO and Tcl engines Closed-Leaf check-in: f94401b3e2 user: ssoberni tags: pt-fixes2-ssoberni
22:45
Bump patch level check-in: 8d72cdd40c user: ssoberni tags: pt-fixes2-ssoberni
2018-02-07
17:15
Rewrite of the TclOO/NX transformation: a) supports standard pt debug mode, b) ~25% speed improvement thx to better handling of variable imports check-in: 9877877dcd user: ssoberni tags: pt-fixes2-ssoberni
2018-02-02
03:38
Merge to trunk: GN patches for doctools and markdown. check-in: 744a6b43a2 user: aku tags: trunk
2018-02-01
18:33
doctools2idx <D> Fixed documentation typos, code comment typos doctools2toc s.a doctools s.a Patch by Gustaf Neumann <[email protected]>, thank you. Closed-Leaf check-in: ede38cc0f5 user: aku tags: doctools-typos-gn
04:47
markdown / markdown <EF> - Applied patch adding syntax highlighting for `fenced code blocks` to the markdown package. Patch received from Gustaf Neumann <[email protected]>, with thanks. Closed-Leaf check-in: 924478eb48 user: aku tags: markdown-syntax-highlight-gn
2018-01-24
20:36
Tkt [8fd2561785] oauth/oauth <B,D> Merged fix of query default to GET, was POST. check-in: 738baecbc3 user: aku tags: trunk

Changes to modules/pt/pkgIndex.tcl.

52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66







-
+








# PARAM runtime.
package ifneeded pt::rde      1.1 [list source [file join $dir pt_rdengine.tcl]]
package ifneeded pt::rde::oo  1.1 [list source [file join $dir pt_rdengine_oo.tcl]]

# Note: The last two numbers are the rde::nx version itself. The
# preceding version information is the rde::oo version it is based on.
package ifneeded pt::rde::nx  1.1.1.0 [list source [file join $dir pt_rdengine_nx.tcl]]
package ifneeded pt::rde::nx  1.1.1.1 [list source [file join $dir pt_rdengine_nx.tcl]]


# PEG grammar specification, as CONTAINER
package ifneeded pt::peg::container::peg 1 [list source [file join $dir pt_peg_container_peg.tcl]]

# */PARAM support (canned configurations).
package ifneeded pt::cparam::configuration::critcl  1.0.2 [list source [file join $dir pt_cparam_config_critcl.tcl]]

Changes to modules/pt/pt_rdengine_nx.tcl.

1
2
3

4
5
6
7
8
9





10
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
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








1
2

3
4
5
6
7


8
9
10
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
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


-
+




-
-
+
+
+
+
+









-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+


-
+
+
+
+
+
+
+
+
# -*- tcl -*-
#
# Copyright (c) 2016-2017 by Stefan Sobernig <[email protected]>
# Copyright (c) 2016-2018 by Stefan Sobernig <[email protected]>

# # ## ### ##### ######## ############# #####################
## Package description

## ...

## An NX implementation of the PackRat Machine (PARAM), a virtual
## machine on top of which parsers for Parsing Expression Grammars
## (PEGs) can be realized. This implementation is tied to the PARAM's
## TclOO implementation and it is automatically derived from the
## corresponding TclOO class (pt::rde::oo) upon loading the package.

# # ## ### ##### ######## ############# #####################
## Requisites

package require pt::rde::oo
package req nx

namespace eval ::pt::rde {

    ##
    ## Helper: An NX metaclass, which allows for deriving an NX class from
    ## a given TclOO class.
    ##
    
    nx::Class create ClassFactory -superclass nx::Class {
	:property prototype:required
	:method init {args} {
	    :alias instvar ::nsf::methods::object::instvar
	    namespace eval [namespace qualifier [self]] {
		namespace import ::nsf::my
	    }
  ##
  ## Helper: An NX metaclass and class generator, which allows for
  ## deriving an NX class from the ::pt::rde::oo class.
  ##
  
  nx::Class create ClassFactory -superclass nx::Class {
    :property prototype:required

    :method mkMethod {name vars params body tmpl} {
      set objVars [list]
      set debugObjVars [list]
      foreach v $vars {
        if {[string first $v $body] > -1} {
          lappend objVars :$v $v
        } else {
          lappend debugObjVars :$v $v
        }
      }
      
      if {[llength $objVars]} {
        set objVars [list upvar 0 {*}$objVars]
      }

      if {[llength $debugObjVars]} {
        set debugObjVars [list debug.pt/rdengine \
                              "\[[list upvar 0 {*}$debugObjVars]\]"]
      }

      set mappings [list @body@ $body @objVars@ $objVars \
                        @debugObjVars@ $debugObjVars @params@ $params]
      
      set finalBody [string map $mappings $tmpl]

      :method $name $params $finalBody
      
    }; # mkMethod
    
    :method init {args} {

      namespace eval [namespace qualifier [self]] {
        namespace import ::nsf::my
      }

	    set vars [info class variables ${:prototype}]
	    if {[llength $vars]} {
		set vars [concat :instvar $vars]
	    }
	    
      :method debugPrep {cls} {
        :object method TraceInitialization [list [list cls $cls]] {
          set mh [$cls info methods -callprotection all TraceInitialization]
          if {$mh ne ""} {
            set script [$cls info method body $mh]
            apply [list {} $script [self]]
          }
        }
	    ## clone constructor
	    lassign [info class constructor ${:prototype}] ctorParams ctorBody
	    
	    set ctorBody [string map [list @body@ $ctorBody @vars@ $vars] {
		:require namespace; apply [list {} {
		    namespace import ::nsf::my
		    @vars@
		    @body@
		} [self]]
	    }]
	    
	    :method init $ctorParams $ctorBody		       

	    ## clone all methods
	    foreach m [info class methods ${:prototype} -private] {
		lassign [info class definition ${:prototype} $m] params body
		:method $m $params [string map [list @body@ $body @vars@ $vars] {
		    @vars@
		    @body@
        return
      }

      :method debugOn {} {
        interp alias {} [namespace current]::Instruction {} [self]::Instruction
        interp alias {} [namespace current]::InstReturn {} [self]::InstReturn
        interp alias {} [namespace current]::State {} [self]::State
        interp alias {} [namespace current]::TraceSetupStacks {} [self]::TraceSetupStacks
        return
      }

      :method debugOff {} {
        interp alias {} [namespace current]::Instruction {} 
        interp alias {} [namespace current]::InstReturn {} 
        interp alias {} [namespace current]::State {} 
        interp alias {} [namespace current]::TraceSetupStacks {}
        return
      }

      set vars [info class variables ${:prototype}]
      
      ## clone constructor
      lassign [info class constructor ${:prototype}] ctorParams ctorBody

      :mkMethod init $vars $ctorParams $ctorBody {
        debug.pt/rdengine {[:debugPrep [current class]][self] TraceInitialization indirection}
        :require namespace;
        apply [list {} {
          namespace import ::nsf::my
          @objVars@
          @body@
        } [self]]
        
        debug.pt/rdengine {[:debugOn][self] DebugCmd indirection on}
      }

      :public method destroy {args} {
        debug.pt/rdengine {[:debugOff][self] DebugCmd indirection off}
        next
      }

      ## clone all methods
      foreach m [info class methods ${:prototype} -private] {
        lassign [info class definition ${:prototype} $m] params body

        :mkMethod $m $vars $params $body {
          @objVars@
          @debugObjVars@
          @body@
		}]
	    }
	}
    }
        }
      }
      
      return
    }; # init
  }; # ClassFactory

    ##
    ## ::pt::rde::nx:
    ##
    ## The NX derivative of ::pt::rde::oo, to be inherited
    ## by the generated grammar class.
    ##
    
    ClassFactory create nx -prototype ::pt::rde::oo
    
  ##
  ## ::pt::rde::nx:
  ##
  ## The NX derivative of ::pt::rde::oo, to be inherited
  ## by the generated grammar class.
  ##
  
  ClassFactory create nx -prototype ::pt::rde::oo

  namespace export nx
}

package provide pt::rde::nx [package req pt::rde::oo].1.0
package provide pt::rde::nx [package req pt::rde::oo].1.1

# Local variables:
#    mode: tcl
#    tcl-indent-level: 2
#    indent-tabs-mode: nil
# End:

Changes to modules/pt/pt_rdengine_oo.tcl.

781
782
783
784
785
786
787
788

789
790

791
792
793

794
795
796
797
798
799
800
781
782
783
784
785
786
787

788


789
790
791
792
793
794
795
796
797
798
799
800







-
+
-
-
+



+







	# from a regular sequence of si:next_char instructions. The
	# error location will be the start of the string token we
	# wanted to match, and the message will contain the entire
	# string token. In the regular sequence we would see the exact
	# point of the mismatch instead, with the message containing
	# the expected character.

	set myok [expr {$tok eq $lex}]
	if {$tok eq $lex} {

	if {$myok} {
	    set myok 1
	    set myloc $last
	    set myerror {}
	} else {
	    set myok 0
	    set myerror [list $myloc [list [list str $tok]]]
	    incr myloc -1
	}
	debug.pt/rdengine {[InstReturn]}
	return
    }

815
816
817
818
819
820
821
822
823

824

825
826

827
828
829
830
831
832
833
815
816
817
818
819
820
821

822
823

824
825
826
827
828
829
830
831
832
833
834







-

+
-
+


+







	    return
	}
	set mycurrent [string index $mytoken $myloc]

	# Note what is needle versus hay. The token, i.e. the string
	# of allowed characters is the hay in which the current
	# character is looked, making it the needle.
	set myok [expr {[string first $mycurrent $tok] >= 0}]

	if {[string first $mycurrent $tok] >= 0} {
	if {$myok} {
	    set myok 1
	    set myerror {}
	} else {
	    set myok 0
	    set myerror [list $myloc [list [list cl $tok]]]
	    incr myloc -1
	}
	debug.pt/rdengine {[InstReturn]}
	return
    }

843
844
845
846
847
848
849
850
851


852
853

854
855
856
857
858
859
860
844
845
846
847
848
849
850


851
852
853
854
855
856
857
858
859
860
861
862







-
-
+
+


+







	    set myerror [list $myloc [list [list t $tok]]]
	    # i:fail_return
	    debug.pt/rdengine {[InstReturn]}
	    return
	}
	set mycurrent [string index $mytoken $myloc]

	set myok [expr {$tok eq $mycurrent}]
	if {$myok} {
	if {$tok eq $mycurrent} {
	    set myok 1
	    set myerror {}
	} else {
	    set myok 0
	    set myerror [list $myloc [list [list t $tok]]]
	    incr myloc -1
	}
	debug.pt/rdengine {[InstReturn]}
	return
    }

870
871
872
873
874
875
876
877
878
879


880
881

882
883

884
885
886
887
888
889
890
872
873
874
875
876
877
878



879
880


881
882
883
884
885
886
887
888
889
890
891







-
-
-
+
+
-
-
+


+







	    set myerror [list $myloc [list [list .. $toks $toke]]]
	    # i:fail_return
	    debug.pt/rdengine {[InstReturn]}
	    return
	}
	set mycurrent [string index $mytoken $myloc]

	set myok [expr {
			([string compare $toks $mycurrent] <= 0) &&
			([string compare $mycurrent $toke] <= 0)
	if {([string compare $toks $mycurrent] <= 0) &&
	    ([string compare $mycurrent $toke] <= 0)} {
		    }] ; # {}
	if {$myok} {
	    set myok 1
	    set myerror {}
	} else {
	    set myok 0
	    set myerror [list $myloc [list [pt::pe range $toks $toke]]]
	    incr myloc -1
	}
	debug.pt/rdengine {[InstReturn]}
	return
    }

Changes to modules/pt/pt_rdengine_tcl.tcl.

769
770
771
772
773
774
775
776

777
778

779
780
781

782
783
784
785
786
787
788
769
770
771
772
773
774
775

776


777
778
779
780
781
782
783
784
785
786
787
788







-
+
-
-
+



+







	# from a regular sequence of si:next_char instructions. The
	# error location will be the start of the string token we
	# wanted to match, and the message will contain the entire
	# string token. In the regular sequence we would see the exact
	# point of the mismatch instead, with the message containing
	# the expected character.

	set myok [expr {$tok eq $lex}]
	if {$tok eq $lex} {

	if {$myok} {
	    set myok 1
	    set myloc $last
	    set myerror {}
	} else {
	    set myok 0
	    set myerror [list $myloc [list [pt::pe str $tok]]]
	    incr myloc -1
	}
	debug.pt/rdengine {[InstReturn]}
	return
    }

803
804
805
806
807
808
809
810
811

812

813
814

815
816
817
818
819
820
821
803
804
805
806
807
808
809

810
811

812
813
814
815
816
817
818
819
820
821
822







-

+
-
+


+







	    return
	}
	set mycurrent [string index $mytoken $myloc]

	# Note what is needle versus hay. The token, i.e. the string
	# of allowed characters is the hay in which the current
	# character is looked, making it the needle.
	set myok [expr {[string first $mycurrent $tok] >= 0}]

	if {[string first $mycurrent $tok] >= 0} {
	if {$myok} {
	    set myok 1
	    set myerror {}
	} else {
	    set myok 0
	    set myerror [list $myloc [list [pt::pe class $tok]]]
	    incr myloc -1
	}
	debug.pt/rdengine {[InstReturn]}
	return
    }

831
832
833
834
835
836
837
838
839


840
841

842
843
844
845
846
847
848
832
833
834
835
836
837
838


839
840
841
842
843
844
845
846
847
848
849
850







-
-
+
+


+







	    set myerror [list $myloc [list [pt::pe terminal $tok]]]
	    # i:fail_return
	    debug.pt/rdengine {[InstReturn]}
	    return
	}
	set mycurrent [string index $mytoken $myloc]

	set myok [expr {$tok eq $mycurrent}]
	if {$myok} {
	if {$tok eq $mycurrent} {
	    set myok 1
	    set myerror {}
	} else {
	    set myok 0
	    set myerror [list $myloc [list [pt::pe terminal $tok]]]
	    incr myloc -1
	}
	debug.pt/rdengine {[InstReturn]}
	return
    }

858
859
860
861
862
863
864
865
866
867


868
869

870
871

872
873
874
875
876
877
878
860
861
862
863
864
865
866



867
868


869
870
871
872
873
874
875
876
877
878
879







-
-
-
+
+
-
-
+


+







	    set myerror [list $myloc [list [pt::pe range $toks $toke]]]
	    # i:fail_return
	    debug.pt/rdengine {[InstReturn]}
	    return
	}
	set mycurrent [string index $mytoken $myloc]

	set myok [expr {
			([string compare $toks $mycurrent] <= 0) &&
			([string compare $mycurrent $toke] <= 0)
	if {([string compare $toks $mycurrent] <= 0) &&
	    ([string compare $mycurrent $toke] <= 0)} {
		    }] ; # {}
	if {$myok} {
	    set myok 1
	    set myerror {}
	} else {
	    set myok 0
	    set myerror [list $myloc [list [pt::pe range $toks $toke]]]
	    incr myloc -1
	}
	debug.pt/rdengine {[InstReturn]}
	return
    }