dyndoc-ruby-core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/dyndoc/.DS_Store +0 -0
- data/dyndoc/Dyn/.postload +1 -0
- data/dyndoc/Dyn/.preload +1 -0
- data/dyndoc/Dyn/After.dyn +3 -0
- data/dyndoc/Dyn/Base.dyn +18 -0
- data/dyndoc/Dyn/Minimum.dyn +20 -0
- data/dyndoc/Model/Html/DefaultPost_html.dyn +5 -0
- data/dyndoc/Model/Html/DefaultPre_html.dyn +15 -0
- data/dyndoc/Model/Odt/DefaultPost_content.xml +3 -0
- data/dyndoc/Model/Odt/DefaultPost_tmpl_content.xml +3 -0
- data/dyndoc/Model/Odt/DefaultPre_content.xml +8 -0
- data/dyndoc/Model/Odt/DefaultPre_tmpl_content.xml +8 -0
- data/dyndoc/Model/Tex/ContentPost_tmpl.tex +1 -0
- data/dyndoc/Model/Tex/ContentPre_tmpl.tex +6 -0
- data/dyndoc/Model/Tex/DefaultPost_tmpl.tex +73 -0
- data/dyndoc/Model/Tex/DefaultPre_tmpl.tex +16 -0
- data/dyndoc/Model/Ttm/DefaultPost_tmpl.ttm +3 -0
- data/dyndoc/Model/Ttm/DefaultPre_tmpl.ttm +16 -0
- data/dyndoc/Std/Array.dyn +96 -0
- data/dyndoc/Std/Composer.dyn +38 -0
- data/dyndoc/Std/DevTag.dyn +101 -0
- data/dyndoc/Std/DynVar.dyn +23 -0
- data/dyndoc/Std/File.dyn +55 -0
- data/dyndoc/Std/Git.dyn +34 -0
- data/dyndoc/Std/List.dyn +46 -0
- data/dyndoc/Std/OOP.dyn +32 -0
- data/dyndoc/Std/Signal.dyn +18 -0
- data/dyndoc/Std/String.dyn +22 -0
- data/dyndoc/Std/Styles.dyn +1 -0
- data/dyndoc/Std/Test.dyn +282 -0
- data/dyndoc/Std/Utils.dyn +42 -0
- data/dyndoc/Std/Verb.dyn +5 -0
- data/dyndoc/Style/Notation/Math.dyn +7 -0
- data/dyndoc/Style/Notation/Stat/Classic.dyn +8 -0
- data/dyndoc/Style/Notation/Stat/Cqls.dyn +44 -0
- data/dyndoc/Style/Text/Std.dyn +5 -0
- data/dyndoc/Style/Text/StdAlias.dyn +3 -0
- data/dyndoc/Style/Text/StdTex.dyn +17 -0
- data/dyndoc/Style/Text/Txt.dyn +1 -0
- data/dyndoc/Tex/.postload +1 -0
- data/dyndoc/Tex/.preload +1 -0
- data/dyndoc/Tex/10pt_tmpl.tex +1 -0
- data/dyndoc/Tex/11pt_tmpl.tex +1 -0
- data/dyndoc/Tex/12pt_tmpl.tex +1 -0
- data/dyndoc/Tex/Article_tmpl.tex +1 -0
- data/dyndoc/Tex/Beamer.dyn_tex +35 -0
- data/dyndoc/Tex/BeamerHandout_tmpl.tex +2 -0
- data/dyndoc/Tex/Book_tmpl.tex +1 -0
- data/dyndoc/Tex/DefaultFirst_tmpl.tex +1 -0
- data/dyndoc/Tex/DefaultLast_tmpl.tex +8 -0
- data/dyndoc/Tex/Default_tmpl.tex +9 -0
- data/dyndoc/Tex/First_tmpl.tex +8 -0
- data/dyndoc/Tex/Fr_tmpl.tex +17 -0
- data/dyndoc/Tex/Header_tmpl.tex +3 -0
- data/dyndoc/Tex/InclGraph_tmpl.tex +19 -0
- data/dyndoc/Tex/InclSpatProc_tmpl.tex +70 -0
- data/dyndoc/Tex/InclSumMI_tmpl.tex +4 -0
- data/dyndoc/Tex/LargeA4_tmpl.tex +5 -0
- data/dyndoc/Tex/Last_tmpl.tex +1 -0
- data/dyndoc/Tex/Option_tmpl.tex +8 -0
- data/dyndoc/Tex/Png_tmpl.tex +1 -0
- data/dyndoc/Tex/RefCite2_tmpl.tex +16 -0
- data/dyndoc/Tex/RefCite_tmpl.tex +16 -0
- data/dyndoc/Tex/Report_tmpl.tex +1 -0
- data/dyndoc/Tex/Theorem_tmpl.tex +14 -0
- data/dyndoc/Tools/.DS_Store +0 -0
- data/dyndoc/Tools/Atom.dyn/index.dyn +42 -0
- data/dyndoc/Tools/AtomDyndocker.dyn/index.dyn +43 -0
- data/dyndoc/Tools/R/Fig.dyn +144 -0
- data/dyndoc/Tools/R/Tools.dyn +344 -0
- data/dyndoc/Tools/Tex/Beamer.dyn +204 -0
- data/dyndoc/Tools/Tex/BeamerSlide.dyn_tex +199 -0
- data/dyndoc/Tools/Tex/Pgf.dyn +115 -0
- data/dyndoc/Tools/Tex/Table.dyn +278 -0
- data/dyndoc/Tools/Tex/Tools.dyn +37 -0
- data/dyndoc/Tools/Tex/Verb.dyn +77 -0
- data/dyndoc/Tools/Web/.DS_Store +0 -0
- data/dyndoc/Tools/Web/Ace.dyn +54 -0
- data/dyndoc/Tools/Web/Code.dyn +129 -0
- data/dyndoc/Tools/Web/DHtmlX.dyn +39 -0
- data/dyndoc/Tools/Web/DataTable.dyn_html +354 -0
- data/dyndoc/Tools/Web/Html.dyn +286 -0
- data/dyndoc/Tools/Web/Html/JQuery.dyn +123 -0
- data/dyndoc/Tools/Web/Html/Styles.dyn +4 -0
- data/dyndoc/Tools/Web/JQueryTools.dyn +87 -0
- data/dyndoc/Tools/Web/Layout.dyn +86 -0
- data/dyndoc/Tools/Web/Layout/CQLS.dyn +6 -0
- data/dyndoc/Tools/Web/Layout/LJK.dyn +41 -0
- data/dyndoc/Tools/Web/TabBar.dyn +37 -0
- data/dyndoc/Tools/Web/Ttm.dyn +20 -0
- data/dyndoc/Tools/Web/Txtl.dyn +14 -0
- data/lib/dyndoc-core.rb +59 -0
- data/lib/dyndoc/base/envir.rb +541 -0
- data/lib/dyndoc/base/filter/call.rb +127 -0
- data/lib/dyndoc/base/filter/filter_mngr.rb +637 -0
- data/lib/dyndoc/base/filter/server.rb +882 -0
- data/lib/dyndoc/base/filters.rb +3 -0
- data/lib/dyndoc/base/helpers.rb +9 -0
- data/lib/dyndoc/base/helpers/core.rb +32 -0
- data/lib/dyndoc/base/helpers/parser.rb +188 -0
- data/lib/dyndoc/base/scanner.rb +886 -0
- data/lib/dyndoc/base/tags.rb +4 -0
- data/lib/dyndoc/base/tags/keys_mngr.rb +401 -0
- data/lib/dyndoc/base/tags/part_tag.rb +194 -0
- data/lib/dyndoc/base/tags/tag_mngr.rb +125 -0
- data/lib/dyndoc/base/tags/user_tag.rb +216 -0
- data/lib/dyndoc/base/tmpl.rb +6 -0
- data/lib/dyndoc/base/tmpl/eval.rb +581 -0
- data/lib/dyndoc/base/tmpl/extension.rb +337 -0
- data/lib/dyndoc/base/tmpl/manager.rb +450 -0
- data/lib/dyndoc/base/tmpl/oop.rb +57 -0
- data/lib/dyndoc/base/tmpl/parse_do.rb +2446 -0
- data/lib/dyndoc/base/tmpl/rbenvir.rb +54 -0
- data/lib/dyndoc/base/utils.rb +367 -0
- data/lib/dyndoc/common/dynArray.rb +234 -0
- data/lib/dyndoc/common/file.rb +52 -0
- data/lib/dyndoc/common/init.rb +2 -0
- data/lib/dyndoc/common/tilt.rb +149 -0
- data/lib/dyndoc/common/utils.rb +61 -0
- data/lib/dyndoc/common/uv.rb +163 -0
- data/lib/dyndoc/init/config.rb +296 -0
- data/lib/dyndoc/init/home.rb +9 -0
- data/lib/dyndoc/plugins/tex.rb +4 -0
- data/lib/dyndoc/plugins/tex/beamer.rb +208 -0
- data/lib/dyndoc/plugins/tex/tex_eval.rb +69 -0
- data/lib/dyndoc/plugins/tex/tex_parse_do.rb +25 -0
- data/lib/dyndoc/plugins/tex/tex_user_tag.rb +32 -0
- data/share/R/dyndocMsys2.R +5 -0
- data/share/R/dyndocTools.R +9 -0
- data/share/R/test.R +14 -0
- data/share/R/tools/dynArray.R +34 -0
- data/share/R/tools/dynCapture.R +84 -0
- data/share/R/tools/dynMsys2.R +54 -0
- data/share/julia/dynArray.jl +93 -0
- data/share/julia/dyndoc.jl +110 -0
- data/share/julia/ruby.jl +37 -0
- metadata +202 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module Dyndoc
|
|
2
|
+
module Ruby
|
|
3
|
+
|
|
4
|
+
class TemplateManager
|
|
5
|
+
|
|
6
|
+
def get_klass(klass)
|
|
7
|
+
return klass.split(",").map{|e| e.strip}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def get_method(call,klass0)
|
|
11
|
+
i,bCall=-1,nil
|
|
12
|
+
klass=klass0+["Object"]
|
|
13
|
+
#p call;p klass;p call+"."+klass[i+1];p @calls.keys
|
|
14
|
+
bCall=@calls[call+"."+klass[i+=1]] until bCall or i==klass0.length
|
|
15
|
+
if bCall
|
|
16
|
+
@meth,@klasses= call.dup,klass
|
|
17
|
+
@called = call << "."+ (@meth_klass=klass[i])
|
|
18
|
+
end
|
|
19
|
+
return bCall
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def get_super_method(parent=1)
|
|
23
|
+
(@klasses.map{|e| @meth+"."+e} & @calls.keys)[parent]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
module AutoClass
|
|
29
|
+
|
|
30
|
+
#be carefull, these objects does not be useable again
|
|
31
|
+
def AutoClass.find(str)
|
|
32
|
+
#declare here the different autodeclaration!
|
|
33
|
+
res={}
|
|
34
|
+
if /^\s*R\:\:([^\:]+)(?:\:(.*))?/ =~ str #for R object (and compatibility)!!!
|
|
35
|
+
res["ObjectName"]={:val=>[$1]}
|
|
36
|
+
res["objR"]={:val=>[($2 and !$2.empty?) ? $2 : $1]}
|
|
37
|
+
res["Class"]={:val=>["class(#{res["objR"][:val]})".to_R.to_a.map{|rclass| "RClass"+rclass.capitalize}.join(",")+",Object"]}
|
|
38
|
+
elsif /^\s*R\((.*)\)\s*$/ =~ str #for R expression
|
|
39
|
+
require 'digest'
|
|
40
|
+
res["ObjectName"]={:val=>["R"+Digest::SHA1.hexdigest($1)]}
|
|
41
|
+
#p [$1,$2]
|
|
42
|
+
res["objR"]={:val=>[$1]}
|
|
43
|
+
res["Class"]={:val=>["class(#{res["objR"][:val]})".to_R.to_a.map{|rclass| "RClass"+rclass.capitalize}.join(",")+",Object"]}
|
|
44
|
+
elsif /^\s*(?:Rb|Ruby|rb|ruby)\((.*)\)\s*$/ =~ str
|
|
45
|
+
require 'digest'
|
|
46
|
+
res["ObjectName"]={:val=>["Rb"+Digest::SHA1.hexdigest($1)]}
|
|
47
|
+
res["objRb"]={:val=>[$1]}
|
|
48
|
+
res["Class"]={:val=>["RbClass"+res["objRb"][:val].class+",Object"]}
|
|
49
|
+
end
|
|
50
|
+
p res
|
|
51
|
+
return res
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,2446 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
3
|
+
## TODO: .force_encoding("utf-8") needs to be added (see server.rb)
|
|
4
|
+
module Dyndoc
|
|
5
|
+
|
|
6
|
+
def Dyndoc.vars=(vars)
|
|
7
|
+
@@vars=vars
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def Dyndoc.vars
|
|
11
|
+
@@vars
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module Ruby
|
|
15
|
+
|
|
16
|
+
class TemplateManager
|
|
17
|
+
|
|
18
|
+
@@depth=0
|
|
19
|
+
|
|
20
|
+
@@cmd=["newBlck","input","require","def","func","meth","new","super","blck","do","if","for","case", "loop","r","renv","rverb","rbverb","jlverb","rout","rb","var","set","hide","format","txt","code","<","<<",">","eval","ifndef","tags","keys","opt","document","yield","get","part","style"]
|
|
21
|
+
## Alias
|
|
22
|
+
@@cmdAlias={"unless"=>"if","out"=>"do","r<"=>"r","R<"=>"R","rb<"=>"rb","r>"=>"r","R>"=>"R","rb>"=>"rb","m<"=>"m","M<"=>"m","m>"=>"m","M>"=>"m","jl>"=>"jl","jl<"=>"jl","<"=>"txt","<<"=>"txt",">"=>"txt","code"=>"txt","dyn"=>"eval","r>>"=>"rverb","R>>"=>"rverb","rout"=>"rverb","rb>>" => "rbverb","jl>>" => "jlverb","saved"=>"blck","blckAnyTag"=>"blck"}
|
|
23
|
+
@@cmd += @@cmdAlias.keys
|
|
24
|
+
|
|
25
|
+
def add_dtag(dtag,cmdAlias=nil)
|
|
26
|
+
@scan=DevTagScanner.new(:dtag) unless @scan
|
|
27
|
+
if dtag
|
|
28
|
+
@scan.merge_tag(dtag)
|
|
29
|
+
@@cmd += dtag[:instr]
|
|
30
|
+
end
|
|
31
|
+
if cmdAlias
|
|
32
|
+
@@cmdAlias[dtag[:instr][0]]=cmdAlias
|
|
33
|
+
end
|
|
34
|
+
#p @@cmd;p @@cmdAlias
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
## insert text between start and stop marks
|
|
38
|
+
## the text is automatically loaded from
|
|
39
|
+
def parse(texblock,filterLoc=nil,tags=nil)
|
|
40
|
+
#Dyndoc.warn "texblock",texblock
|
|
41
|
+
@scan=DevTagScanner.new(:dtag) unless @scan
|
|
42
|
+
@varscan=VarsScanner.new unless @varscan
|
|
43
|
+
#puts "parse";p texblock
|
|
44
|
+
if texblock.is_a? String
|
|
45
|
+
texblock=texblock.force_encoding("utf-8")
|
|
46
|
+
## Dyndoc.warn "parse",texblock
|
|
47
|
+
if @@interactive
|
|
48
|
+
Utils.parse_dyn_block_for_interactive!(texblock)
|
|
49
|
+
else
|
|
50
|
+
Utils.parse_raw_text!(texblock,self)
|
|
51
|
+
end
|
|
52
|
+
#Dyndoc.warn "After parse_raw_text",texblock
|
|
53
|
+
#puts "raw_key and raw_text";p Utils.dyndoc_raw_text
|
|
54
|
+
#escape accolade every time a new text is scanned!
|
|
55
|
+
Utils.escape!(texblock,CHARS_SET_FIRST)
|
|
56
|
+
Utils.clean_bom_utf8!(texblock)
|
|
57
|
+
Utils.silence_warnings do
|
|
58
|
+
texblock=@scan.process("{#document][#content]" + texblock + "[#}")
|
|
59
|
+
end
|
|
60
|
+
## Dyndoc.warn "parsed",texblock
|
|
61
|
+
end
|
|
62
|
+
#p "texblock";p texblock
|
|
63
|
+
unless filterLoc
|
|
64
|
+
filterLoc=FilterManager.new({:global=>@global},self)
|
|
65
|
+
filterLoc.envir["_FILENAME_CURRENT_"]=@filename.to_s if @filename
|
|
66
|
+
Envir.set_textElt!(filterLoc.envir.global,["_FILENAME_"],@filename.to_s) if @filename
|
|
67
|
+
Envir.set_textElt!(filterLoc.envir.global,["_FILENAME_ORIG_"], @tmpl_cfg[:filename_tmpl_orig].to_s) if @tmpl_cfg[:filename_tmpl_orig]
|
|
68
|
+
Envir.set_textElt!(filterLoc.envir.global,["_PWD_"],Dir.pwd) if @filename
|
|
69
|
+
#puts "filterLoc";p @filename;p filterLoc.envir["_PWD_"]
|
|
70
|
+
end
|
|
71
|
+
Dyndoc.cfg_dir[:current_doc_path]=filterLoc.envir["_PWD_"] || ""
|
|
72
|
+
##Dyndoc.warn :current_doc_path,Dyndoc.cfg_dir[:current_doc_path]
|
|
73
|
+
##partTag tricks
|
|
74
|
+
tagsOld=@tags.dup if tags #save @tags
|
|
75
|
+
@tags+=tags if tags
|
|
76
|
+
|
|
77
|
+
@vars,varsOld=filterLoc.envir,@vars
|
|
78
|
+
Dyndoc.vars=@vars
|
|
79
|
+
@filter=filterLoc unless @filter ##root filter
|
|
80
|
+
out=""
|
|
81
|
+
#p texblock
|
|
82
|
+
texblock.map{|b|
|
|
83
|
+
#p b
|
|
84
|
+
cmd=b[0].to_s
|
|
85
|
+
@curCmd=cmd
|
|
86
|
+
cmd=@@cmdAlias[cmd] if @@cmdAlias.keys.include? cmd
|
|
87
|
+
#Dyndoc.warn "parse:cmd,b",[cmd,b]
|
|
88
|
+
@@depth+=1
|
|
89
|
+
###TO temporarily AVOID RESCUE MODE:
|
|
90
|
+
###
|
|
91
|
+
if true; method("do_"+cmd).call(out,b,filterLoc); else
|
|
92
|
+
begin
|
|
93
|
+
## Dyndoc.warn "cmd",[cmd,b]
|
|
94
|
+
method("do_"+cmd).call(out,b,filterLoc)
|
|
95
|
+
## Dyndoc.warn [:out,out] if cmd=="eval"
|
|
96
|
+
rescue
|
|
97
|
+
puts "=> Leaving block depth #{@@depth}: "
|
|
98
|
+
codeText=b.inspect
|
|
99
|
+
##Dyndoc.warn "codeText",codeText
|
|
100
|
+
nbChar=(Dyndoc.cfg_dyn[:nbChar_error]) ? Dyndoc.cfg_dyn[:nbChar_error] : 80
|
|
101
|
+
if codeText.length > nbChar
|
|
102
|
+
codeText=codeText[0..((nbChar*2/3).to_int)]+" ...... "+codeText[(-(nbChar/3).to_int)..-1]
|
|
103
|
+
end
|
|
104
|
+
puts codeText
|
|
105
|
+
if @@depth==1
|
|
106
|
+
puts "=> Exiting abnormally!\n"
|
|
107
|
+
raise SystemExit
|
|
108
|
+
else
|
|
109
|
+
raise RuntimeError, "Dyn Runtime Error"
|
|
110
|
+
end
|
|
111
|
+
ensure
|
|
112
|
+
@@depth -= 1
|
|
113
|
+
end
|
|
114
|
+
###TO temporarily AVOID RESCUE MODE:
|
|
115
|
+
###
|
|
116
|
+
end
|
|
117
|
+
}
|
|
118
|
+
##restore old partTag and vars
|
|
119
|
+
@tags=tagsOld if tags
|
|
120
|
+
@tags.uniq!
|
|
121
|
+
@vars=varsOld
|
|
122
|
+
Dyndoc.vars=@vars
|
|
123
|
+
#Dyndoc.warn "parse:out",out
|
|
124
|
+
return out
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# same as parse except that input is a string and the filterLoc is the current one.
|
|
128
|
+
# Rmk: used in String::to_dyn
|
|
129
|
+
def parse_string(input,filterLoc=@filter,tags=[])
|
|
130
|
+
init_tags(input)
|
|
131
|
+
txt=input
|
|
132
|
+
return parse(txt,filterLoc,tags)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def parse_args(blck,filter)
|
|
136
|
+
## Dyndoc.warn "parse_args",blck
|
|
137
|
+
parse(blck[1..-1],filter)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def eval_args(blck,filter)
|
|
141
|
+
@rbEnvir[0].eval(parse(blck[1..-1],filter))
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def next_block(blck,i)
|
|
145
|
+
b=[]
|
|
146
|
+
while (i+1<blck.length and blck[i+1].is_a? Array)
|
|
147
|
+
i+=1
|
|
148
|
+
b << blck[i]
|
|
149
|
+
end
|
|
150
|
+
return b.unshift(i)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def next_block_until(blck,i,tagset)
|
|
154
|
+
b=[]
|
|
155
|
+
while (i+1<blck.length and !(tagset.include? blck[i+1]))
|
|
156
|
+
i+=1
|
|
157
|
+
b << blck[i]
|
|
158
|
+
end
|
|
159
|
+
return b.unshift(i)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def next_block_while(blck,i,tagset)
|
|
163
|
+
b=[]
|
|
164
|
+
while (i+1<blck.length and (tagset.include? blck[i+1]))
|
|
165
|
+
i+=1
|
|
166
|
+
b << blck[i]
|
|
167
|
+
end
|
|
168
|
+
return b.unshift(i)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def do_do(tex,blck,filter)
|
|
172
|
+
i=-1
|
|
173
|
+
begin
|
|
174
|
+
case blck[i+=1]
|
|
175
|
+
when :do,:<
|
|
176
|
+
i,*b2=next_block(blck,i)
|
|
177
|
+
parse(b2,filter)
|
|
178
|
+
when :out,:>
|
|
179
|
+
i,*b2=next_block(blck,i)
|
|
180
|
+
tex << parse(b2,filter)
|
|
181
|
+
when :nl,:"\\n"
|
|
182
|
+
i,*b2=next_block(blck,i)
|
|
183
|
+
tex << "\n" << parse(b2,filter)
|
|
184
|
+
end
|
|
185
|
+
end while i<blck.length-1
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
=begin
|
|
189
|
+
def get_named_blck(b2,filter)
|
|
190
|
+
vars=nil #default: no named block!
|
|
191
|
+
if b2[0][0]==:named
|
|
192
|
+
vars=filter.apply(b2[0][1].strip)
|
|
193
|
+
vars.gsub!("#",@Fmt)
|
|
194
|
+
b2=b2[0][2..-1]
|
|
195
|
+
if vars[0,1]==">"
|
|
196
|
+
fmts,vars=vars[1..-1].split(":")
|
|
197
|
+
b2=nil unless fmts.split(",").map{|e| e.strip}.include? @fmt
|
|
198
|
+
else
|
|
199
|
+
#if a variable ends with FORMATS element
|
|
200
|
+
if (ind=vars.rindex(/(#{Dyndoc::FORMATS.join("|")})$/))
|
|
201
|
+
#do not evaluate unless right format
|
|
202
|
+
b2=nil unless vars[ind..-1]==@Fmt
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
p [vars,b2]
|
|
207
|
+
return [vars,b2]
|
|
208
|
+
end
|
|
209
|
+
=end
|
|
210
|
+
|
|
211
|
+
#new syntax: [#>] tag1,tag2,... > var [...]
|
|
212
|
+
def get_named_blck(b2,filter)
|
|
213
|
+
vars=nil #default: no named block!
|
|
214
|
+
if b2[0][0]==:named
|
|
215
|
+
vars=filter.apply(b2[0][1].strip)
|
|
216
|
+
vars.gsub!("#",@Fmt)
|
|
217
|
+
b2=b2[0][2..-1]
|
|
218
|
+
if vars.include? ">"
|
|
219
|
+
fmts,vars=vars.split(">")
|
|
220
|
+
b2=nil unless fmts.split(",").map{|e| e.strip}.include? @fmt
|
|
221
|
+
#TODO: changer et mettre la condition sur les tags!!!! et non uniquement sur le format!
|
|
222
|
+
#HOWTO: b2 non nil s'il existe un document pour lequel cette partie est à évaluer!
|
|
223
|
+
else
|
|
224
|
+
#if a variable ends with FORMATS element
|
|
225
|
+
if (ind=vars.rindex(/(#{Dyndoc::FORMATS.join("|")})$/))
|
|
226
|
+
#do not evaluate unless right format
|
|
227
|
+
b2=nil unless vars[ind..-1]==@Fmt
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
return [vars,b2]
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def get_named_blck_simple(b2,filter)
|
|
235
|
+
vars=nil #default: no named block!
|
|
236
|
+
if b2[0][0]==:named
|
|
237
|
+
vars=filter.apply(b2[0][1].strip)
|
|
238
|
+
b2=b2[0][2..-1]
|
|
239
|
+
end
|
|
240
|
+
return [vars,b2]
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def make_named_blck(tex,filter,vars,b2,bang=false)
|
|
244
|
+
#puts "make_named_blck:b2";p b2
|
|
245
|
+
val=parse(b2,filter)
|
|
246
|
+
#puts "make_named_blck:val";p val
|
|
247
|
+
# NB: bang is processed only at the end and not in the recursive process of parsing!
|
|
248
|
+
# The reason is that maybe the form <NAME>! is not correct in some old document!
|
|
249
|
+
#Dyndoc.warn "make_named_blck:val",[val,process_bang(val),filter.rbEnvir] if bang
|
|
250
|
+
#DEBUG ONLY: val2=val if bang
|
|
251
|
+
val=parse(process_bang(val),filter) if bang
|
|
252
|
+
#Dyndoc.warn "make_named_blck:val2",[val2,val] if bang
|
|
253
|
+
val=Utils.format_blocktext(val)
|
|
254
|
+
#puts "format_blocktext:val";p val
|
|
255
|
+
if vars
|
|
256
|
+
vars.split(",").each{|var|
|
|
257
|
+
eval_SET(var.strip,val,filter)
|
|
258
|
+
}
|
|
259
|
+
else
|
|
260
|
+
tex << val.force_encoding("utf-8")
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
#######################################
|
|
266
|
+
## format helpers
|
|
267
|
+
#######################################
|
|
268
|
+
def format(which=:all)
|
|
269
|
+
formats={
|
|
270
|
+
:output => outputFormat,
|
|
271
|
+
:blck => blockFormat,
|
|
272
|
+
:parent => parentFormat,
|
|
273
|
+
:default => defaultFormat,
|
|
274
|
+
:current => currentFormat
|
|
275
|
+
}
|
|
276
|
+
which==:all ? formats : formats[which]
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def outputFormat
|
|
280
|
+
@fmtOutput
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
def defaultFormat
|
|
284
|
+
(@defaultFmtContainer.to_s)[0...-1]
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def currentFormat
|
|
288
|
+
(@curFmtContainer.to_s)[0...-1]
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def blockFormat
|
|
292
|
+
@fmtContainer[0] ? (@fmtContainer[0].to_s)[0...-1] : nil
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def parentFormat(level=1)
|
|
296
|
+
@fmtContainer[level] ? (@fmtContainer[level].to_s)[0...-1] : nil
|
|
297
|
+
end
|
|
298
|
+
#########################################
|
|
299
|
+
|
|
300
|
+
def do_blck(tex,blck,filter)
|
|
301
|
+
#begin puts "do_blck";p @curCmd;p blck; end if @curCmd=="blck"
|
|
302
|
+
i=0 #blck[0]==:blck
|
|
303
|
+
#New mode (071108): save and restore named block!
|
|
304
|
+
curCmd,blckname=@curCmd,nil
|
|
305
|
+
|
|
306
|
+
if blck[1].is_a? Array
|
|
307
|
+
## Fix blckAnyTag when starting with text => add :>
|
|
308
|
+
if blck[0] == :blckAnyTag and blck[1][0]==:main
|
|
309
|
+
blck.insert(1,:>)
|
|
310
|
+
else
|
|
311
|
+
blckname=parse([blck[1]],filter).strip
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
##Dyndoc.warn :blckname,[blckname,blck]
|
|
315
|
+
if curCmd=="saved"
|
|
316
|
+
####################################################################
|
|
317
|
+
## TODO: all the stuff generated has to be saved!
|
|
318
|
+
## tex records all the generated content but what about the files!
|
|
319
|
+
## Maybe, keep tracks of all files generated! By default put it inside inside .dyn_out directory
|
|
320
|
+
## but also records which files have been generated in the saved mode!
|
|
321
|
+
####################################################################
|
|
322
|
+
#blckname=parse([blck[1]],filter).strip
|
|
323
|
+
##puts "blckname";p blckname
|
|
324
|
+
return if blckname.empty?
|
|
325
|
+
unless blck[2]
|
|
326
|
+
#p Utils.dyndoc_raw_var_ls
|
|
327
|
+
#p blckname
|
|
328
|
+
if Utils.dyndoc_raw_var_ls.include? blckname
|
|
329
|
+
tex << Utils.dyndoc_raw_var_content(blckname,self)
|
|
330
|
+
end
|
|
331
|
+
else
|
|
332
|
+
## fetch the result from the saved result if it exists or force regeneration at the command line!
|
|
333
|
+
res=Utils.saved_content_get(blckname,self,true) #true here is very important since input user is checked first to know if content needs to be regenerated!
|
|
334
|
+
#puts "direct:res";p res
|
|
335
|
+
unless res
|
|
336
|
+
res=parse([blck[2..-1].unshift(:blck)],filter)
|
|
337
|
+
#puts "created:res";p res
|
|
338
|
+
## saved_contents_file does not not contain this block!
|
|
339
|
+
Utils.saved_content_add_as_variable(blckname,res,@filename)
|
|
340
|
+
end
|
|
341
|
+
tex << res ## stop here!
|
|
342
|
+
end
|
|
343
|
+
else #curCmd=="blck"
|
|
344
|
+
@blckDepth ||= []
|
|
345
|
+
@blckDepth << curCmd
|
|
346
|
+
#puts "blckDepth";p @blckDepth;p @@newBlcks.keys
|
|
347
|
+
if !(cmdBlcks=@@newBlcks.keys & @blckDepth).empty?
|
|
348
|
+
#puts "cmdBlcks";p cmdBlcks
|
|
349
|
+
#puts "blckDepth";p @blckDepth
|
|
350
|
+
#p blck
|
|
351
|
+
@newBlckMode=true
|
|
352
|
+
(["blckAnyTag"]+cmdBlcks).each do |cmd|
|
|
353
|
+
#Dyndoc.warn "cmd",[cmd.to_sym,blck[0]]
|
|
354
|
+
if blck[0]==cmd.to_sym
|
|
355
|
+
# Fix bug when calling newBlck with no space at the beginning
|
|
356
|
+
# blckname==nil only for blckAnyTag
|
|
357
|
+
if !blckname and cmd!="blckAnyTag"
|
|
358
|
+
blckname=""
|
|
359
|
+
blck=blck[0,1]+[[:main,""]]+blck[1..-1]
|
|
360
|
+
end
|
|
361
|
+
#Dyndoc.warn "BEFORE COMPLETED_BLCK",[cmd,blckname,blck]
|
|
362
|
+
blck=completed_newBlck(cmd,blckname,blck,filter)
|
|
363
|
+
#Dyndoc.warn "AFTER COMPLETED_BLCK",blck
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
elsif blck[1].is_a? Array
|
|
368
|
+
#blckname=parse([blck[1]],filter).strip
|
|
369
|
+
to_end=!blckname.empty?
|
|
370
|
+
if blck[2] and to_end
|
|
371
|
+
mode,to_exec=:normal,nil
|
|
372
|
+
if ["+",">","$"].include? blckname[0,1]
|
|
373
|
+
mode,blckname = :append,blckname[1..-1].strip
|
|
374
|
+
elsif ["^","<"].include? blckname[0,1]
|
|
375
|
+
mode,blckname = :prepend,blckname[1..-1].strip
|
|
376
|
+
end
|
|
377
|
+
to_exec,blckname=true,blckname[0...-1] if blckname[-1,1]=="!"
|
|
378
|
+
#Dyndoc.warn "to_exec",[to_exec,blckname]
|
|
379
|
+
@savedBlocks[blckname]= ( mode==:normal ? blck[2..-1].unshift(:blck) : ( mode==:append ? @savedBlocks[blckname]+blck[2..-1] : (blck[2..-1]+@savedBlocks[blckname][1..-1]).unshift(:blck) ) )
|
|
380
|
+
tex << parse([@savedBlocks[blckname]],filter) if to_exec
|
|
381
|
+
elsif to_end
|
|
382
|
+
#p @savedBlocks[blckname]
|
|
383
|
+
#puts "blck #{blckname}"
|
|
384
|
+
tex << parse([@savedBlocks[blckname]],filter) if @savedBlocks[blckname]
|
|
385
|
+
end
|
|
386
|
+
#p to_stop;p blck
|
|
387
|
+
return if to_end
|
|
388
|
+
end
|
|
389
|
+
# normal (old) mode
|
|
390
|
+
cond,cond_tag=true,true
|
|
391
|
+
condArch=[]
|
|
392
|
+
|
|
393
|
+
#p blck if curCmd=="tabbar"
|
|
394
|
+
if @@newBlcks.keys.include? @blckDepth[-1]
|
|
395
|
+
@blckName ||= []
|
|
396
|
+
tmp=blck[1][1].strip
|
|
397
|
+
@blckName << (tmp.empty? ? `uuidgen`.strip : tmp)
|
|
398
|
+
#puts "blckNAME";p @blckName
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
begin
|
|
402
|
+
case (current_block_tag=blck[i+=1])
|
|
403
|
+
when :"%"
|
|
404
|
+
i,*b2=next_block(blck,i)
|
|
405
|
+
when :"?"
|
|
406
|
+
i,*b2=next_block(blck,i)
|
|
407
|
+
if cond_tag
|
|
408
|
+
filter.outType=":rb"
|
|
409
|
+
##Dyndoc.warn "do_block:?:b2",b2
|
|
410
|
+
code=parse_args(b2[0],filter).strip
|
|
411
|
+
#puts "do_block:?:code"; p code
|
|
412
|
+
mode=code.downcase
|
|
413
|
+
#puts "do_block:?:mode";p mode
|
|
414
|
+
if ["!","else"].include? mode
|
|
415
|
+
cond = !cond
|
|
416
|
+
elsif ["*","all","end"].include? mode
|
|
417
|
+
cond,condArch=true,[]
|
|
418
|
+
elsif mode=~/^prev/
|
|
419
|
+
nbPop=mode.scan(/ \d*$/)
|
|
420
|
+
nbPop=(nbPop.empty? ? 1 : nbPop[0].to_i)
|
|
421
|
+
nbPop.times{cond=condArch.pop}
|
|
422
|
+
else
|
|
423
|
+
mode,code=code[0,1],code[1..-1] if ["&","|"].include? code[0,1]
|
|
424
|
+
cond2=@rbEnvir[0].eval(code)
|
|
425
|
+
condArch << cond
|
|
426
|
+
if mode=="&"
|
|
427
|
+
cond= cond & cond2
|
|
428
|
+
elsif mode=="|"
|
|
429
|
+
cond= cond | cond2
|
|
430
|
+
else
|
|
431
|
+
cond=cond2
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
filter.outType=nil
|
|
435
|
+
end
|
|
436
|
+
#puts "cond in block #{code}=";p cond
|
|
437
|
+
when :tag,:"??"
|
|
438
|
+
## Dyndoc.warn "tag:blck",blck
|
|
439
|
+
i,*b2=next_block(blck,i)
|
|
440
|
+
## Dyndoc.warn "tag:b2",b2
|
|
441
|
+
code=parse(b2,filter).strip.downcase
|
|
442
|
+
## Dyndoc.warn "tag",code
|
|
443
|
+
if ["!","else"].include? code
|
|
444
|
+
cond_tag = !cond_tag
|
|
445
|
+
elsif ["*","all","end"].include? code
|
|
446
|
+
cond_tag=true
|
|
447
|
+
else
|
|
448
|
+
mode=nil
|
|
449
|
+
mode,code=code[0,1],code[1..-1] if ["&","|","-"].include? code[0,1]
|
|
450
|
+
## Dyndoc.warn "mode and code",[mode,code]
|
|
451
|
+
tags=TagManager.make_tags(code)
|
|
452
|
+
## Dyndoc.warn "tags, @tags",[tags,@tags]
|
|
453
|
+
|
|
454
|
+
cond2_tag=TagManager.tags_ok?(tags,@tags)
|
|
455
|
+
#puts "mode, cond_tag et cond2_tag";p mode; p cond_tag;p cond2_tag
|
|
456
|
+
if mode=="&"
|
|
457
|
+
#puts "tags, @tags";p tags;p @tags
|
|
458
|
+
#puts "mode, cond_tag et cond2_tag";p mode; p cond_tag;p cond2_tag; p cond_tag.class;p cond2_tag.class;p cond_tag and cond2_tag
|
|
459
|
+
#RMK: a=0 and nil => a=0 because a stays to be a FixNum.
|
|
460
|
+
cond_tag= (cond_tag and cond2_tag ? 0 : nil)
|
|
461
|
+
#puts "INTER cond_tag->";p cond_tag
|
|
462
|
+
elsif mode=="|"
|
|
463
|
+
cond_tag = (cond_tag or cond2_tag ? 0 : nil)
|
|
464
|
+
elsif mode=="-"
|
|
465
|
+
cond_tag = !cond2_tag
|
|
466
|
+
else
|
|
467
|
+
cond_tag = cond2_tag
|
|
468
|
+
end
|
|
469
|
+
#puts "FINAL cond_tag->";p cond_tag
|
|
470
|
+
end
|
|
471
|
+
#puts "cond_tag in block #{code}=";p cond_tag
|
|
472
|
+
when :do,:<
|
|
473
|
+
i,*b2=next_block(blck,i)
|
|
474
|
+
parse(b2,filter) if cond_tag and cond
|
|
475
|
+
when :"r<",:"rb<",:"R<",:"m<",:"M<",:"jl<"
|
|
476
|
+
# if current_block_tag==:"jl<"
|
|
477
|
+
# ##p "iciiiii"
|
|
478
|
+
# end
|
|
479
|
+
newblck=blck[i]
|
|
480
|
+
#puts "newblock";p newblck;p blck
|
|
481
|
+
i,*b2=next_block(blck,i)
|
|
482
|
+
#p b2
|
|
483
|
+
code=b2[0][1..-1]
|
|
484
|
+
##p code
|
|
485
|
+
#need to be cleaned with no bracket at the beginning and the end of the block!
|
|
486
|
+
clean_block_without_bracket(code)
|
|
487
|
+
if cond_tag and cond
|
|
488
|
+
b2=[code.unshift(newblck)]
|
|
489
|
+
##puts "r<;rb<";p b2
|
|
490
|
+
filter.outType=":"+(blck[i].to_s)[0...-1]
|
|
491
|
+
#p filter.outType
|
|
492
|
+
parse(b2,filter)
|
|
493
|
+
filter.outType=nil
|
|
494
|
+
end
|
|
495
|
+
when :"=" #equivalent of :var but DO NOT USE :var
|
|
496
|
+
i,*b2=next_block(blck,i)
|
|
497
|
+
if cond_tag and cond
|
|
498
|
+
#puts "=:b2";p b2
|
|
499
|
+
b=make_var_block(b2.unshift(:var),filter)
|
|
500
|
+
#puts "=:b";p b
|
|
501
|
+
eval_VARS(b,filter)
|
|
502
|
+
end
|
|
503
|
+
when :"-"
|
|
504
|
+
i,*b2=next_block(blck,i)
|
|
505
|
+
if cond_tag and cond
|
|
506
|
+
#puts "-:b2"
|
|
507
|
+
parse(b2,filter).strip.split(",").each{|key| @vars.remove(key)}
|
|
508
|
+
end
|
|
509
|
+
when :+
|
|
510
|
+
##Dyndoc.warn "+:-1:block",[i,blck]
|
|
511
|
+
i,*b2=next_block(blck,i)
|
|
512
|
+
##Dyndoc.warn "+:0:i,b2",[i,b2]
|
|
513
|
+
if cond_tag and cond
|
|
514
|
+
var,pos=b2[0][1].split(",")
|
|
515
|
+
## Dyndoc.warn "+:1:var,pos",[var,pos]
|
|
516
|
+
pos = -1 unless pos
|
|
517
|
+
pos=pos.to_i
|
|
518
|
+
var=filter.apply(var)
|
|
519
|
+
varObj=@vars.extract_raw(var)
|
|
520
|
+
## Dyndoc.warn "+:2:var",[var,varObj,(varObj.is_a? Array)]
|
|
521
|
+
if varObj
|
|
522
|
+
if varObj.is_a? Array
|
|
523
|
+
pos=varObj.length+pos+1 if pos<0
|
|
524
|
+
varNew=var+".#{pos}"
|
|
525
|
+
#new element
|
|
526
|
+
## Needs to deep dup (dup is not enough!)
|
|
527
|
+
b2dup=Marshal.load( Marshal.dump(b2) )
|
|
528
|
+
b2dup[0][1]="::ADDED_ELT"
|
|
529
|
+
## Dyndoc.warn "+:3:b2,b2dup,blck",[b2,b2dup,blck]
|
|
530
|
+
b=make_var_block(b2dup.unshift(:var),filter)
|
|
531
|
+
## Dyndoc.warn "b",b
|
|
532
|
+
eval_VARS(b,filter)
|
|
533
|
+
type=@vars.extract_raw("::ADDED_ELT").class
|
|
534
|
+
res={:val=>[""]}
|
|
535
|
+
res=[] if type==Array
|
|
536
|
+
res={} if type==Hash
|
|
537
|
+
varObj.insert(pos,res)
|
|
538
|
+
## Dyndoc.warn "varObj",[varObj,b2]
|
|
539
|
+
b2dup[1][1]=varNew
|
|
540
|
+
b=make_var_block(b2dup,filter)
|
|
541
|
+
## Dyndoc.warn "+:4:b2,b2dup,blck",[b2,b2dup,blck]
|
|
542
|
+
eval_VARS(b,filter)
|
|
543
|
+
elsif varObj.is_a? Hash and varObj[:val]
|
|
544
|
+
## Dyndoc.warn "+:else1:blck",blck
|
|
545
|
+
## Needs to deep dup (dup is not enough!)
|
|
546
|
+
b2dup=Marshal.load( Marshal.dump(b2) )
|
|
547
|
+
b2dup[0][1]="::ADDED_ELT"
|
|
548
|
+
## Dyndoc.warn "+:3else:b2",[b2,b2dup]
|
|
549
|
+
## Dyndoc.warn "+:else2:blck",blck
|
|
550
|
+
## Dyndoc.warn "+:else2:b2.unshift(:var)",b2dup.unshift(:var)
|
|
551
|
+
b=make_var_block(b2dup.unshift(:var),filter)
|
|
552
|
+
## Dyndoc.warn "+:4else:b",b
|
|
553
|
+
## Dyndoc.warn "+:else2:blck",blck
|
|
554
|
+
eval_VARS(b,filter)
|
|
555
|
+
res=@vars.extract_raw("::ADDED_ELT")
|
|
556
|
+
varObj[:val][0].insert(pos,res[:val][0])
|
|
557
|
+
## Dyndoc.warn "+:5else:varObj",[varObj,b]
|
|
558
|
+
end
|
|
559
|
+
#puts "varNew:#{var}";p @vars.extract_raw(var)
|
|
560
|
+
end
|
|
561
|
+
end
|
|
562
|
+
when :out,:>,:">!" # :>! is in some sense equivalent of :set
|
|
563
|
+
i,*b2=next_block(blck,i)
|
|
564
|
+
#puts "block >, cond_tag, cond";p cond_tag ;p cond
|
|
565
|
+
if cond_tag and cond and !b2.empty?
|
|
566
|
+
#puts "do_blck:out";p b2
|
|
567
|
+
#p blck
|
|
568
|
+
vars,b2=get_named_blck(b2,filter)
|
|
569
|
+
#Dyndoc.warn "do_blck:out, >!",[vars,b2] if current_block_tag==:">!"
|
|
570
|
+
#p b2
|
|
571
|
+
#p current_block_tag
|
|
572
|
+
#p current_block_tag==:">!"
|
|
573
|
+
make_named_blck(tex,filter,vars,b2,current_block_tag==:">!") if b2
|
|
574
|
+
end
|
|
575
|
+
when :"_<"
|
|
576
|
+
i,*b2=next_block(blck,i)
|
|
577
|
+
val=parse(b2,filter).strip
|
|
578
|
+
@defaultFmtContainer=(val+">").to_sym if ["","html","tex","txtl","ttm","md","adoc"].include? val
|
|
579
|
+
when :"txtl>",:"ttm>",:"tex>",:"html>",:"_>",:"__>",:"md>",:"adoc>"
|
|
580
|
+
newblck=blck[i]
|
|
581
|
+
@curFmtContainer=:"tex>" unless @curFmtContainer
|
|
582
|
+
if newblck==:"__>"
|
|
583
|
+
newblck=@curFmtContainer #the previous one
|
|
584
|
+
elsif newblck==:"_>"
|
|
585
|
+
newblck=(@defaultFmtContainer ? @defaultFmtContainer : @curFmtContainer) #the default one
|
|
586
|
+
else
|
|
587
|
+
@curFmtContainer=nil #to redefine at the end
|
|
588
|
+
end
|
|
589
|
+
i,*b2=next_block(blck,i)
|
|
590
|
+
if cond_tag and cond and !b2.empty? #if b2 empty nothing to do!
|
|
591
|
+
@fmtContainer.unshift newblck
|
|
592
|
+
val=parse(b2,filter)
|
|
593
|
+
if @fmtContainer[1] and @fmtContainer[1]==@fmtContainer[0] #no need to convert!
|
|
594
|
+
tex << val
|
|
595
|
+
else #convert
|
|
596
|
+
## Dyndoc.warn "txtl formats",[@fmtContainer[0],@fmtOutput,@fmtContainer[1]]
|
|
597
|
+
tex << Dyndoc::Converter.convert(val,@fmtContainer[0],@fmtOutput,@fmtContainer[1]) #last parameter: true means to protect
|
|
598
|
+
end
|
|
599
|
+
@curFmtContainer=@fmtContainer[0] unless @curFmtContainer
|
|
600
|
+
@fmtContainer.shift
|
|
601
|
+
end
|
|
602
|
+
|
|
603
|
+
when :"r>",:"rb>",:"R>",:"m>",:"M>",:"jl>"
|
|
604
|
+
newblck=blck[i]
|
|
605
|
+
i,*b2=next_block(blck,i)
|
|
606
|
+
#puts "RB>";p b2;p i;p blck
|
|
607
|
+
if cond_tag and cond and !b2.empty? #if b2 empty nothing to do!
|
|
608
|
+
vars,b2=get_named_blck(b2,filter)
|
|
609
|
+
if b2
|
|
610
|
+
b2=[b2.unshift(newblck)]
|
|
611
|
+
filter.outType=":"+(blck[i].to_s)[0...-1]
|
|
612
|
+
make_named_blck(tex,filter,vars,b2)
|
|
613
|
+
filter.outType=nil
|
|
614
|
+
end
|
|
615
|
+
end
|
|
616
|
+
when :"r>>",:"R>>",:rout,:rverb
|
|
617
|
+
newblck=blck[i]
|
|
618
|
+
i,*b2=next_block(blck,i)
|
|
619
|
+
if cond_tag and cond
|
|
620
|
+
vars,b2=get_named_blck(b2,filter)
|
|
621
|
+
if b2
|
|
622
|
+
b2=[b2.unshift(newblck)]
|
|
623
|
+
filter.outType=":r" #+(blck[i].to_s)[0...-1]
|
|
624
|
+
=begin
|
|
625
|
+
val=parse(b2,filter)
|
|
626
|
+
#puts "make_named_blck:val";p val
|
|
627
|
+
val=Utils.format_blocktext(val)
|
|
628
|
+
#puts "format_blocktext:val";p val
|
|
629
|
+
if vars
|
|
630
|
+
vars.split(",").each{|var|
|
|
631
|
+
eval_SET(var.strip,val,filter)
|
|
632
|
+
}
|
|
633
|
+
else
|
|
634
|
+
tex << val
|
|
635
|
+
end
|
|
636
|
+
=end
|
|
637
|
+
make_named_blck(tex,filter,vars,b2)
|
|
638
|
+
filter.outType=nil
|
|
639
|
+
end
|
|
640
|
+
end
|
|
641
|
+
when :"jl>>",:jlverb,:"rb>>",:rbverb
|
|
642
|
+
newblck=blck[i]
|
|
643
|
+
i,*b2=next_block(blck,i)
|
|
644
|
+
if cond_tag and cond
|
|
645
|
+
vars,b2=get_named_blck(b2,filter)
|
|
646
|
+
if b2
|
|
647
|
+
b2=[b2.unshift(newblck)]
|
|
648
|
+
filter.outType=newblck.to_s[0,2].to_sym #":jl" #+(blck[i].to_s)[0...-1]
|
|
649
|
+
=begin
|
|
650
|
+
val=parse(b2,filter)
|
|
651
|
+
#puts "make_named_blck:val";p val
|
|
652
|
+
val=Utils.format_blocktext(val)
|
|
653
|
+
#puts "format_blocktext:val";p val
|
|
654
|
+
if vars
|
|
655
|
+
vars.split(",").each{|var|
|
|
656
|
+
eval_SET(var.strip,val,filter)
|
|
657
|
+
}
|
|
658
|
+
else
|
|
659
|
+
tex << val
|
|
660
|
+
end
|
|
661
|
+
=end
|
|
662
|
+
make_named_blck(tex,filter,vars,b2)
|
|
663
|
+
filter.outType=nil
|
|
664
|
+
end
|
|
665
|
+
end
|
|
666
|
+
when :>>
|
|
667
|
+
i,*b2=next_block(blck,i)
|
|
668
|
+
if cond_tag and cond
|
|
669
|
+
file,b2=get_named_blck(b2,filter)
|
|
670
|
+
if b2 and file
|
|
671
|
+
mode=:save
|
|
672
|
+
case file[-1,1]
|
|
673
|
+
when "?"
|
|
674
|
+
mode=:exist
|
|
675
|
+
file=file[0...-1]
|
|
676
|
+
when "!"
|
|
677
|
+
mode=:nothing
|
|
678
|
+
file=file[0...-1]
|
|
679
|
+
end
|
|
680
|
+
mode=(File.exist?(file) ? :nothing : :save ) if mode==:exist
|
|
681
|
+
tex2=parse(b2,filter)
|
|
682
|
+
tex2==Utils.format_blocktext(tex2)
|
|
683
|
+
if mode==:save
|
|
684
|
+
File.open(file,"w") do |f|
|
|
685
|
+
f << tex2
|
|
686
|
+
end
|
|
687
|
+
end
|
|
688
|
+
end
|
|
689
|
+
end
|
|
690
|
+
when :nl,:"\\n"
|
|
691
|
+
i,*b2=next_block(blck,i)
|
|
692
|
+
if cond_tag and cond
|
|
693
|
+
tex << "\n" << parse(b2,filter)
|
|
694
|
+
#puts "nl";p tex
|
|
695
|
+
end
|
|
696
|
+
when :yield #only inside a {#def] block!
|
|
697
|
+
i,*b2=next_block(blck,i)
|
|
698
|
+
if cond_tag and cond
|
|
699
|
+
codename=parse(b2,filter).strip
|
|
700
|
+
#p codename
|
|
701
|
+
#p @def_blck
|
|
702
|
+
make_yield(tex,codename,filter)
|
|
703
|
+
end
|
|
704
|
+
when :<< #input without variable entries
|
|
705
|
+
i,*b2=next_block(blck,i)
|
|
706
|
+
if cond_tag and cond
|
|
707
|
+
#p b2
|
|
708
|
+
var,b2=get_named_blck(b2,filter)
|
|
709
|
+
#p var;p b2
|
|
710
|
+
tmpl=parse(b2,filter).strip
|
|
711
|
+
#p tmpl
|
|
712
|
+
val=eval_INPUT(tmpl,[],filter)
|
|
713
|
+
if var
|
|
714
|
+
eval_SET(var.strip,val,filter)
|
|
715
|
+
else
|
|
716
|
+
tex << val
|
|
717
|
+
end
|
|
718
|
+
end
|
|
719
|
+
else
|
|
720
|
+
i,*b2=next_block(blck,i)
|
|
721
|
+
blckCmd=(current_block_tag.is_a? Symbol) ? ("do_blck_"+curCmd+"_"+current_block_tag.to_s).to_sym : nil
|
|
722
|
+
#Dyndoc.warn :blckCmd,[current_block_tag,blckCmd,(methods.include? blckCmd),methods.sort]
|
|
723
|
+
blckCmd=nil if blckCmd and !(methods.include? blckCmd)
|
|
724
|
+
#Dyndoc.warn :blckCmd2,blckCmd
|
|
725
|
+
if cond_tag and cond and blckCmd
|
|
726
|
+
#Dyndoc.warn :blck_command #, [blckCmd,b2]
|
|
727
|
+
method(blckCmd).call(tex,b2,filter)
|
|
728
|
+
end
|
|
729
|
+
end
|
|
730
|
+
end while i<blck.length-1
|
|
731
|
+
@blckName.pop if @blckName and @@newBlcks.keys.include? @blckDepth[-1]
|
|
732
|
+
@blckDepth.pop
|
|
733
|
+
@newBlckMode=nil
|
|
734
|
+
end
|
|
735
|
+
end
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
def do_format(tex,blck,filter)
|
|
739
|
+
i=0
|
|
740
|
+
i,*b2=next_block(blck,i)
|
|
741
|
+
format=parse(b2,filter).strip
|
|
742
|
+
puts "format=#{format}"
|
|
743
|
+
@fmtOutput=format
|
|
744
|
+
end
|
|
745
|
+
|
|
746
|
+
def do_main(tex,b,filter)
|
|
747
|
+
#OLD: @userTag.evalUserTags(tex,b[1],filter)
|
|
748
|
+
#NEW: simply apply the filter on the text
|
|
749
|
+
#b[1]="" unless b[1]
|
|
750
|
+
#puts "do_main";p b[1]
|
|
751
|
+
res=filter.apply(b[1])
|
|
752
|
+
unless res.scan(/^__RAW__/).empty?
|
|
753
|
+
res=Utils.protect_format_blocktext(res)
|
|
754
|
+
else
|
|
755
|
+
res=Utils.format_blocktext(res)
|
|
756
|
+
end
|
|
757
|
+
#puts res
|
|
758
|
+
tex << res
|
|
759
|
+
#TODO: maybe propose a language like textile to be converted in any format
|
|
760
|
+
end
|
|
761
|
+
|
|
762
|
+
=begin
|
|
763
|
+
def do_TXT(tex,b,i,splitter,filter)
|
|
764
|
+
out = eval_TXT(b,filter)
|
|
765
|
+
#p "OUT";p out
|
|
766
|
+
return unless out
|
|
767
|
+
tex << out << "\n" unless @echo<0
|
|
768
|
+
end
|
|
769
|
+
=end
|
|
770
|
+
|
|
771
|
+
def make_var_block(blck,filter,dict=nil)
|
|
772
|
+
b,i,go=[],-1,true
|
|
773
|
+
cpt=0
|
|
774
|
+
#p blck
|
|
775
|
+
begin
|
|
776
|
+
#p blck[i+1]
|
|
777
|
+
case blck[i+=1]
|
|
778
|
+
when :var, :","
|
|
779
|
+
#p blck[i]
|
|
780
|
+
i,*b2=next_block(blck,i)
|
|
781
|
+
#puts "make_var";p i;p b2
|
|
782
|
+
#deal with
|
|
783
|
+
unless b2.empty?
|
|
784
|
+
name=nil
|
|
785
|
+
if b2[0][0]==:named
|
|
786
|
+
b2=b2[0]
|
|
787
|
+
if b2[0]==:named
|
|
788
|
+
b2 << [:main,""] unless b2[2]
|
|
789
|
+
var=b2[2..-1]
|
|
790
|
+
name=filter.apply(b2[1])
|
|
791
|
+
#puts "make_var_block:name";p name
|
|
792
|
+
#p dict
|
|
793
|
+
if dict and (name2=dict.find{|v| v=~/^#{name}/})
|
|
794
|
+
name=name2
|
|
795
|
+
dict.delete(name)
|
|
796
|
+
end
|
|
797
|
+
b2=var
|
|
798
|
+
end
|
|
799
|
+
end
|
|
800
|
+
|
|
801
|
+
end
|
|
802
|
+
#p name
|
|
803
|
+
#p b2
|
|
804
|
+
#p dict
|
|
805
|
+
# DO NOT remove lstrip! Otherwise, there is an error of compilation in test/V3/testECO2.dyn! => README.250808: OK now! The explanation was that is was needed only by @varscan (solved now)! The __STR__ escape the first and last whitespaces
|
|
806
|
+
#p b2
|
|
807
|
+
b2=parse(b2,filter) #.lstrip #.split("\n")
|
|
808
|
+
#puts "name";p name
|
|
809
|
+
#puts "b2222";p b2
|
|
810
|
+
|
|
811
|
+
sep=(dict ? "__ELTS__" : "\n" )
|
|
812
|
+
#OLD: unless b2.empty? or b2=~/^:?:[#{FilterManager.letters}]*(?:\[(.*)\])?\s*=?(?:=>|,)/
|
|
813
|
+
unless b2=~ /^:?:[#{FilterManager.letters}]*(?:\[(.*)\])?\s*=?(?:=>|,)/
|
|
814
|
+
#puts "ICCIII";p b2
|
|
815
|
+
name=(dict ? dict.shift : "var#{cpt+=1}" ) unless name
|
|
816
|
+
if name
|
|
817
|
+
#puts "name0";p name
|
|
818
|
+
#p name[0,1]==":"
|
|
819
|
+
#puts "name";p name
|
|
820
|
+
modif,affect="","=>"
|
|
821
|
+
if name[-1,1]=="?"
|
|
822
|
+
name=name[0...-1]
|
|
823
|
+
if name[-1,1]=="!"
|
|
824
|
+
name=name[0...-1]
|
|
825
|
+
#p filter.envir.local
|
|
826
|
+
keys2=Envir.to_keys((name[0,1]=="." ? "self"+name : name)+"-USER-" )
|
|
827
|
+
#p keys2
|
|
828
|
+
env=Envir.elt_defined?(filter.envir.local,keys2)
|
|
829
|
+
#p env
|
|
830
|
+
if env=Envir.elt_defined?(filter.envir.local,keys2)
|
|
831
|
+
env[keys2[-1][0..-7]]=env[keys2[-1]]
|
|
832
|
+
env.delete(keys2[-1])
|
|
833
|
+
modif=nil
|
|
834
|
+
b2=nil
|
|
835
|
+
end
|
|
836
|
+
#p env
|
|
837
|
+
#p filter.envir.extract(name)
|
|
838
|
+
else
|
|
839
|
+
modif="?"
|
|
840
|
+
end
|
|
841
|
+
end
|
|
842
|
+
if modif
|
|
843
|
+
if name[-1,1]=="+"
|
|
844
|
+
name=name[0...-1]
|
|
845
|
+
modif+="+"
|
|
846
|
+
end
|
|
847
|
+
if name[-1,1]=="!"
|
|
848
|
+
#p "!!!!";p name
|
|
849
|
+
name=name[0...-1]
|
|
850
|
+
affect="==>"
|
|
851
|
+
end
|
|
852
|
+
name=":"+name unless name[0,1]==":"
|
|
853
|
+
affect="["+modif+"] "+affect unless modif.empty?
|
|
854
|
+
#p b2.strip
|
|
855
|
+
if (arr=@varscan.build_vars(b2.strip)) #the stuff for parsing array
|
|
856
|
+
#puts "arr";p arr
|
|
857
|
+
#p b2
|
|
858
|
+
b2=arr.map{|k,v|
|
|
859
|
+
name+"."+k+affect+Utils.protect_blocktext(v)
|
|
860
|
+
}.join(sep)
|
|
861
|
+
## add the order!
|
|
862
|
+
## ONLY for list not array!
|
|
863
|
+
#b2+=sep+name+"._order_"+affect+Utils.protect_blocktext(arr.map{|k,v| k}.join(","))
|
|
864
|
+
#p b2
|
|
865
|
+
else
|
|
866
|
+
#puts "named";p b2
|
|
867
|
+
b2=name+affect+Utils.protect_blocktext(b2) #see README.250808!
|
|
868
|
+
end
|
|
869
|
+
#p b2
|
|
870
|
+
end
|
|
871
|
+
else
|
|
872
|
+
#puts "b2";p b2
|
|
873
|
+
b2=Utils.protect_blocktext(b2) #see README.250808!
|
|
874
|
+
#p b2
|
|
875
|
+
end
|
|
876
|
+
end
|
|
877
|
+
#puts "b2:#{name}";p b2
|
|
878
|
+
#p b2.split(sep)
|
|
879
|
+
b += b2.split(sep) if b2
|
|
880
|
+
#puts "b";p b
|
|
881
|
+
end
|
|
882
|
+
end while i<blck.length-1
|
|
883
|
+
#puts "make_var_block";p b
|
|
884
|
+
return b
|
|
885
|
+
end
|
|
886
|
+
|
|
887
|
+
def do_var(tex,blck,filter)
|
|
888
|
+
#p blck
|
|
889
|
+
b=make_var_block(blck,filter)
|
|
890
|
+
#puts "do_var:b";p b
|
|
891
|
+
#puts "do_var:filter.local";p filter.envir.local
|
|
892
|
+
eval_VARS(b,filter)
|
|
893
|
+
end
|
|
894
|
+
|
|
895
|
+
def do_set(tex,blck,filter)
|
|
896
|
+
i,*b2=next_block(blck,1)
|
|
897
|
+
#puts "set";p blck[1]
|
|
898
|
+
#p b2
|
|
899
|
+
#p parse_args(blck[1],filter)
|
|
900
|
+
eval_SET(parse_args(blck[1],filter),parse(b2,filter),filter) #,true)
|
|
901
|
+
end
|
|
902
|
+
|
|
903
|
+
def do_hide(tex,blck,filter)
|
|
904
|
+
## nothing to do!!!
|
|
905
|
+
end
|
|
906
|
+
|
|
907
|
+
def do_txt(tex,blck,filter)
|
|
908
|
+
#p blck
|
|
909
|
+
code=blck[1].dup
|
|
910
|
+
#puts "do_txt:code";p code
|
|
911
|
+
##p @curCmd
|
|
912
|
+
|
|
913
|
+
## to name some code block!
|
|
914
|
+
#name=""
|
|
915
|
+
##JUST IN CASE, OLD: if code=~ /^\s*([\w\.\-_:]*)\s*\[(.*)\]\s*$/m #multiline!
|
|
916
|
+
if code=~ /^\s*([\w\.\-_:]+)\s*\[(.*)\]\s*$/m #multiline!
|
|
917
|
+
name,code=$1.strip,$2
|
|
918
|
+
##code="["+code+"]" if name.empty?
|
|
919
|
+
end
|
|
920
|
+
#puts "do_txt:name,code";p [name,code]
|
|
921
|
+
##
|
|
922
|
+
@unprotected_txt=code
|
|
923
|
+
@protected_txt=Utils.protect_txt_block(code)
|
|
924
|
+
#puts "do_txt:@protected_code";p @protected_code
|
|
925
|
+
#puts "do_txt2:code";p name;p code
|
|
926
|
+
res = (@curCmd=="txt" ? code : @protected_txt )
|
|
927
|
+
#puts "res";p res
|
|
928
|
+
if name #unless name.empty?
|
|
929
|
+
#Dyndoc.warn "txt:name",[name,code]
|
|
930
|
+
## the following is only applied when @curCmd==">" or maybe ">>"
|
|
931
|
+
filter.envir[name]=[code]
|
|
932
|
+
outType=nil
|
|
933
|
+
outType=filter.outType+"=" if filter.outType
|
|
934
|
+
tex << filter.convert(name+"!",outType) if @curCmd==">" #useful for templating as in Table.dyn
|
|
935
|
+
else
|
|
936
|
+
#Dyndoc.warn "res",res
|
|
937
|
+
tex << res
|
|
938
|
+
end
|
|
939
|
+
end
|
|
940
|
+
|
|
941
|
+
def do_verb(tex,blck,filter)
|
|
942
|
+
i=0
|
|
943
|
+
i,*b2=next_block(blck,i)
|
|
944
|
+
code=parse(b2,filter)
|
|
945
|
+
Utils.escape!(code,[["{","__OPEN__"],["}","__CLOSE__"]])
|
|
946
|
+
tex << Dyndoc::VERB[@cfg[:format_doc]][:begin] << "\n"
|
|
947
|
+
tex << code.strip << "\n"
|
|
948
|
+
tex << Dyndoc::VERB[@cfg[:format_doc]][:end] << "\n"
|
|
949
|
+
end
|
|
950
|
+
|
|
951
|
+
def do_eval(tex,blck,filter)
|
|
952
|
+
i=0
|
|
953
|
+
#puts "do_eval";p blck
|
|
954
|
+
#puts '#{code}';p @vars["code"]
|
|
955
|
+
i,*b2=next_block(blck,i)
|
|
956
|
+
code=parse(b2,filter)
|
|
957
|
+
#puts "do_eval: code";p code
|
|
958
|
+
Utils.escape_delim!(code)
|
|
959
|
+
#puts "do_eval2: code";p code
|
|
960
|
+
mode=[]
|
|
961
|
+
while code=~/^(test|pre|last|raw)\|.*/
|
|
962
|
+
code = code[($1.length+1)..-1]
|
|
963
|
+
mode << $1.to_sym
|
|
964
|
+
end
|
|
965
|
+
code=Dyndoc::Utils.dyndoc_raw_text(code) if mode.include? :test
|
|
966
|
+
#puts "do_eval:mode";p mode;p code
|
|
967
|
+
#PUT THE FOLLOWING IN THE DOCUMENTATION:
|
|
968
|
+
#puts "WARNING: {#dyn] accept :last and :raw in this order!" unless (mode - [:last,:raw]).empty?
|
|
969
|
+
if mode.include? :pre
|
|
970
|
+
tex2=prepare_output(code)
|
|
971
|
+
#puts "TOTO";p output_pre_model;p @pre_model
|
|
972
|
+
#puts "do_eval:PRE tex2";p tex2
|
|
973
|
+
else
|
|
974
|
+
code="{#document][#main]"+code+"[#}"
|
|
975
|
+
#puts "do_eval:code";p code
|
|
976
|
+
tex2=parse(code,filter)
|
|
977
|
+
end
|
|
978
|
+
Utils.dyndoc_raw_text!(tex2) if mode.include? :last
|
|
979
|
+
#puts "do_eval:tex2";p tex2
|
|
980
|
+
tex2=Utils.dyndoc_raw_text_add(tex2) if mode.include? :raw
|
|
981
|
+
tex << tex2
|
|
982
|
+
if i<blck.length-1 and blck[i+=1]==:to
|
|
983
|
+
i,*b2=next_block(blck,i)
|
|
984
|
+
file=parse(b2,filter)
|
|
985
|
+
unless file.empty?
|
|
986
|
+
File.open(file,"w") do |f|
|
|
987
|
+
f << tex2
|
|
988
|
+
end
|
|
989
|
+
end
|
|
990
|
+
end
|
|
991
|
+
end
|
|
992
|
+
|
|
993
|
+
def do_ifndef(tex,blck,filter)
|
|
994
|
+
i=0
|
|
995
|
+
i,*b2=next_block(blck,i)
|
|
996
|
+
file=parse(b2,filter).strip
|
|
997
|
+
#p file
|
|
998
|
+
if File.exist?(file)
|
|
999
|
+
tex << File.read(file)
|
|
1000
|
+
elsif blck[i+=1]==:<<
|
|
1001
|
+
#p blck[(i+1)..-1]
|
|
1002
|
+
tex2=parse(blck[(i+1)..-1],filter)
|
|
1003
|
+
#p tex2
|
|
1004
|
+
file=file[1..-1] if file[0,1]=="!"
|
|
1005
|
+
File.open(file,"w") do |f|
|
|
1006
|
+
f << tex2
|
|
1007
|
+
end
|
|
1008
|
+
tex << tex2
|
|
1009
|
+
end
|
|
1010
|
+
end
|
|
1011
|
+
|
|
1012
|
+
def do_input(tex,blck,filter)
|
|
1013
|
+
tmpl=parse_args(blck[1],filter)
|
|
1014
|
+
#p tmpl
|
|
1015
|
+
b=make_var_block(blck[2..-1].unshift(:var),filter)
|
|
1016
|
+
#puts "do_input:b";p b
|
|
1017
|
+
tex << eval_INPUT(tmpl,b,filter)
|
|
1018
|
+
end
|
|
1019
|
+
|
|
1020
|
+
def do_require(tex,blck,filter)
|
|
1021
|
+
## just load and parse : read some FUNCs and EXPORT some variables
|
|
1022
|
+
## in the header
|
|
1023
|
+
#Dyndoc.warn "do_require",blck
|
|
1024
|
+
#p parse_args(blck,filter)
|
|
1025
|
+
tmpl=parse_args(blck,filter).strip.split("\n")
|
|
1026
|
+
#Dyndoc.warn "require",tmpl
|
|
1027
|
+
eval_LOAD(tmpl,filter)
|
|
1028
|
+
end
|
|
1029
|
+
|
|
1030
|
+
def do_func(tex,blck,filter)
|
|
1031
|
+
call=parse_args(blck[1],filter)
|
|
1032
|
+
code=blck[2..-1]
|
|
1033
|
+
#p "code func";p code
|
|
1034
|
+
eval_func(call,code)
|
|
1035
|
+
end
|
|
1036
|
+
|
|
1037
|
+
def make_def(blck,filter)
|
|
1038
|
+
call=parse_args(blck[1],filter)
|
|
1039
|
+
code,arg,var,rbEnvir=nil,[],[:var],nil
|
|
1040
|
+
i=1
|
|
1041
|
+
begin
|
|
1042
|
+
case blck[i+=1]
|
|
1043
|
+
when :binding
|
|
1044
|
+
i,*b2=next_block(blck,i)
|
|
1045
|
+
rbEnvir=b2[0][1].strip
|
|
1046
|
+
when :do,:<,:out,:>,:"r<",:"rb<",:"r>",:"R>",:"R<",:"r>>",:rverb,:"rb>>",:rbverb,:"jl>>",:jlverb,:"rb>",:"?",:tag,:"??",:yield,:>>,:"=",:"+",:<<,:"txtl>",:"md>",:"adoc>",:"html>",:"tex>",:"_>"
|
|
1047
|
+
code = blck[i..-1].unshift(:blck)
|
|
1048
|
+
when :","
|
|
1049
|
+
i,*b2=next_block(blck,i)
|
|
1050
|
+
#p blck;p b2
|
|
1051
|
+
#deal with
|
|
1052
|
+
b2=b2[0]
|
|
1053
|
+
if b2[0]==:named
|
|
1054
|
+
=begin
|
|
1055
|
+
if false
|
|
1056
|
+
#Old one!
|
|
1057
|
+
#puts "b2";p b2
|
|
1058
|
+
b2 << [:main,""] unless b2[2]
|
|
1059
|
+
arg << b2[1]
|
|
1060
|
+
var0=b2[2..-1]
|
|
1061
|
+
var0[0][1]= ":"+b2[1]+"[?]=>" + var0[0][1]
|
|
1062
|
+
var << :"," unless var.length==1
|
|
1063
|
+
#p var0
|
|
1064
|
+
var += var0
|
|
1065
|
+
#next: New one
|
|
1066
|
+
else
|
|
1067
|
+
=end
|
|
1068
|
+
#puts "b2";p b2
|
|
1069
|
+
# 151108: Adding "!" at the end of the parameter name disables the default ability. This is completed with
|
|
1070
|
+
arg << (b2[1][-1,1]=="!" ? b2[1][0...-1]+"-USER-" : b2[1])
|
|
1071
|
+
#p arg
|
|
1072
|
+
b2[1]+="?"
|
|
1073
|
+
b2 << [:main,""] unless b2[2]
|
|
1074
|
+
#p b2
|
|
1075
|
+
var << :"," unless var.length==1
|
|
1076
|
+
var << b2
|
|
1077
|
+
#end
|
|
1078
|
+
elsif b2[0]==:main
|
|
1079
|
+
#puts "make_def";p call
|
|
1080
|
+
parse([b2],filter).split(",").map{|v| v.strip}.each{|v|
|
|
1081
|
+
var << :"," unless var.length==1
|
|
1082
|
+
var << [:named, v+"?" , [:main, ""]]
|
|
1083
|
+
arg << v
|
|
1084
|
+
}
|
|
1085
|
+
#p var
|
|
1086
|
+
#var << b2
|
|
1087
|
+
end
|
|
1088
|
+
else #just after the arg is a comment and not dealt
|
|
1089
|
+
i,*b2=next_block(blck,i)
|
|
1090
|
+
end
|
|
1091
|
+
end while i<blck.length-1 and !code
|
|
1092
|
+
#if no block code is provided (possible for method) nothing to do is represented by the following code!
|
|
1093
|
+
code=[:blck, :<] unless code
|
|
1094
|
+
code=[code]
|
|
1095
|
+
#puts "var";p var
|
|
1096
|
+
code.unshift(var) unless var.length==1
|
|
1097
|
+
#puts "code def #{call}";p code
|
|
1098
|
+
call+= ((call.include? "|") ? "," : "|")+arg.join(",") unless arg.empty?
|
|
1099
|
+
return [call,code,rbEnvir]
|
|
1100
|
+
end
|
|
1101
|
+
|
|
1102
|
+
def do_def(tex,blck,filter)
|
|
1103
|
+
call,code,rbEnvir=make_def(blck,filter)
|
|
1104
|
+
#puts "do_def";p call;p code;p rbEnvir
|
|
1105
|
+
eval_func(call,code,rbEnvir)
|
|
1106
|
+
end
|
|
1107
|
+
|
|
1108
|
+
def do_meth(tex,blck,filter)
|
|
1109
|
+
#puts "do_meth";p blck
|
|
1110
|
+
call,code=make_def(blck,filter)
|
|
1111
|
+
#puts "do_meth";p call;p code
|
|
1112
|
+
eval_meth(call,code)
|
|
1113
|
+
end
|
|
1114
|
+
|
|
1115
|
+
def do_new(tex,blck,filter)
|
|
1116
|
+
#first declaration of the object
|
|
1117
|
+
#puts "do_new";p blck
|
|
1118
|
+
var=parse_args(blck[1],filter).strip
|
|
1119
|
+
var = var[1..-1] if var[0,1]==":"
|
|
1120
|
+
i=2
|
|
1121
|
+
if blck[i]==:of
|
|
1122
|
+
i,*b2=next_block(blck,2)
|
|
1123
|
+
klass=parse(b2,filter).split(",").map{|e| e.strip}.join(",")
|
|
1124
|
+
else
|
|
1125
|
+
return
|
|
1126
|
+
end
|
|
1127
|
+
i+=1
|
|
1128
|
+
inR=@rEnvir[0]
|
|
1129
|
+
if blck[i]==:in
|
|
1130
|
+
i,*b2=next_block(blck,i)
|
|
1131
|
+
#p b2
|
|
1132
|
+
#p filter.envir.local["self"]
|
|
1133
|
+
inR=parse(b2,filter).strip
|
|
1134
|
+
#p inR
|
|
1135
|
+
inR,parentR=inR.split("<").map{|e| e.strip}
|
|
1136
|
+
parentR=@rEnvir[0] unless parentR or RServer.exist?(parentR)
|
|
1137
|
+
#p parentR
|
|
1138
|
+
RServer.new_envir(inR,parentR) unless RServer.exist?(inR)
|
|
1139
|
+
i+=1
|
|
1140
|
+
end
|
|
1141
|
+
#puts "do_new:var,klass";p var;p klass
|
|
1142
|
+
=begin
|
|
1143
|
+
b2=blck[4..-1].map{|e|
|
|
1144
|
+
if e.is_a? Array and e[0]==:named
|
|
1145
|
+
e[1]=var+"."+e[1]
|
|
1146
|
+
end
|
|
1147
|
+
e
|
|
1148
|
+
}
|
|
1149
|
+
=end
|
|
1150
|
+
b2=[[:named,var+".Class",[:main,klass]]]
|
|
1151
|
+
b2+=[:",",[:named,var+".Renvir",[:main,inR]]]
|
|
1152
|
+
#puts "do_new:b2";p b2
|
|
1153
|
+
b=make_var_block(b2.unshift(:var),filter)
|
|
1154
|
+
#puts "do_new:var";p b
|
|
1155
|
+
eval_VARS(b,filter)
|
|
1156
|
+
#puts "do_new:eval_VARS";p filter.envir.local
|
|
1157
|
+
# and then call of the initialize method here called new.(Class)
|
|
1158
|
+
=begin
|
|
1159
|
+
call="new"
|
|
1160
|
+
bCall=get_method(call,get_klass(klass))
|
|
1161
|
+
p call
|
|
1162
|
+
=end
|
|
1163
|
+
b2=[] << :call<< [:args,[:main,"new"]] << [:named,"self",[:main,var]]
|
|
1164
|
+
#p blck[4..-1]
|
|
1165
|
+
b2+=blck[i..-1]
|
|
1166
|
+
#puts "do_new:new b2";p b2
|
|
1167
|
+
tex << parse([b2],filter)
|
|
1168
|
+
#tex << eval_CALL("new",b,filter)
|
|
1169
|
+
end
|
|
1170
|
+
|
|
1171
|
+
def do_super(tex,blck,filter)
|
|
1172
|
+
#first declaration of the object
|
|
1173
|
+
var=parse_args(blck[1],filter).strip
|
|
1174
|
+
i=2
|
|
1175
|
+
parent=1
|
|
1176
|
+
if blck[i]==:parent
|
|
1177
|
+
i,*b2=next_block(blck,2)
|
|
1178
|
+
parent=parse(b2,filter).to_i
|
|
1179
|
+
parent=1 if parent==0
|
|
1180
|
+
i+=1
|
|
1181
|
+
end
|
|
1182
|
+
#find next class!
|
|
1183
|
+
super_meth=get_super_method(parent)
|
|
1184
|
+
#p super_meth
|
|
1185
|
+
return "" unless super_meth
|
|
1186
|
+
#build the updtaed block
|
|
1187
|
+
b2=[] << :call<< [:args,[:main,super_meth]] << [:named,"self",[:main,var]]
|
|
1188
|
+
b2+=blck[i..-1]
|
|
1189
|
+
#puts "super b2";p b2
|
|
1190
|
+
tex << parse([b2],filter)
|
|
1191
|
+
#tex << eval_CALL("new",b,filter)
|
|
1192
|
+
end
|
|
1193
|
+
|
|
1194
|
+
def make_call(blck,filter)
|
|
1195
|
+
code,codename,var={"default"=>[:blck]},"default",[]
|
|
1196
|
+
i=-1
|
|
1197
|
+
begin
|
|
1198
|
+
case blck[i+=1]
|
|
1199
|
+
when :blck, :"->"
|
|
1200
|
+
#todo: change codename with the arg of blck
|
|
1201
|
+
i,*b2=next_block(blck,i)
|
|
1202
|
+
codename=parse(b2,filter).strip
|
|
1203
|
+
code[codename]=[:blck]
|
|
1204
|
+
when :do,:<,:out,:>,:"r<",:"R<",:"rb<",:"r>",:"R>",:"rb>",:nl,:"\n",:>>,:"?",:tag,:"??",:"=",:"+",:<<,:"%",:"html>",:"tex>",:"txtl>",:"md>",:"adoc>" #NO :yield because of infinite loops
|
|
1205
|
+
code[codename] << blck[i]
|
|
1206
|
+
i,*b2=next_block(blck,i)
|
|
1207
|
+
code[codename] += b2
|
|
1208
|
+
when :var,:","
|
|
1209
|
+
var << blck[i]
|
|
1210
|
+
i,*b2=next_block(blck,i)
|
|
1211
|
+
#puts "var et ,";p b2
|
|
1212
|
+
var += b2
|
|
1213
|
+
else
|
|
1214
|
+
var << :","
|
|
1215
|
+
res=[:named,blck[i].to_s]
|
|
1216
|
+
i,*b2=next_block(blck,i)
|
|
1217
|
+
res += b2
|
|
1218
|
+
var << res
|
|
1219
|
+
#p var
|
|
1220
|
+
end
|
|
1221
|
+
end while i<blck.length-1
|
|
1222
|
+
code.each_key{|k| code.delete(k) if code[k].length==1 }
|
|
1223
|
+
return [var,code]
|
|
1224
|
+
end
|
|
1225
|
+
|
|
1226
|
+
def do_call(tex,blck,filter)
|
|
1227
|
+
#Dyndoc.warn "do_call",blck
|
|
1228
|
+
call=parse_args(blck[1],filter)
|
|
1229
|
+
#puts "do_call";p call
|
|
1230
|
+
#p args
|
|
1231
|
+
#this corrects a bad behavior of the scanner when the call directive is called directly.
|
|
1232
|
+
if blck[2]==:","
|
|
1233
|
+
var_block= blck[3..-1].unshift(:var)
|
|
1234
|
+
else
|
|
1235
|
+
var_block=blck[2..-1].unshift(:var)
|
|
1236
|
+
end
|
|
1237
|
+
#puts "var_block";p var_block
|
|
1238
|
+
var,code=make_call(var_block,filter)
|
|
1239
|
+
#puts "VAR"
|
|
1240
|
+
#p code
|
|
1241
|
+
#Dyndoc.warn "do_call:var",var
|
|
1242
|
+
|
|
1243
|
+
#p var
|
|
1244
|
+
=begin
|
|
1245
|
+
if @meths.include? call
|
|
1246
|
+
@meth_var=(var[3..-1] ? var[0,1]+var[3..-1] : nil)
|
|
1247
|
+
var=var[0..1]
|
|
1248
|
+
end
|
|
1249
|
+
=end
|
|
1250
|
+
#puts "VAR2";p blck[2..-1].unshift(:var)
|
|
1251
|
+
#puts "var block (AV)";p var
|
|
1252
|
+
|
|
1253
|
+
#19/10/08: this complete the method name if necessary in order to provide args! Now, meth may be used with partial argument completed in the R spirit!
|
|
1254
|
+
call4args,vars4args=call.dup,[]
|
|
1255
|
+
isMeth=CallFilter.isMeth?(call)
|
|
1256
|
+
##puts "#{call} isMeth => #{isMeth}!!!"
|
|
1257
|
+
if isMeth
|
|
1258
|
+
#puts "meth:call=#{call}"
|
|
1259
|
+
obj=parse((var[1][0]==:named ? var[1][2..-1] : [var[1]] ),filter)
|
|
1260
|
+
#puts "obj=#{obj}"
|
|
1261
|
+
if @vars.extract(obj) and @vars.extract(obj).respond_to? "keys"
|
|
1262
|
+
#puts "extract obj";p @vars.extract(obj).keys
|
|
1263
|
+
vars4args=(@vars.extract(obj).keys.select{|e| e.is_a? String} - ["Renvir","ObjectName","Class"]).map{|e| "."+e}
|
|
1264
|
+
#obj=parse([blck[2]],filter)
|
|
1265
|
+
#p @vars[obj+".Class"]
|
|
1266
|
+
get_method(call4args,@vars[obj+".Class"].split(",")) if @vars[obj+".Class"]
|
|
1267
|
+
#=> call4args is modified inside get_method!!!
|
|
1268
|
+
end
|
|
1269
|
+
end
|
|
1270
|
+
|
|
1271
|
+
#puts "call4args=#{call4args}"
|
|
1272
|
+
#p @args[call4args]
|
|
1273
|
+
args=(@args[call4args] ? @args[call4args].dup : nil)
|
|
1274
|
+
args+=vars4args if args
|
|
1275
|
+
#puts "args";p args
|
|
1276
|
+
#TODO: for method, args has to be initialized by finding the class of the object! Pb: how to know that it is a method => make a method in Call???
|
|
1277
|
+
b=(var.length==1 ? [] : make_var_block(var,filter,args))
|
|
1278
|
+
#puts "var block (AP)";p b
|
|
1279
|
+
b,meth_args_b=CallFilter.argsMeth(call,b)
|
|
1280
|
+
#puts "call";p call
|
|
1281
|
+
#p @calls[call]
|
|
1282
|
+
#Dyndoc.warn "var2 block",b
|
|
1283
|
+
#p meth_args_b
|
|
1284
|
+
|
|
1285
|
+
#Dyndoc.warn "call:out",eval_CALL(call,b,filter)
|
|
1286
|
+
tex << eval_CALL(call,b,filter,meth_args_b,code)
|
|
1287
|
+
end
|
|
1288
|
+
|
|
1289
|
+
|
|
1290
|
+
def make_style_meth(meth,klass,blck)
|
|
1291
|
+
b=[:meth, [:args, [:main, "#{name_style(meth)}.Style#{klass}"]]]
|
|
1292
|
+
b += [:","] if ((blck[0].is_a? Array) and ([:main,:named].include? blck[0][0]))
|
|
1293
|
+
b += blck
|
|
1294
|
+
#p b
|
|
1295
|
+
return b
|
|
1296
|
+
end
|
|
1297
|
+
|
|
1298
|
+
def make_style_new(klass,blck)
|
|
1299
|
+
b=[:new, [:args,blck[0]],:of, [:main, "Style#{klass}"]]+blck[1..-1]
|
|
1300
|
+
#puts "make_style_new";p b
|
|
1301
|
+
return b
|
|
1302
|
+
end
|
|
1303
|
+
|
|
1304
|
+
## this allows us to consider independently the calls {#p] and {@p] for user-defined only methods!!!!
|
|
1305
|
+
def name_style(call)
|
|
1306
|
+
call=="new" ? call : "_style_"+call
|
|
1307
|
+
end
|
|
1308
|
+
|
|
1309
|
+
def make_style_call(call,obj,blck)
|
|
1310
|
+
b=[:call, [:args, [:main, name_style(call)]], [:main, obj]]
|
|
1311
|
+
unless blck.empty? #call not of the form {@toto@}
|
|
1312
|
+
b += [:","]
|
|
1313
|
+
#if only a block is given without parameter => no comma! => THIS IS NOT POSSIBLE BECAUSE OF THE CODE ARGUMENT!
|
|
1314
|
+
#puts "make_style_call:blck";p blck
|
|
1315
|
+
b += ((blck[0].is_a? Array) ? blck : [blck])
|
|
1316
|
+
end
|
|
1317
|
+
#puts "make_style_call";p b
|
|
1318
|
+
b
|
|
1319
|
+
end
|
|
1320
|
+
|
|
1321
|
+
def register_style_init
|
|
1322
|
+
@styles={:cmd=>{},:class=>{},:alias=>{}} unless @styles
|
|
1323
|
+
end
|
|
1324
|
+
|
|
1325
|
+
def register_style_meth(klass,meth)
|
|
1326
|
+
register_style_init
|
|
1327
|
+
@styles[:class][klass]=[] unless @styles[:class][klass]
|
|
1328
|
+
@styles[:class][klass] << meth
|
|
1329
|
+
@styles[:class][klass].uniq!
|
|
1330
|
+
end
|
|
1331
|
+
|
|
1332
|
+
def register_style_cmds(cmds,style,force=nil)
|
|
1333
|
+
## register cmds
|
|
1334
|
+
register_style_init
|
|
1335
|
+
cmds.each{|cmd|
|
|
1336
|
+
@styles[:cmd][cmd]=style if force or !@styles[:cmd][cmd]
|
|
1337
|
+
}
|
|
1338
|
+
end
|
|
1339
|
+
|
|
1340
|
+
def do_style(tex,blck,filter)
|
|
1341
|
+
call=parse_args(blck[1],filter)
|
|
1342
|
+
#p call
|
|
1343
|
+
call=call.split(":")
|
|
1344
|
+
#puts "style:call";p call
|
|
1345
|
+
#p @styles
|
|
1346
|
+
#p blck[2..-1]
|
|
1347
|
+
if call[0][0,1]=~/[A-Z]/
|
|
1348
|
+
# style declaration
|
|
1349
|
+
unless call[1]
|
|
1350
|
+
# instance of new object
|
|
1351
|
+
b=make_style_new(call[0],blck[2..-1])
|
|
1352
|
+
do_new(tex,b,filter)
|
|
1353
|
+
style=parse_args(b[1],filter)
|
|
1354
|
+
#p style
|
|
1355
|
+
register_style_cmds(@styles[:class][call[0]],style)
|
|
1356
|
+
else
|
|
1357
|
+
case call[1]
|
|
1358
|
+
when "new"
|
|
1359
|
+
# constructor style method called instance is demanded
|
|
1360
|
+
register_style_init
|
|
1361
|
+
b=make_style_meth("new",call[0],blck[2..-1])
|
|
1362
|
+
#p b
|
|
1363
|
+
do_meth(tex,b,filter)
|
|
1364
|
+
b=make_style_new(call[0],[[:main,call[0][0,1].downcase+call[0][1..-1] ]]) #,:<])
|
|
1365
|
+
#p b
|
|
1366
|
+
#p filter.envir
|
|
1367
|
+
do_new(tex,b,filter)
|
|
1368
|
+
#p filter.envir
|
|
1369
|
+
else
|
|
1370
|
+
#puts "register style meth:#{call[1]}.#{call[0]}"
|
|
1371
|
+
# style cmd method
|
|
1372
|
+
b=make_style_meth(call[1],call[0],blck[2..-1])
|
|
1373
|
+
do_meth(tex,b,filter)
|
|
1374
|
+
# register a new meth for this new Style Class
|
|
1375
|
+
register_style_meth(call[0],call[1])
|
|
1376
|
+
register_style_cmds([call[1]],call[0][0,1].downcase+call[0][1..-1])
|
|
1377
|
+
end
|
|
1378
|
+
end
|
|
1379
|
+
elsif call[0]=="style"
|
|
1380
|
+
if call[1]=="cmds"
|
|
1381
|
+
style=blck[2][1].strip
|
|
1382
|
+
cmds=(blck[4] ? blck[4][1] : nil)
|
|
1383
|
+
cmds=cmds.split(",").map{|cmd| cmd.strip} if cmds
|
|
1384
|
+
if @vars[style+".Class"]
|
|
1385
|
+
klass=@vars[style+".Class"][5..-1]
|
|
1386
|
+
cmds=(cmds ? cmds & @styles[:class][klass] : @styles[:class][klass] )
|
|
1387
|
+
register_style_cmds(cmds,style,true)
|
|
1388
|
+
end
|
|
1389
|
+
elsif call[1]=="alias" and @styles
|
|
1390
|
+
aliases=parse([blck[2]],filter).split(",")
|
|
1391
|
+
value=parse([blck[4]],filter)
|
|
1392
|
+
aliases.each{|a|
|
|
1393
|
+
@styles[:alias][a]=value
|
|
1394
|
+
}
|
|
1395
|
+
end
|
|
1396
|
+
else
|
|
1397
|
+
# cmd style call
|
|
1398
|
+
no_obj=call.length==1
|
|
1399
|
+
obj,cmds=(no_obj ? [nil]+call : call)
|
|
1400
|
+
=begin
|
|
1401
|
+
if obj and !@vars[obj+".Class"]
|
|
1402
|
+
cmds.unshift(obj)
|
|
1403
|
+
obj=nil
|
|
1404
|
+
end
|
|
1405
|
+
=end
|
|
1406
|
+
#recursive alias replacement
|
|
1407
|
+
|
|
1408
|
+
##TODO: it seems that no call in new is possible!
|
|
1409
|
+
#p cmds
|
|
1410
|
+
#register_style_init
|
|
1411
|
+
#p @styles
|
|
1412
|
+
while !(aliases=(cmds.split("|") & @styles[:alias].keys)).empty?
|
|
1413
|
+
aliases.each{|a| cmds.gsub!(a,@styles[:alias][a])}
|
|
1414
|
+
end
|
|
1415
|
+
#puts "cmds";p cmds
|
|
1416
|
+
cmds=cmds.split("|")
|
|
1417
|
+
#puts "cmds2";p cmds
|
|
1418
|
+
#TODO: facility to define alias for style!?!?!
|
|
1419
|
+
b=blck[2..-1]
|
|
1420
|
+
#p cmds
|
|
1421
|
+
cmds.reverse.each{|cmd|
|
|
1422
|
+
obj=@styles[:cmd][cmd] if no_obj
|
|
1423
|
+
#p @filter.envir
|
|
1424
|
+
b=make_style_call(cmd,obj,b)
|
|
1425
|
+
#p b
|
|
1426
|
+
}
|
|
1427
|
+
#puts "style:call";p b
|
|
1428
|
+
do_call(tex,b,filter)
|
|
1429
|
+
end
|
|
1430
|
+
end
|
|
1431
|
+
|
|
1432
|
+
def do_loop(tex,blck,filter)
|
|
1433
|
+
## last executing !!!
|
|
1434
|
+
## To think about environment!!!
|
|
1435
|
+
cond=true
|
|
1436
|
+
#p blck
|
|
1437
|
+
while cond
|
|
1438
|
+
i=-1
|
|
1439
|
+
begin
|
|
1440
|
+
|
|
1441
|
+
case blck[i+=1]
|
|
1442
|
+
when :loop
|
|
1443
|
+
i,*b2=next_block(blck,i)
|
|
1444
|
+
tex << parse(b2,filter)
|
|
1445
|
+
when :break
|
|
1446
|
+
cond=!eval_args(blck[i+=1],filter)
|
|
1447
|
+
i,*b2=next_block(blck,i)
|
|
1448
|
+
tex << parse(b2,filter) if cond
|
|
1449
|
+
end
|
|
1450
|
+
end while cond and i<blck.length-1
|
|
1451
|
+
end
|
|
1452
|
+
end
|
|
1453
|
+
|
|
1454
|
+
def do_document(tex,blck,filter)
|
|
1455
|
+
i=0
|
|
1456
|
+
#puts "document:blck"
|
|
1457
|
+
#p blck
|
|
1458
|
+
begin
|
|
1459
|
+
var,mode="",""
|
|
1460
|
+
to_parse=true
|
|
1461
|
+
#p i;p blck[i+1]
|
|
1462
|
+
case blck[i+=1]
|
|
1463
|
+
########################## Commands
|
|
1464
|
+
when :main,:content
|
|
1465
|
+
var,mode=nil,:view
|
|
1466
|
+
when :require
|
|
1467
|
+
var,mode=nil,:load
|
|
1468
|
+
when :helpers
|
|
1469
|
+
var,mode,to_parse=nil,:helpers,true
|
|
1470
|
+
when :path
|
|
1471
|
+
var,mode=nil,:path
|
|
1472
|
+
when :first
|
|
1473
|
+
#p blck[i+=1]
|
|
1474
|
+
var,mode,to_parse=nil,:first,false
|
|
1475
|
+
when :last
|
|
1476
|
+
var,mode,to_parse=nil,:last,false
|
|
1477
|
+
when :texinputs ## Latex
|
|
1478
|
+
var,mode,to_parse=nil,:texinputs,true
|
|
1479
|
+
when :optclass ## Latex
|
|
1480
|
+
var,mode,to_parse=nil,:optclass,true
|
|
1481
|
+
################################ MODEL VARIABLES
|
|
1482
|
+
when :class ## Latex
|
|
1483
|
+
var,mode="_DOCUMENTCLASS_",""
|
|
1484
|
+
when :preamble
|
|
1485
|
+
var,mode="_PREAMBLE_","+"
|
|
1486
|
+
when :postamble
|
|
1487
|
+
var,mode="_POSTAMBLE_","+"
|
|
1488
|
+
when :style
|
|
1489
|
+
var,mode="_STYLEDOC_","+"
|
|
1490
|
+
when :package
|
|
1491
|
+
var,mode="_USEPACKAGE_","+"
|
|
1492
|
+
when :title
|
|
1493
|
+
var,mode="_TITLE_","+"
|
|
1494
|
+
when :before
|
|
1495
|
+
var,mode="_BEGINDOC_","+"
|
|
1496
|
+
when :after
|
|
1497
|
+
var,mode="_ENDDOC_","+"
|
|
1498
|
+
### specific for HTML! Different from tilt mode!
|
|
1499
|
+
when :js
|
|
1500
|
+
var,mode="_JSDOC_","+"
|
|
1501
|
+
when :css
|
|
1502
|
+
var,mode="_STYLEDOC_","+"
|
|
1503
|
+
when :header
|
|
1504
|
+
var,mode="_HEADER_","+"
|
|
1505
|
+
when :footer
|
|
1506
|
+
var,mode="_FOOTER_","+"
|
|
1507
|
+
when :default
|
|
1508
|
+
var,mode=nil,:default
|
|
1509
|
+
when :cfg
|
|
1510
|
+
var,mode=nil,:cfg
|
|
1511
|
+
end
|
|
1512
|
+
i,*b2=next_block(blck,i)
|
|
1513
|
+
#p b2
|
|
1514
|
+
res=parse(b2,filter) if to_parse
|
|
1515
|
+
#p var
|
|
1516
|
+
#puts "res";p res
|
|
1517
|
+
unless var
|
|
1518
|
+
case mode
|
|
1519
|
+
when :view
|
|
1520
|
+
tex << res
|
|
1521
|
+
when :default, :cfg
|
|
1522
|
+
## nothing to do: used in document.rb
|
|
1523
|
+
when :load
|
|
1524
|
+
#puts "document:require";p res
|
|
1525
|
+
eval_LOAD(res.strip.split("\n"),filter)
|
|
1526
|
+
when :helpers
|
|
1527
|
+
eval_LOAD_HELPERS(res.strip.split("\n"),filter)
|
|
1528
|
+
when :path
|
|
1529
|
+
#puts "document:path";p res
|
|
1530
|
+
unless res.strip.empty?
|
|
1531
|
+
paths=res.strip.split("\n").map{|e| e.strip unless e.strip.empty?}.compact
|
|
1532
|
+
#p paths
|
|
1533
|
+
@tmpl_cfg[:rootDoc]="" unless @tmpl_cfg[:rootDoc]
|
|
1534
|
+
#Dyndoc.warn "rootDoc",@tmpl_cfg[:rootDoc]
|
|
1535
|
+
rootpaths=@tmpl_cfg[:rootDoc].split(Dyndoc::PATH_SEP)
|
|
1536
|
+
#Dyndoc.warn "rootpaths",rootpaths
|
|
1537
|
+
newpaths=[]
|
|
1538
|
+
paths.each{|e|
|
|
1539
|
+
#if File.exist?(e)
|
|
1540
|
+
# newpaths << e
|
|
1541
|
+
#els
|
|
1542
|
+
if e[0,1]=="-" and File.exist?(e[1..-1])
|
|
1543
|
+
rootpaths.delete(e[1..-1])
|
|
1544
|
+
elsif (ind=e.to_i)<0
|
|
1545
|
+
rootpaths.delete_at(-ind-1)
|
|
1546
|
+
else
|
|
1547
|
+
newpaths << e
|
|
1548
|
+
end
|
|
1549
|
+
}
|
|
1550
|
+
rootpaths=newpaths+rootpaths
|
|
1551
|
+
#p rootpaths
|
|
1552
|
+
@tmpl_cfg[:rootDoc]=rootpaths.join(Dyndoc::PATH_SEP)
|
|
1553
|
+
end
|
|
1554
|
+
when :first
|
|
1555
|
+
Dyndoc.dyn_block[:first]=[] unless Dyndoc.dyn_block[:first]
|
|
1556
|
+
Dyndoc.dyn_block[:first]+=b2
|
|
1557
|
+
#Dyndoc "firstblock#{i}",Dyndoc.dyn_block[:first]
|
|
1558
|
+
when :last
|
|
1559
|
+
Dyndoc.dyn_block[:last]=[] unless Dyndoc.dyn_block[:last]
|
|
1560
|
+
Dyndoc.dyn_block[:last]+=b2
|
|
1561
|
+
#Dyndoc "lastblock#{i}",Dyndoc.dyn_block[:last]
|
|
1562
|
+
when :texinputs
|
|
1563
|
+
sep=(RUBY_PLATFORM=~/mingw32/ ? ";" : ":")
|
|
1564
|
+
ENV["TEXINPUTS"]="" unless ENV["TEXINPUTS"]
|
|
1565
|
+
ENV["TEXINPUTS"]+=sep+res.strip.split("\n").join(sep)
|
|
1566
|
+
when :optclass
|
|
1567
|
+
optclass=res.strip.split("\n").join(",").split(",").map { |e| "\""+e.strip+"\"" }.join(",")
|
|
1568
|
+
#puts "optclass";p optclass
|
|
1569
|
+
eval_RbCODE("_optclass_ << ["+optclass+"]",filter)
|
|
1570
|
+
end
|
|
1571
|
+
else
|
|
1572
|
+
res=res.strip if var=="_DOCUMENTCLASS_"
|
|
1573
|
+
eval_GLOBALVAR(var,res,filter,mode)
|
|
1574
|
+
eval_TEX_TITLE(filter) if var=="_TITLE_" and @cfg[:format_doc]==:tex
|
|
1575
|
+
end
|
|
1576
|
+
end while i<blck.length-1
|
|
1577
|
+
end
|
|
1578
|
+
|
|
1579
|
+
=begin
|
|
1580
|
+
## PB! never stop whenever condition is true => ex: if false (not exec), elsif true (exec), elsif false (not exec), else (is then exec)
|
|
1581
|
+
def do_if(tex,blck,filter)
|
|
1582
|
+
i,cond=-1,true
|
|
1583
|
+
#p blck
|
|
1584
|
+
begin
|
|
1585
|
+
filter.outType=":rb"
|
|
1586
|
+
case blck[i+=1]
|
|
1587
|
+
when :if
|
|
1588
|
+
#puts "do_if:blck[i+1]";p blck[i+1]
|
|
1589
|
+
cond=eval_args(blck[i+=1],filter)
|
|
1590
|
+
when :unless
|
|
1591
|
+
cond=!eval_args(blck[i+=1],filter)
|
|
1592
|
+
when :elsif
|
|
1593
|
+
cond= (!cond and eval_args(blck[i+=1],filter))
|
|
1594
|
+
#p blck[i]
|
|
1595
|
+
#p eval_args(blck[i],filter)
|
|
1596
|
+
#p cond
|
|
1597
|
+
when :else
|
|
1598
|
+
cond= !cond
|
|
1599
|
+
end
|
|
1600
|
+
filter.outType=nil
|
|
1601
|
+
i,*b2=next_block(blck,i)
|
|
1602
|
+
tex << parse(b2,filter) if cond
|
|
1603
|
+
end while i<blck.length-1
|
|
1604
|
+
#puts "tex";p tex
|
|
1605
|
+
end
|
|
1606
|
+
=end
|
|
1607
|
+
|
|
1608
|
+
def do_if(tex,blck,filter)
|
|
1609
|
+
i,cond=-1,nil
|
|
1610
|
+
#p blck
|
|
1611
|
+
begin
|
|
1612
|
+
filter.outType=":rb"
|
|
1613
|
+
case blck[i+=1]
|
|
1614
|
+
when :if, :elsif
|
|
1615
|
+
#puts "do_if:blck[i+1]";p blck[i+1]
|
|
1616
|
+
cond=eval_args(blck[i+=1],filter)
|
|
1617
|
+
when :unless
|
|
1618
|
+
cond=!eval_args(blck[i+=1],filter)
|
|
1619
|
+
when :else
|
|
1620
|
+
cond= true
|
|
1621
|
+
end
|
|
1622
|
+
filter.outType=nil
|
|
1623
|
+
i,*b2=next_block(blck,i)
|
|
1624
|
+
tex << parse(b2,filter) if cond
|
|
1625
|
+
end while !cond and i<blck.length-1
|
|
1626
|
+
#puts "tex";p tex
|
|
1627
|
+
end
|
|
1628
|
+
|
|
1629
|
+
|
|
1630
|
+
#BIENTOT OBSOLETE!
|
|
1631
|
+
def do_for(tex,blck,filter)
|
|
1632
|
+
filter.outType=":rb"
|
|
1633
|
+
code=""
|
|
1634
|
+
# @forFilter is here to make available the dyn variables!
|
|
1635
|
+
@cptRbCode,@rbCode,@texRbCode,@forFilter=-1,{},{},filter unless @rbCode
|
|
1636
|
+
code << "if res; for " << parse_args(blck[1],filter).strip << " do\n"
|
|
1637
|
+
cpt=(@cptRbCode+=1) #local value to delete later!
|
|
1638
|
+
#p cpt
|
|
1639
|
+
@rbCode[cpt]=[blck[2..-1].unshift(:blck)]
|
|
1640
|
+
@texRbCode[cpt]=tex
|
|
1641
|
+
code << "@texRbCode[#{cpt}] << parse(@rbCode[#{cpt}],@forFilter)\n"
|
|
1642
|
+
code << "end;end\n"
|
|
1643
|
+
#p code
|
|
1644
|
+
#puts "titi";p filter.envir.local
|
|
1645
|
+
#p @rbCode[cpt]
|
|
1646
|
+
#Dyndoc.warn :for_code,[code.encoding,code,__ENCODING__]
|
|
1647
|
+
@rbEnvir[0].eval(code)
|
|
1648
|
+
@rbCode.delete(cpt)
|
|
1649
|
+
#p @rbCode
|
|
1650
|
+
@texRbCode.delete(cpt)
|
|
1651
|
+
filter.outType=nil
|
|
1652
|
+
end
|
|
1653
|
+
|
|
1654
|
+
|
|
1655
|
+
|
|
1656
|
+
def do_case(tex,blck,filter)
|
|
1657
|
+
choices=parse_args(blck[1],filter).strip
|
|
1658
|
+
#puts "choices";p choices
|
|
1659
|
+
#p blck
|
|
1660
|
+
var="__elt_case__"
|
|
1661
|
+
tmp=choices.scan(/(^\w*):(.*)/)[0]
|
|
1662
|
+
var,choices=tmp[0].strip,tmp[1].strip if tmp
|
|
1663
|
+
choices=choices.split(",").map{|e| e.strip}
|
|
1664
|
+
choices.each{|choice|
|
|
1665
|
+
i=1
|
|
1666
|
+
todo,cond,all=true,false,false
|
|
1667
|
+
begin
|
|
1668
|
+
case blck[i+=1]
|
|
1669
|
+
when :when
|
|
1670
|
+
#puts "when";p blck[i]
|
|
1671
|
+
c=parse_args(blck[i+=1],filter).strip.split(",").map{|e| e.strip}
|
|
1672
|
+
#p "#{choice} in #{c.join(",")}"
|
|
1673
|
+
cond=(c.include? choice)
|
|
1674
|
+
all |= cond
|
|
1675
|
+
when :else
|
|
1676
|
+
cond=!all
|
|
1677
|
+
end
|
|
1678
|
+
i,*b2=next_block(blck,i)
|
|
1679
|
+
@vars[var]=choice
|
|
1680
|
+
tex << parse(b2,filter) if cond
|
|
1681
|
+
#if cond
|
|
1682
|
+
# puts "tex in case";p tex
|
|
1683
|
+
#end
|
|
1684
|
+
end while todo and i<blck.length-1
|
|
1685
|
+
}
|
|
1686
|
+
#puts "tex in case";p tex
|
|
1687
|
+
end
|
|
1688
|
+
|
|
1689
|
+
def do_r(tex,blck,filter)
|
|
1690
|
+
newblck=blck[0]
|
|
1691
|
+
#puts "do_r";p blck
|
|
1692
|
+
filter.outType=":r"
|
|
1693
|
+
i=0
|
|
1694
|
+
i,*b2=next_block(blck,i)
|
|
1695
|
+
code=parse(b2,filter)
|
|
1696
|
+
inR=nil
|
|
1697
|
+
if blck[i+=1]==:in
|
|
1698
|
+
i,*b2=next_block(blck,i)
|
|
1699
|
+
inR=parse(b2,filter).strip
|
|
1700
|
+
RServer.new_envir(inR,@rEnvir[0]) unless RServer.exist?(inR)
|
|
1701
|
+
end
|
|
1702
|
+
@rEnvir.unshift(inR) if inR
|
|
1703
|
+
#puts "do_r:code";p code;p eval_RCODE(code,filter,true,true) if newblck==:"r>"
|
|
1704
|
+
if newblck==:"r>"
|
|
1705
|
+
tex2=eval_RCODE(code,filter,:pretty=> true,:capture=> true)
|
|
1706
|
+
## Dyndoc.warn "rrrrrrrrrrrrrrr: tex2", tex2
|
|
1707
|
+
tex << tex2
|
|
1708
|
+
else
|
|
1709
|
+
# pretty is put to false because prettyNum does not accept empty output or something like that!
|
|
1710
|
+
eval_RCODE(code,filter,:pretty=> false)
|
|
1711
|
+
end
|
|
1712
|
+
@rEnvir.shift if inR
|
|
1713
|
+
filter.outType=nil
|
|
1714
|
+
end
|
|
1715
|
+
|
|
1716
|
+
def do_renv(tex,blck,filter)
|
|
1717
|
+
inR=parse_args(blck,filter).strip
|
|
1718
|
+
#p inR
|
|
1719
|
+
mode=:ls
|
|
1720
|
+
case inR[-1,1]
|
|
1721
|
+
when "+"
|
|
1722
|
+
mode=:attach
|
|
1723
|
+
inR=inR[0...-1]
|
|
1724
|
+
when "-"
|
|
1725
|
+
mode=:detach
|
|
1726
|
+
inR=inR[0...-1]
|
|
1727
|
+
when "?"
|
|
1728
|
+
mode=:show
|
|
1729
|
+
inR=inR[0...-1]
|
|
1730
|
+
end
|
|
1731
|
+
unless [:detach,:ls].include? mode
|
|
1732
|
+
#puts "#{inR} EXIST?";p RServer.exist?(inR);"print(ls(.GlobalEnv$.env4dyn))".to_R
|
|
1733
|
+
RServer.new_envir(inR,@rEnvir[0]) unless RServer.exist?(inR)
|
|
1734
|
+
end
|
|
1735
|
+
case mode
|
|
1736
|
+
when :ls
|
|
1737
|
+
unless inR.empty?
|
|
1738
|
+
begin
|
|
1739
|
+
inRTmp=eval(inR)
|
|
1740
|
+
inR=(inRTmp.is_a? Regexp) ? inRTmp : /#{inR}/
|
|
1741
|
+
rescue
|
|
1742
|
+
inR=/#{inR}/
|
|
1743
|
+
end
|
|
1744
|
+
end
|
|
1745
|
+
tex << ((inR.is_a? Regexp) ? @rEnvir.select{|rEnv| rEnv=~ inR} : @rEnvir ).join(",")
|
|
1746
|
+
when :attach
|
|
1747
|
+
@rEnvir.unshift(inR) unless inR.empty?
|
|
1748
|
+
when :detach
|
|
1749
|
+
if inR.empty?
|
|
1750
|
+
@rEnvir.shift
|
|
1751
|
+
else
|
|
1752
|
+
if w=@rEnvir.index(inR)
|
|
1753
|
+
@rEnvir.delete_at(w)
|
|
1754
|
+
end
|
|
1755
|
+
end
|
|
1756
|
+
when :show
|
|
1757
|
+
tex << (inR.empty? ? @rEnvir[0] : (@rEnvir[0]==inR).to_s)
|
|
1758
|
+
end
|
|
1759
|
+
end
|
|
1760
|
+
|
|
1761
|
+
def do_rverb(tex,blck,filter)
|
|
1762
|
+
# require 'pry'
|
|
1763
|
+
# binding.pry
|
|
1764
|
+
newblck=blck[0]
|
|
1765
|
+
filter.outType=":r"
|
|
1766
|
+
i=0
|
|
1767
|
+
i,*b2=next_block(blck,i)
|
|
1768
|
+
#Dyndoc.warn "rverb:b2",b2
|
|
1769
|
+
code=parse(b2,filter)
|
|
1770
|
+
i+=1
|
|
1771
|
+
inR=nil
|
|
1772
|
+
if blck[i]==:in
|
|
1773
|
+
i,*b2=next_block(blck,i)
|
|
1774
|
+
inR=parse(b2,filter).strip
|
|
1775
|
+
RServer.new_envir(inR,@rEnvir[0]) unless RServer.exist?(inR)
|
|
1776
|
+
i+=1
|
|
1777
|
+
end
|
|
1778
|
+
mode=@cfg[:mode_doc]
|
|
1779
|
+
#p [mode,@fmt,@fmtOutput]
|
|
1780
|
+
mode=@fmtOutput.to_sym if @fmtOutput and ["html","tex","txtl","raw"].include? @fmtOutput
|
|
1781
|
+
mode=(@fmt and !@fmt.empty? ? @fmt.to_sym : :default) unless mode
|
|
1782
|
+
if blck[i]==:mode
|
|
1783
|
+
i,*b2=next_block(blck,i)
|
|
1784
|
+
mode=parse(b2,filter).strip.to_sym
|
|
1785
|
+
end
|
|
1786
|
+
mode=:default if newblck==:rout #or newblck==:"r>>"
|
|
1787
|
+
@rEnvir.unshift(inR) if inR
|
|
1788
|
+
process_r(code)
|
|
1789
|
+
#Dyndoc.warn "rverb:rcode",code,@@interactive
|
|
1790
|
+
res=RServer.echo_verb(code,@@interactive ? :raw : mode,@rEnvir[0], prompt: (@@interactive ? "R" : ""))
|
|
1791
|
+
require "dyndoc/common/uv" if @@interactive
|
|
1792
|
+
|
|
1793
|
+
warn_level = $VERBOSE;$VERBOSE = nil
|
|
1794
|
+
tex << (@@interactive ? Uv.parse(res.force_encoding("utf-8"), "xhtml", File.join(Uv.syntax_path,"r.syntax") , false, "solarized",false) : res.force_encoding("utf-8") )
|
|
1795
|
+
$VERBOSE = warn_level
|
|
1796
|
+
#Dyndoc.warn "rverb:result",res
|
|
1797
|
+
@rEnvir.shift if inR
|
|
1798
|
+
filter.outType=nil
|
|
1799
|
+
end
|
|
1800
|
+
|
|
1801
|
+
def do_rbverb(tex,blck,filter)
|
|
1802
|
+
# require 'pry'
|
|
1803
|
+
# binding.pry
|
|
1804
|
+
newblck=blck[0]
|
|
1805
|
+
filter.outType=":rb"
|
|
1806
|
+
i=0
|
|
1807
|
+
i,*b2=next_block(blck,i)
|
|
1808
|
+
#puts "rverb:b2";p b2
|
|
1809
|
+
code=parse(b2,filter)
|
|
1810
|
+
i+=1
|
|
1811
|
+
|
|
1812
|
+
mode=@cfg[:mode_doc]
|
|
1813
|
+
#p [mode,@fmt,@fmtOutput]
|
|
1814
|
+
mode=@fmtOutput.to_sym if @fmtOutput and ["html","tex","txtl","raw"].include? @fmtOutput
|
|
1815
|
+
mode=(@fmt and !@fmt.empty? ? @fmt.to_sym : :default) unless mode
|
|
1816
|
+
if blck[i]==:mode
|
|
1817
|
+
i,*b2=next_block(blck,i)
|
|
1818
|
+
mode=parse(b2,filter).strip.to_sym
|
|
1819
|
+
end
|
|
1820
|
+
|
|
1821
|
+
process_rb(code)
|
|
1822
|
+
## Dyndoc.warn "rverb:rcode";p code
|
|
1823
|
+
res=RbServer.echo_verb(code,@@interactive ? :raw : mode,@rbEnvir[0])
|
|
1824
|
+
## Dyndoc.warn "rbverb:res",res
|
|
1825
|
+
require "dyndoc/common/uv" if @@interactive
|
|
1826
|
+
warn_level = $VERBOSE;$VERBOSE = nil
|
|
1827
|
+
tex << (@@interactive ? Uv.parse(res, "xhtml", File.join(Uv.syntax_path,"ruby.syntax") , false, "solarized",false) : res )
|
|
1828
|
+
$VERBOSE = warn_level
|
|
1829
|
+
#puts "rverb:result";p res
|
|
1830
|
+
|
|
1831
|
+
filter.outType=nil
|
|
1832
|
+
end
|
|
1833
|
+
|
|
1834
|
+
def do_jlverb(tex,blck,filter)
|
|
1835
|
+
# require 'pry'
|
|
1836
|
+
# binding.pry
|
|
1837
|
+
newblck=blck[0]
|
|
1838
|
+
filter.outType=":jl"
|
|
1839
|
+
i=0
|
|
1840
|
+
i,*b2=next_block(blck,i)
|
|
1841
|
+
#puts "rverb:b2";p b2
|
|
1842
|
+
code=parse(b2,filter)
|
|
1843
|
+
i+=1
|
|
1844
|
+
|
|
1845
|
+
mode=@cfg[:mode_doc]
|
|
1846
|
+
#p [mode,@fmt,@fmtOutput]
|
|
1847
|
+
mode=@fmtOutput.to_sym if @fmtOutput and ["html","tex","txtl","raw"].include? @fmtOutput
|
|
1848
|
+
mode=(@fmt and !@fmt.empty? ? @fmt.to_sym : :default) unless mode
|
|
1849
|
+
if blck[i]==:mode
|
|
1850
|
+
i,*b2=next_block(blck,i)
|
|
1851
|
+
mode=parse(b2,filter).strip.to_sym
|
|
1852
|
+
end
|
|
1853
|
+
|
|
1854
|
+
process_jl(code)
|
|
1855
|
+
#puts "rverb:rcode";p code
|
|
1856
|
+
res=JLServer.echo_verb(code,@@interactive ? :raw : mode)
|
|
1857
|
+
require "dyndoc/common/uv" if @@interactive
|
|
1858
|
+
warn_level = $VERBOSE;$VERBOSE = nil
|
|
1859
|
+
tex << (@@interactive ? Uv.parse(res, "xhtml", File.join(Uv.syntax_path,"julia.syntax") , false, "solarized",false) : res )
|
|
1860
|
+
$VERBOSE = warn_level
|
|
1861
|
+
#puts "rverb:result";p res
|
|
1862
|
+
|
|
1863
|
+
filter.outType=nil
|
|
1864
|
+
end
|
|
1865
|
+
|
|
1866
|
+
def dynBlock_in_doLangBlock?(blck)
|
|
1867
|
+
blck.map{|b| b.respond_to? "[]" and [:>,:<,:<<].include? b[0] }.any?
|
|
1868
|
+
end
|
|
1869
|
+
|
|
1870
|
+
attr_accessor :doLangBlock
|
|
1871
|
+
|
|
1872
|
+
def make_do_lang_blck(blck,id,lang=:rb)
|
|
1873
|
+
#p blck
|
|
1874
|
+
cptCode=-1
|
|
1875
|
+
## Dyndoc.warn "make_do_lang_blck",blck
|
|
1876
|
+
blck2=blck.map{|b|
|
|
1877
|
+
## Dyndoc.warn "b",b
|
|
1878
|
+
if b.respond_to? "[]" and [:>,:<,:<<].include? b[0]
|
|
1879
|
+
cptCode+=1
|
|
1880
|
+
@doLangBlock[id][:code][cptCode]=Utils.escape_delim!(b[1])
|
|
1881
|
+
codeLangBlock = "Dyndoc.tmpl_mngr.eval"+ lang.to_s.capitalize+"Block(#{id.to_s},#{cptCode.to_s},:#{b[0].to_s},:#{lang})"
|
|
1882
|
+
|
|
1883
|
+
@doLangBlockEnvs=[0] unless @doLangBlockEnvs #never empty?
|
|
1884
|
+
@doLangBlockEnvs << (doLangBlockEnv=@doLangBlockEnvs.max + 1)
|
|
1885
|
+
@doLangBlock[id][:env] << doLangBlockEnv
|
|
1886
|
+
|
|
1887
|
+
## NEW: Special treatment for R code because environment is different from GlobalEnv
|
|
1888
|
+
case lang
|
|
1889
|
+
when :R
|
|
1890
|
+
# first, get the environment
|
|
1891
|
+
codeLangBlock="{.GlobalEnv$.env4dyn$rbBlock#{doLangBlockEnv.to_s} <- environment();.rb(\""+codeLangBlock+"\");invisible()}"
|
|
1892
|
+
# use it to evaluate the dyn block with R stuff! (renv)
|
|
1893
|
+
@doLangBlock[id][:code][cptCode]= "[#<]{#renv]rbBlock#{doLangBlockEnv.to_s}+[#}[#>]"+@doLangBlock[id][:code][cptCode]+"[#<]{#renv]rbBlock#{doLangBlockEnv.to_s}-[#}"
|
|
1894
|
+
when :jl
|
|
1895
|
+
# Nothing since no binding or environment in Julia
|
|
1896
|
+
# Toplevel used
|
|
1897
|
+
codeLangBlock="begin Ruby.run(\""+codeLangBlock+"\") end"
|
|
1898
|
+
@doLangBlock[id][:code][cptCode]= "[#>]"+@doLangBlock[id][:code][cptCode]
|
|
1899
|
+
when :rb
|
|
1900
|
+
##DEBUG: codeRbBlock="begin $curDyn.tmpl.rbenvir_go_to(:rbBlock#{rbBlockEnv.to_s},binding);p \"rbBlock#{doBlockEnv.to_s}\";p \"rbCode=#{codeRbBlock}\";$result4BlockCode="+codeRbBlock+";$curDyn.tmpl.rbenvir_back_from(:rbBlock#{doLangBlockEnv.to_s});$result4BlockCode; end"
|
|
1901
|
+
codeLangBlock="begin Dyndoc.tmpl_mngr.rbenvir_go_to(:rbBlock#{doLangBlockEnv.to_s},binding);$result4BlockCode="+codeLangBlock+";Dyndoc.tmpl_mngr.rbenvir_back_from(:rbBlock#{doLangBlockEnv.to_s});$result4BlockCode; end"
|
|
1902
|
+
end
|
|
1903
|
+
case lang
|
|
1904
|
+
when :R
|
|
1905
|
+
process_r(@doLangBlock[id][:code][cptCode])
|
|
1906
|
+
when :jl
|
|
1907
|
+
# TODO
|
|
1908
|
+
process_jl(@doLangBlock[id][:code][cptCode])
|
|
1909
|
+
when :rb
|
|
1910
|
+
process_rb(@doLangBlock[id][:code][cptCode])
|
|
1911
|
+
end
|
|
1912
|
+
[:main,codeLangBlock]
|
|
1913
|
+
else
|
|
1914
|
+
b
|
|
1915
|
+
end
|
|
1916
|
+
}
|
|
1917
|
+
## Dyndoc.warn "cptRb",cptRb
|
|
1918
|
+
## Dyndoc.warn "blck2",blck2
|
|
1919
|
+
blck2
|
|
1920
|
+
end
|
|
1921
|
+
|
|
1922
|
+
def evalRbBlock(id,cpt,tag,lang=:rb)
|
|
1923
|
+
## Dyndoc.warn "@doLangBlock[#{id.to_s}][:code][#{cpt.to_s}]",@doLangBlock[id][:code][cpt]#,@doLangBlock[id][:filter]
|
|
1924
|
+
## this deals with the problem of newBlcks!
|
|
1925
|
+
##puts "block_normal";p blckMode_normal?
|
|
1926
|
+
code=(blckMode_normal? ? @doLangBlock[id][:code][cpt] : "{#blckAnyTag]"+@doLangBlock[id][:code][cpt]+"[#blckAnyTag}" )
|
|
1927
|
+
#puts "code";p code
|
|
1928
|
+
@doLangBlock[id][:out]=parse(code,@doLangBlock[id][:filter])
|
|
1929
|
+
##Dyndoc.warn "evalRbBlock:doLangBlock",[id,code,@doLangBlock[id][:out]] if tag == :>
|
|
1930
|
+
|
|
1931
|
+
#########################################
|
|
1932
|
+
## THIS IS FOR OLD
|
|
1933
|
+
##@doLangBlock[id][:tex] << @doLangBlock[id][:out] if tag == :>
|
|
1934
|
+
## THIS IS NEW
|
|
1935
|
+
print @doLangBlock[id][:out] if tag == :>
|
|
1936
|
+
##
|
|
1937
|
+
#Dyndoc.warn "EVALRBBLOCK: @doLangBlock[id][:out]",@doLangBlock[id][:out] if tag == :>
|
|
1938
|
+
#######################################
|
|
1939
|
+
|
|
1940
|
+
if tag == :<<
|
|
1941
|
+
return ( lang==:R ? RServer.output(@doLangBlock[id][:out],@rEnvir[0],true) : eval(@doLangBlock[id][:out]) )
|
|
1942
|
+
else
|
|
1943
|
+
return @doLangBlock[id][:out]
|
|
1944
|
+
end
|
|
1945
|
+
end
|
|
1946
|
+
|
|
1947
|
+
=begin DO NOT REMOVE: OLD STUFF (just in case the experimental one fails!!!)
|
|
1948
|
+
def do_rb(tex,blck,filter)
|
|
1949
|
+
##a new rbEnvir is added inside this function! For a while, every ruby code is to evaluate inside this envir till the end of function.
|
|
1950
|
+
## rbBlock stuff
|
|
1951
|
+
#p blck
|
|
1952
|
+
#puts "do_rb binding"; p binding; p local_variables
|
|
1953
|
+
dynBlock=dynBlock_in_doLangBlock?(blck)
|
|
1954
|
+
if dynBlock
|
|
1955
|
+
##OLD:@filterRbBlock=filter
|
|
1956
|
+
@doLangBlock=[] unless @doLangBlock
|
|
1957
|
+
@doLangBlock << {:tex=>'',:code=>[],:out=>'',:filter=>filter,:env=>[]} #@filterRbBlock}
|
|
1958
|
+
rbBlockId=@doLangBlock.length-1
|
|
1959
|
+
#OLD:eval("rbBlock={:tex=>'',:code=>[],:out=>'',:filter=>@filterRbBlock}",@rbEnvir[0])
|
|
1960
|
+
end
|
|
1961
|
+
## this is ruby code!
|
|
1962
|
+
filter.outType=":rb"
|
|
1963
|
+
#puts "do_rb";p filter.envir.local
|
|
1964
|
+
blck=make_do_lang_blck(blck,rbBlockId)
|
|
1965
|
+
#puts "do_rb";p blck
|
|
1966
|
+
code = parse_args(blck,filter)
|
|
1967
|
+
#puts "rb code="+code
|
|
1968
|
+
process_rb(code) if Utils.raw_code_to_process
|
|
1969
|
+
#puts "rb CODE="+code
|
|
1970
|
+
res=eval_RbCODE(code,filter)
|
|
1971
|
+
tex2=(dynBlock ? @doLangBlock[rbBlockId][:tex] : (blck[0]==:"rb>" ? res : ""))
|
|
1972
|
+
#OLD:tex2=(dynBlock ? eval("rbBlock[:tex]",@rbEnvir[0]) : "")
|
|
1973
|
+
#puts "tex2";p tex2
|
|
1974
|
+
tex << tex2
|
|
1975
|
+
#tex << res if blck[0]==:"rb>" and !dynBlock #and tex2.empty? ##=> done above!
|
|
1976
|
+
## revert all the stuff
|
|
1977
|
+
if dynBlock
|
|
1978
|
+
@doLangBlockEnvs -= @doLangBlock[rbBlockId][:env] #first remove useless envRs
|
|
1979
|
+
@doLangBlock.pop
|
|
1980
|
+
end
|
|
1981
|
+
filter.outType=nil
|
|
1982
|
+
#puts "SORTIE RB!"
|
|
1983
|
+
#p dynBlock; p blck;p tex2
|
|
1984
|
+
end
|
|
1985
|
+
=end
|
|
1986
|
+
|
|
1987
|
+
#=begin NEW STUFF!!!
|
|
1988
|
+
def do_rb(tex,blck,filter)
|
|
1989
|
+
require 'stringio'
|
|
1990
|
+
@rbIO=[] unless @rbIO
|
|
1991
|
+
@rbIO << (blck[0]==:"rb>" ? StringIO.new : STDOUT)
|
|
1992
|
+
$stdout=@rbIO[-1]
|
|
1993
|
+
|
|
1994
|
+
## Dyndoc.warn "blck",blck
|
|
1995
|
+
## Dyndoc.warn "do_rb binding",binding,local_variables
|
|
1996
|
+
dynBlock=dynBlock_in_doLangBlock?(blck)
|
|
1997
|
+
if dynBlock
|
|
1998
|
+
@doLangBlock=[] unless @doLangBlock
|
|
1999
|
+
@doLangBlock << {:tex=>'',:code=>[],:out=>'',:filter=>filter,:env=>[]} #@filterRbBlock}
|
|
2000
|
+
rbBlockId=@doLangBlock.length-1
|
|
2001
|
+
end
|
|
2002
|
+
## this is ruby code!
|
|
2003
|
+
filter.outType=":rb"
|
|
2004
|
+
## Dyndoc.warn "do_rb",filter.envir.local
|
|
2005
|
+
blck=make_do_lang_blck(blck,rbBlockId)
|
|
2006
|
+
## Dyndoc.warn "do_rb",blck
|
|
2007
|
+
code = parse_args(blck,filter)
|
|
2008
|
+
## Dyndoc.warn "rb code="+code
|
|
2009
|
+
process_rb(code) if Utils.raw_code_to_process
|
|
2010
|
+
## Dyndoc.warn "rb CODE="+code
|
|
2011
|
+
as_default_tmpl_mngr! if blck[0]==:"rb>"
|
|
2012
|
+
res=eval_RbCODE(code,filter)
|
|
2013
|
+
|
|
2014
|
+
if blck[0]==:"rb>"
|
|
2015
|
+
tex2=@rbIO.pop.string
|
|
2016
|
+
#Dyndoc.warn "res",res
|
|
2017
|
+
#Dyndoc.warn "RbRbRbRbRbRbRb:", (tex2.empty? ? res : tex2)
|
|
2018
|
+
tex << (tex2.empty? ? res : tex2)
|
|
2019
|
+
else
|
|
2020
|
+
@rbIO.pop
|
|
2021
|
+
end
|
|
2022
|
+
|
|
2023
|
+
## revert all the stuff
|
|
2024
|
+
if dynBlock
|
|
2025
|
+
@doLangBlockEnvs -= @doLangBlock[rbBlockId][:env] #first remove useless envRs
|
|
2026
|
+
@doLangBlock.pop
|
|
2027
|
+
end
|
|
2028
|
+
$stdout=@rbIO.empty? ? STDOUT : @rbIO[-1]
|
|
2029
|
+
|
|
2030
|
+
filter.outType=nil
|
|
2031
|
+
## Dyndoc.warn "SORTIE RB!",dynBlock,blck,tex2
|
|
2032
|
+
end
|
|
2033
|
+
#=end
|
|
2034
|
+
|
|
2035
|
+
|
|
2036
|
+
def evalRBlock(id,cpt,tag,lang=:R)
|
|
2037
|
+
## this deals with the problem of newBlcks!
|
|
2038
|
+
## Dyndoc.warn "block_normal",blckMode_normal?
|
|
2039
|
+
code=(blckMode_normal? ? @doLangBlock[id][:code][cpt] : "{#blckAnyTag]"+@doLangBlock[id][:code][cpt]+"[#blckAnyTag}" )
|
|
2040
|
+
## Dyndoc.warn "codeR",code
|
|
2041
|
+
@doLangBlock[id][:out]=parse(code,@doLangBlock[id][:filter])
|
|
2042
|
+
## Dyndoc.warn "code2R", @doLangBlock[id][:out]
|
|
2043
|
+
if tag == :>
|
|
2044
|
+
outcode=@doLangBlock[id][:out].gsub(/\\/,'\\\\\\\\') #to be compatible with R
|
|
2045
|
+
outcode=outcode.gsub(/\'/,"\\\\\'")
|
|
2046
|
+
#Dyndoc.warn
|
|
2047
|
+
outcode='cat(\''+outcode+'\')'
|
|
2048
|
+
#Dyndoc.warn "outcode",outcode
|
|
2049
|
+
outcode.to_R # CLEVER: directly redirect in R output that is then captured
|
|
2050
|
+
end
|
|
2051
|
+
if tag == :<<
|
|
2052
|
+
return ( lang==:R ? RServer.output(@doLangBlock[id][:out],@rEnvir[0],true) : eval(@doLangBlock[id][:out]) )
|
|
2053
|
+
else
|
|
2054
|
+
return @doLangBlock[id][:out]
|
|
2055
|
+
end
|
|
2056
|
+
end
|
|
2057
|
+
|
|
2058
|
+
|
|
2059
|
+
def do_R(tex,blck,filter)
|
|
2060
|
+
## rBlock stuff
|
|
2061
|
+
# Dyndoc.warn "do_R",blck
|
|
2062
|
+
dynBlock=dynBlock_in_doLangBlock?(blck)
|
|
2063
|
+
if dynBlock
|
|
2064
|
+
@doLangBlock=[] unless @doLangBlock
|
|
2065
|
+
@doLangBlock << {:tex=>'',:code=>[],:out=>'',:filter=>filter,:env=>[]}
|
|
2066
|
+
rBlockId=@doLangBlock.length-1
|
|
2067
|
+
end
|
|
2068
|
+
## this is R code!
|
|
2069
|
+
filter.outType=":r"
|
|
2070
|
+
## Dyndoc.warn "do_R",filter.envir.local
|
|
2071
|
+
blck=make_do_lang_blck(blck,rBlockId,:R) #true at the end is for R!
|
|
2072
|
+
## Dyndoc.warn "do_R",blck
|
|
2073
|
+
code = parse_args(blck,filter)
|
|
2074
|
+
## Dyndoc.warn "R code="+code
|
|
2075
|
+
process_r(code)
|
|
2076
|
+
## Dyndoc.warn "R CODE="+code
|
|
2077
|
+
|
|
2078
|
+
if blck[0]==:"R>"
|
|
2079
|
+
## Dyndoc.warn "R>",code
|
|
2080
|
+
as_default_tmpl_mngr!
|
|
2081
|
+
tex2=eval_RCODE(code,filter,:blockR => true)
|
|
2082
|
+
## Dyndoc.warn "RRRRRRRRRRRRRRRR: tex2",tex2
|
|
2083
|
+
tex << tex2
|
|
2084
|
+
else
|
|
2085
|
+
# pretty is put to false because prettyNum does not accept empty output or something like that!
|
|
2086
|
+
eval_RCODE(code,filter,:pretty=> false)
|
|
2087
|
+
end
|
|
2088
|
+
## revert all the stuff
|
|
2089
|
+
if dynBlock
|
|
2090
|
+
@doLangBlockEnvs -= @doLangBlock[rBlockId][:env] #first remove useless envRs
|
|
2091
|
+
@doLangBlock.pop
|
|
2092
|
+
end
|
|
2093
|
+
filter.outType=nil
|
|
2094
|
+
## Dyndoc.warn "SORTIE R!",dynBlock,blck,tex2
|
|
2095
|
+
end
|
|
2096
|
+
|
|
2097
|
+
def evalJlBlock(id,cpt,tag,lang=:jl)
|
|
2098
|
+
## Dyndoc.warn "evalJlBlock!!!"
|
|
2099
|
+
## this deals with the problem of newBlcks!
|
|
2100
|
+
## Dyndoc.warn "block_normal",blckMode_normal?
|
|
2101
|
+
## Dyndoc.warn "@doLangBlock",@doLangBlock
|
|
2102
|
+
code=(blckMode_normal? ? @doLangBlock[id][:code][cpt] : "{#blckAnyTag]"+@doLangBlock[id][:code][cpt]+"[#blckAnyTag}" )
|
|
2103
|
+
## Dyndoc.warn "codeJL",code
|
|
2104
|
+
## Dyndoc.warn "filter",@doLangBlock[id][:filter]
|
|
2105
|
+
@doLangBlock[id][:out]=parse(code,@doLangBlock[id][:filter])
|
|
2106
|
+
## Dyndoc.warn "code2JL",@doLangBlock[id][:out]
|
|
2107
|
+
## Dyndoc.warn tag
|
|
2108
|
+
if tag == :>
|
|
2109
|
+
outcode=@doLangBlock[id][:out] #.gsub(/\\/,'\\\\\\\\') #to be compatible with R
|
|
2110
|
+
outcode='print("'+outcode+'")'
|
|
2111
|
+
## Dyndoc.warn "outcode",outcode
|
|
2112
|
+
Julia.exec outcode,:get=>nil # CLEVER: directly redirect in R output that is then captured
|
|
2113
|
+
end
|
|
2114
|
+
if tag == :<<
|
|
2115
|
+
return ( lang==:jl ? JLServer.eval(@doLangBlock[id][:out],@rEnvir[0],true) : eval(@doLangBlock[id][:out]) )
|
|
2116
|
+
else
|
|
2117
|
+
return @doLangBlock[id][:out]
|
|
2118
|
+
end
|
|
2119
|
+
end
|
|
2120
|
+
|
|
2121
|
+
def do_jl(tex,blck,filter)
|
|
2122
|
+
return unless Dyndoc.cfg_dyn[:langs].include? :jl
|
|
2123
|
+
## jlBlock stuff
|
|
2124
|
+
as_default_tmpl_mngr! if
|
|
2125
|
+
dynBlock=dynBlock_in_doLangBlock?(blck)
|
|
2126
|
+
if dynBlock
|
|
2127
|
+
@doLangBlock=[] unless @doLangBlock
|
|
2128
|
+
@doLangBlock << {:tex=>'',:code=>[],:out=>'',:filter=>filter,:env=>[]}
|
|
2129
|
+
jlBlockId=@doLangBlock.length-1
|
|
2130
|
+
end
|
|
2131
|
+
## Dyndoc.warn "do_jl";p blck
|
|
2132
|
+
filter.outType=":jl"
|
|
2133
|
+
# i=0
|
|
2134
|
+
# i,*b2=next_block(blck,i)
|
|
2135
|
+
# code=parse(b2,filter)
|
|
2136
|
+
blck=make_do_lang_blck(blck,jlBlockId,:jl)
|
|
2137
|
+
## Dyndoc.warn "do_jl",blck
|
|
2138
|
+
code = parse_args(blck,filter)
|
|
2139
|
+
## Dyndoc.warn "DO_JL",code
|
|
2140
|
+
## Dyndoc.warn "@doLangBlock",@doLangBlock[0][:code] if @doLangBlock[0]
|
|
2141
|
+
process_jl(code)
|
|
2142
|
+
## Dyndoc.warn "code_jl",code
|
|
2143
|
+
if [:"jl>"].include? blck[0]
|
|
2144
|
+
as_default_tmpl_mngr!
|
|
2145
|
+
tex << JLServer.outputs(code,:block => true)
|
|
2146
|
+
else
|
|
2147
|
+
JLServer.eval(code)
|
|
2148
|
+
end
|
|
2149
|
+
## revert all the stuff
|
|
2150
|
+
if dynBlock
|
|
2151
|
+
@doLangBlockEnvs -= @doLangBlock[jlBlockId][:env] #first remove useless envRs
|
|
2152
|
+
@doLangBlock.pop
|
|
2153
|
+
end
|
|
2154
|
+
filter.outType=nil
|
|
2155
|
+
end
|
|
2156
|
+
|
|
2157
|
+
def do_m(tex,blck,filter)
|
|
2158
|
+
newblck=blck[0]
|
|
2159
|
+
# Dyndoc.warn "do_m";p blck
|
|
2160
|
+
filter.outType=":m"
|
|
2161
|
+
i=0
|
|
2162
|
+
i,*b2=next_block(blck,i)
|
|
2163
|
+
code=parse(b2,filter)
|
|
2164
|
+
|
|
2165
|
+
#p ["Mathematica",code]
|
|
2166
|
+
code='TeXForm['+code+']' if blck[0]==:"M>"
|
|
2167
|
+
tex2=Dyndoc::Converter.mathlink(code)
|
|
2168
|
+
if [:"M>",:"m>"].include? blck[0]
|
|
2169
|
+
tex << (blck[0]==:"M>" ? ('$'+tex2+'$').gsub("\\\\","\\") : tex2 )
|
|
2170
|
+
end
|
|
2171
|
+
filter.outType=nil
|
|
2172
|
+
end
|
|
2173
|
+
|
|
2174
|
+
def do_tags(tex,blck,filter)
|
|
2175
|
+
i=0
|
|
2176
|
+
#puts "do_tags"
|
|
2177
|
+
#p @tags
|
|
2178
|
+
#p blck.length
|
|
2179
|
+
if blck.length==1
|
|
2180
|
+
##p @tags.map{|t| t.inspect}.join(",")
|
|
2181
|
+
tex << @tags.map{|t| t.inspect}.join(",")
|
|
2182
|
+
return
|
|
2183
|
+
end
|
|
2184
|
+
begin
|
|
2185
|
+
case blck[i+=1]
|
|
2186
|
+
when :when
|
|
2187
|
+
tags=TagManager.make_tags(parse_args(blck[i+=1],filter).strip)
|
|
2188
|
+
else
|
|
2189
|
+
puts "ERROR! Only [#when] tag! ";p blck[i]
|
|
2190
|
+
end
|
|
2191
|
+
#p part_tag
|
|
2192
|
+
i,*b2=next_block(blck,i)
|
|
2193
|
+
# fparse if allowed!
|
|
2194
|
+
if TagManager.tags_ok?(tags,@tags)
|
|
2195
|
+
#p b2
|
|
2196
|
+
tex << parse(b2,filter)
|
|
2197
|
+
end
|
|
2198
|
+
end while i<blck.length-1
|
|
2199
|
+
end
|
|
2200
|
+
|
|
2201
|
+
def do_keys(tex,blck,filter)
|
|
2202
|
+
arg=parse_args(blck[1],filter).strip
|
|
2203
|
+
#puts "do_keys: @keys";p @keys
|
|
2204
|
+
#Register!
|
|
2205
|
+
if arg[0..8]=="register:"
|
|
2206
|
+
#puts ">>>>>>>>> Keys->Register";p arg
|
|
2207
|
+
#puts "@keys:";p @keys
|
|
2208
|
+
$dyn_keys={} unless $dyn_keys
|
|
2209
|
+
unless $dyn_keys[:crit]
|
|
2210
|
+
$dyn_keys[:crit]={:pre=>[],:user=>[]}
|
|
2211
|
+
$dyn_keys[:index]=$dyn_keys[:crit][:user]
|
|
2212
|
+
## predefined
|
|
2213
|
+
$dyn_keys[:crit][:pre]=["order","required"]
|
|
2214
|
+
$dyn_keys["order"]={:type=>:order}
|
|
2215
|
+
$dyn_keys["required"]={:type=>:required}
|
|
2216
|
+
## user defined
|
|
2217
|
+
$dyn_keys[:alias]=[]
|
|
2218
|
+
$dyn_keys[:current]=[]
|
|
2219
|
+
$dyn_keys[:begin]=[]
|
|
2220
|
+
$dyn_keys[:end]=[]
|
|
2221
|
+
end
|
|
2222
|
+
arg[9..-1].split(":").each{|e|
|
|
2223
|
+
type=e.split("=").map{|e2| e2.strip}
|
|
2224
|
+
res={:type=>type[1].to_sym}
|
|
2225
|
+
crit,*aliases=type[0].split(",").map{|e2| e2.strip}
|
|
2226
|
+
$dyn_keys[:index] << crit
|
|
2227
|
+
$dyn_keys[crit]=res
|
|
2228
|
+
#which criteria need some further treatments
|
|
2229
|
+
$dyn_keys[:begin] << crit if [:section].include? res[:type]
|
|
2230
|
+
$dyn_keys[:end] << crit if [:section].include? res[:type]
|
|
2231
|
+
unless aliases.empty?
|
|
2232
|
+
$dyn_keys[:alias]+=aliases
|
|
2233
|
+
aliases.each{|e| $dyn_keys[e]=crit}
|
|
2234
|
+
end
|
|
2235
|
+
}
|
|
2236
|
+
$dyn_keys[:index] << "order" << "required"
|
|
2237
|
+
#puts "$dyn_keys";p $dyn_keys
|
|
2238
|
+
#puts "Before: @keys:";p @keys
|
|
2239
|
+
#p @init_keys
|
|
2240
|
+
@keys.merge!(KeysManager.make_keys(@init_keys)) if @init_keys
|
|
2241
|
+
#puts "After make_keys: @keys";p @keys #if @tmpl_cfg[:debug]
|
|
2242
|
+
#p @init_keys
|
|
2243
|
+
#Set!
|
|
2244
|
+
elsif arg[0..3]=="set:"
|
|
2245
|
+
##puts ">>>>>>>>> Keys->Set"
|
|
2246
|
+
@init_keys=KeysManager.init_keys([arg[4..-1].strip])
|
|
2247
|
+
@keys.merge!(KeysManager.make_keys(@init_keys))
|
|
2248
|
+
#Require!
|
|
2249
|
+
elsif arg[0..7]=="require:"
|
|
2250
|
+
##puts ">>>>>>>>> Keys->Require"
|
|
2251
|
+
$dyn_keys[:require]=":"+arg[8..-1]
|
|
2252
|
+
|
|
2253
|
+
#Select!
|
|
2254
|
+
else
|
|
2255
|
+
#puts ">>>>>>>>> Keys->Select"
|
|
2256
|
+
to_merge=(arg[0,1]=="+")
|
|
2257
|
+
if $dyn_keys[:current].empty?
|
|
2258
|
+
mode_keys=:init
|
|
2259
|
+
$dyn_keys[:cpt]=0
|
|
2260
|
+
$dyn_keys[:tex]={}
|
|
2261
|
+
lock_parent=nil unless to_merge
|
|
2262
|
+
else
|
|
2263
|
+
mode_keys=:fetch
|
|
2264
|
+
lock_parent=$dyn_keys[:current][-1] unless to_merge
|
|
2265
|
+
$dyn_keys[:cpt]+=1
|
|
2266
|
+
end
|
|
2267
|
+
|
|
2268
|
+
#puts "mode_keys";p mode_keys
|
|
2269
|
+
#p arg
|
|
2270
|
+
arg=arg[1..-1] if to_merge
|
|
2271
|
+
lock=KeysManager.make(arg)
|
|
2272
|
+
lock=KeysManager.var_names(lock)
|
|
2273
|
+
KeysManager.simplify(lock) #simplify default value!
|
|
2274
|
+
lock_keys_orig=lock.keys
|
|
2275
|
+
if to_merge
|
|
2276
|
+
KeysManager.merge(lock)
|
|
2277
|
+
elsif lock_parent
|
|
2278
|
+
KeysManager.merge(lock,lock_parent)
|
|
2279
|
+
end
|
|
2280
|
+
#p lock
|
|
2281
|
+
KeysManager.make_title(lock)
|
|
2282
|
+
#p $dyn_keys[:title]
|
|
2283
|
+
|
|
2284
|
+
#puts "do_keys:lock";p lock
|
|
2285
|
+
# remember the last lock!
|
|
2286
|
+
$dyn_keys[:lastlock]=lock
|
|
2287
|
+
$dyn_keys[:current] << lock
|
|
2288
|
+
##IMPORTANT: put here and not after the parsing otherwise cpt increases abnormally.
|
|
2289
|
+
unless mode_keys==:init
|
|
2290
|
+
tex << "__DYNKEYS#{$dyn_keys[:cpt]}__"
|
|
2291
|
+
end
|
|
2292
|
+
KeysManager.begin(lock_keys_orig,lock,@keys)
|
|
2293
|
+
@lock=lock #to use inside dyndoc!
|
|
2294
|
+
$dyn_keys[:tex][$dyn_keys[:cpt]] = {:lock=>lock,:content=>parse([blck[2..-1].unshift(:blck)],filter)}
|
|
2295
|
+
if mode_keys==:init
|
|
2296
|
+
#puts "$dyn_keys[:tex]";p $dyn_keys[:tex]
|
|
2297
|
+
texAry=keys_recurse($dyn_keys[:tex][0])
|
|
2298
|
+
#puts "texAry";p texAry
|
|
2299
|
+
texAry=[texAry] unless texAry.is_a? Array
|
|
2300
|
+
keys_print(tex,texAry)
|
|
2301
|
+
end
|
|
2302
|
+
KeysManager.end(lock_keys_orig,lock,@keys)
|
|
2303
|
+
$dyn_keys[:current].pop
|
|
2304
|
+
end
|
|
2305
|
+
end
|
|
2306
|
+
|
|
2307
|
+
def keys_recurse(tex)
|
|
2308
|
+
#puts "keys_recurse: tex";p tex
|
|
2309
|
+
texAry=tex[:content].split(/__DYNKEYS(\d+)__/,-1)
|
|
2310
|
+
if texAry.length==1
|
|
2311
|
+
tex
|
|
2312
|
+
else
|
|
2313
|
+
(0...texAry.length).map do |i|
|
|
2314
|
+
if i%2==1
|
|
2315
|
+
keys_recurse($dyn_keys[:tex][texAry[i].to_i])
|
|
2316
|
+
else
|
|
2317
|
+
{:lock=>tex[:lock],:content=>texAry[i]}
|
|
2318
|
+
end
|
|
2319
|
+
end
|
|
2320
|
+
end
|
|
2321
|
+
end
|
|
2322
|
+
|
|
2323
|
+
def keys_show(texAry)
|
|
2324
|
+
puts "@keys";p @keys
|
|
2325
|
+
texAry.each{|e|
|
|
2326
|
+
p e[:lock]
|
|
2327
|
+
p e[:content]
|
|
2328
|
+
}
|
|
2329
|
+
end
|
|
2330
|
+
|
|
2331
|
+
def keys_select(texAry)
|
|
2332
|
+
texAry.find_all{|e|
|
|
2333
|
+
KeysManager.unlocked?(e[:lock],@keys)
|
|
2334
|
+
}
|
|
2335
|
+
end
|
|
2336
|
+
|
|
2337
|
+
def keys_compare(e1,e2)
|
|
2338
|
+
i,res=0,0
|
|
2339
|
+
#p @keys["order"]
|
|
2340
|
+
while res ==0 and i<@keys["order"].length
|
|
2341
|
+
a=@keys["order"][i]
|
|
2342
|
+
#puts "a";p a
|
|
2343
|
+
res=a[:order]*(e1[:lock][a[:val]] <=> e2[:lock][a[:val]])
|
|
2344
|
+
i+=1
|
|
2345
|
+
end
|
|
2346
|
+
#because of pb of sort to deal with equality!
|
|
2347
|
+
res=e1[:index]<=>e2[:index] if res==0
|
|
2348
|
+
res
|
|
2349
|
+
end
|
|
2350
|
+
|
|
2351
|
+
def keys_sort(texAry)
|
|
2352
|
+
texAry.each_with_index{|e,i| e[:index]=i}
|
|
2353
|
+
texAry.sort{|e1,e2|
|
|
2354
|
+
#p e1;p e2
|
|
2355
|
+
keys_compare(e1,e2)
|
|
2356
|
+
}
|
|
2357
|
+
end
|
|
2358
|
+
|
|
2359
|
+
|
|
2360
|
+
def keys_print(tex,texAry)
|
|
2361
|
+
#keys_show(texAry.flatten) if @tmpl_cfg[:debug]
|
|
2362
|
+
texAry=keys_select(texAry.flatten)
|
|
2363
|
+
keys_show(texAry) if @tmpl_cfg[:debug]
|
|
2364
|
+
texAry=keys_sort(texAry) if @keys["order"]
|
|
2365
|
+
#puts "SORTED"
|
|
2366
|
+
#keys_show(texAry)
|
|
2367
|
+
texAry.each{|e| tex << e[:content]}
|
|
2368
|
+
end
|
|
2369
|
+
|
|
2370
|
+
def do_opt(tex,blck,filter)
|
|
2371
|
+
#p blck
|
|
2372
|
+
#p parse(blck[1..-1],filter)
|
|
2373
|
+
#p parse(blck[1..-1],filter).split(",").map{|e| e.strip}
|
|
2374
|
+
#p @tags
|
|
2375
|
+
taglist=parse(blck[1..-1],filter).strip
|
|
2376
|
+
|
|
2377
|
+
taglist.split(",").map{|e| e.strip}.each{|tag|
|
|
2378
|
+
if tag[0,1]=="-"
|
|
2379
|
+
@tags.delete(TagManager.init_input_tag(tag[1..-1]))
|
|
2380
|
+
else
|
|
2381
|
+
tag=tag[1..-1] if tag[0,1]=="+"
|
|
2382
|
+
@tags << TagManager.init_input_tag(tag)
|
|
2383
|
+
end
|
|
2384
|
+
}
|
|
2385
|
+
#puts "ici";p @tags
|
|
2386
|
+
end
|
|
2387
|
+
|
|
2388
|
+
def make_yield(tex,codename,filter)
|
|
2389
|
+
if @def_blck[-1] and @def_blck[-1].keys.include? codename
|
|
2390
|
+
#codename="default" unless @def_blck[-1].keys.include? codename
|
|
2391
|
+
#p codename
|
|
2392
|
+
#p @def_blck[-1][codename]
|
|
2393
|
+
#p parse([@def_blck[-1][codename]],filter) if @def_blck[-1][codename]
|
|
2394
|
+
tex << parse([@def_blck[-1][codename]],filter) if @def_blck[-1][codename]
|
|
2395
|
+
#p filter.envir.local["self"]
|
|
2396
|
+
end
|
|
2397
|
+
end
|
|
2398
|
+
|
|
2399
|
+
def do_get(tex,blck,filter)
|
|
2400
|
+
blckname=filter.apply(blck[1][1])
|
|
2401
|
+
codename=filter.apply(blck[3][1])
|
|
2402
|
+
if @def_blck[-1] and @def_blck[-1].keys.include? codename
|
|
2403
|
+
@savedBlocks[blckname]=@def_blck[-1][codename]
|
|
2404
|
+
#puts "do_get";p @savedBlocks[blckname]
|
|
2405
|
+
end
|
|
2406
|
+
end
|
|
2407
|
+
|
|
2408
|
+
def do_yield(tex,blck,filter)
|
|
2409
|
+
#p blck
|
|
2410
|
+
#p parse(blck[1..-1],filter)
|
|
2411
|
+
codename=parse(blck[1..-1],filter)
|
|
2412
|
+
make_yield(tex,codename,filter)
|
|
2413
|
+
end
|
|
2414
|
+
|
|
2415
|
+
def do_part(tex,blck,filter)
|
|
2416
|
+
i=0
|
|
2417
|
+
i,*b2=next_block(blck,i)
|
|
2418
|
+
file=parse(b2,filter).strip
|
|
2419
|
+
# prepare the filename
|
|
2420
|
+
file,part=file.split("|").map{|e| e.strip}
|
|
2421
|
+
file,out=file.split("#").map{|e| e.strip}
|
|
2422
|
+
out=(out ? out.to_sym : @cfg[:format_doc])
|
|
2423
|
+
out=:dyn if [:*,:all].include? out
|
|
2424
|
+
file=File.join("part",file+"_part"+Dyndoc::EXTS[out])
|
|
2425
|
+
# part tags prepended by "part:"
|
|
2426
|
+
part=TagManager.make_tags(part.split(",").map{|e| "part:"+e}.join(",")) if part
|
|
2427
|
+
#
|
|
2428
|
+
if File.exist?(file) and (!part or !TagManager.tags_ok?(part,@tags))
|
|
2429
|
+
puts "partial #{file} loaded"
|
|
2430
|
+
tex << File.read(file)
|
|
2431
|
+
else
|
|
2432
|
+
puts "partial #{file} generated"
|
|
2433
|
+
tex2=parse([blck[(i+1)..-1].unshift(:blck)],filter)
|
|
2434
|
+
#puts tex2
|
|
2435
|
+
Dyndoc.make_dir("part")
|
|
2436
|
+
File.open(file,"w") do |f|
|
|
2437
|
+
f << tex2
|
|
2438
|
+
end
|
|
2439
|
+
tex << tex2
|
|
2440
|
+
end
|
|
2441
|
+
end
|
|
2442
|
+
|
|
2443
|
+
end
|
|
2444
|
+
|
|
2445
|
+
end
|
|
2446
|
+
end
|