This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
xrfragment.py
2716 lines (2469 loc) · 105 KB
/
xrfragment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Generated by Haxe 4.3.3
# coding: utf-8
import sys
import math as python_lib_Math
import math as Math
import inspect as python_lib_Inspect
import re as python_lib_Re
import sys as python_lib_Sys
import functools as python_lib_Functools
import traceback as python_lib_Traceback
from io import StringIO as python_lib_io_StringIO
import urllib.parse as python_lib_urllib_Parse
class _hx_AnonObject:
_hx_disable_getattr = False
def __init__(self, fields):
self.__dict__ = fields
def __repr__(self):
return repr(self.__dict__)
def __contains__(self, item):
return item in self.__dict__
def __getitem__(self, item):
return self.__dict__[item]
def __getattr__(self, name):
if (self._hx_disable_getattr):
raise AttributeError('field does not exist')
else:
return None
def _hx_hasattr(self,field):
self._hx_disable_getattr = True
try:
getattr(self, field)
self._hx_disable_getattr = False
return True
except AttributeError:
self._hx_disable_getattr = False
return False
class Enum:
_hx_class_name = "Enum"
__slots__ = ("tag", "index", "params")
_hx_fields = ["tag", "index", "params"]
_hx_methods = ["__str__"]
def __init__(self,tag,index,params):
self.tag = tag
self.index = index
self.params = params
def __str__(self):
if (self.params is None):
return self.tag
else:
return self.tag + '(' + (', '.join(str(v) for v in self.params)) + ')'
Enum._hx_class = Enum
class Class: pass
class EReg:
_hx_class_name = "EReg"
__slots__ = ("pattern", "matchObj", "_hx_global")
_hx_fields = ["pattern", "matchObj", "global"]
_hx_methods = ["split", "replace"]
def __init__(self,r,opt):
self.matchObj = None
self._hx_global = False
options = 0
_g = 0
_g1 = len(opt)
while (_g < _g1):
i = _g
_g = (_g + 1)
c = (-1 if ((i >= len(opt))) else ord(opt[i]))
if (c == 109):
options = (options | python_lib_Re.M)
if (c == 105):
options = (options | python_lib_Re.I)
if (c == 115):
options = (options | python_lib_Re.S)
if (c == 117):
options = (options | python_lib_Re.U)
if (c == 103):
self._hx_global = True
self.pattern = python_lib_Re.compile(r,options)
def split(self,s):
if self._hx_global:
ret = []
lastEnd = 0
x = python_HaxeIterator(python_lib_Re.finditer(self.pattern,s))
while x.hasNext():
x1 = x.next()
x2 = HxString.substring(s,lastEnd,x1.start())
ret.append(x2)
lastEnd = x1.end()
x = HxString.substr(s,lastEnd,None)
ret.append(x)
return ret
else:
self.matchObj = python_lib_Re.search(self.pattern,s)
if (self.matchObj is None):
return [s]
else:
return [HxString.substring(s,0,self.matchObj.start()), HxString.substr(s,self.matchObj.end(),None)]
def replace(self,s,by):
_this = by.split("$$")
by = "_hx_#repl#__".join([python_Boot.toString1(x1,'') for x1 in _this])
def _hx_local_0(x):
res = by
g = x.groups()
_g = 0
_g1 = len(g)
while (_g < _g1):
i = _g
_g = (_g + 1)
gs = g[i]
if (gs is None):
continue
delimiter = ("$" + HxOverrides.stringOrNull(str((i + 1))))
_this = (list(res) if ((delimiter == "")) else res.split(delimiter))
res = gs.join([python_Boot.toString1(x1,'') for x1 in _this])
_this = res.split("_hx_#repl#__")
res = "$".join([python_Boot.toString1(x1,'') for x1 in _this])
return res
replace = _hx_local_0
return python_lib_Re.sub(self.pattern,replace,s,(0 if (self._hx_global) else 1))
EReg._hx_class = EReg
class Reflect:
_hx_class_name = "Reflect"
__slots__ = ()
_hx_statics = ["field", "getProperty", "callMethod", "isObject", "deleteField", "copy"]
@staticmethod
def field(o,field):
return python_Boot.field(o,field)
@staticmethod
def getProperty(o,field):
if (o is None):
return None
if (field in python_Boot.keywords):
field = ("_hx_" + field)
elif ((((len(field) > 2) and ((ord(field[0]) == 95))) and ((ord(field[1]) == 95))) and ((ord(field[(len(field) - 1)]) != 95))):
field = ("_hx_" + field)
if isinstance(o,_hx_AnonObject):
return Reflect.field(o,field)
tmp = Reflect.field(o,("get_" + ("null" if field is None else field)))
if ((tmp is not None) and callable(tmp)):
return tmp()
else:
return Reflect.field(o,field)
@staticmethod
def callMethod(o,func,args):
if callable(func):
return func(*args)
else:
return None
@staticmethod
def isObject(v):
_g = Type.typeof(v)
tmp = _g.index
if (tmp == 4):
return True
elif (tmp == 6):
_g1 = _g.params[0]
return True
else:
return False
@staticmethod
def deleteField(o,field):
if (field in python_Boot.keywords):
field = ("_hx_" + field)
elif ((((len(field) > 2) and ((ord(field[0]) == 95))) and ((ord(field[1]) == 95))) and ((ord(field[(len(field) - 1)]) != 95))):
field = ("_hx_" + field)
if (not python_Boot.hasField(o,field)):
return False
o.__delattr__(field)
return True
@staticmethod
def copy(o):
if (o is None):
return None
o2 = _hx_AnonObject({})
_g = 0
_g1 = python_Boot.fields(o)
while (_g < len(_g1)):
f = (_g1[_g] if _g >= 0 and _g < len(_g1) else None)
_g = (_g + 1)
value = Reflect.field(o,f)
setattr(o2,(("_hx_" + f) if ((f in python_Boot.keywords)) else (("_hx_" + f) if (((((len(f) > 2) and ((ord(f[0]) == 95))) and ((ord(f[1]) == 95))) and ((ord(f[(len(f) - 1)]) != 95)))) else f)),value)
return o2
Reflect._hx_class = Reflect
class Std:
_hx_class_name = "Std"
__slots__ = ()
_hx_statics = ["isOfType", "string", "parseInt", "shortenPossibleNumber", "parseFloat"]
@staticmethod
def isOfType(v,t):
if ((v is None) and ((t is None))):
return False
if (t is None):
return False
if ((type(t) == type) and (t == Dynamic)):
return (v is not None)
isBool = isinstance(v,bool)
if (((type(t) == type) and (t == Bool)) and isBool):
return True
if ((((not isBool) and (not ((type(t) == type) and (t == Bool)))) and ((type(t) == type) and (t == Int))) and isinstance(v,int)):
return True
vIsFloat = isinstance(v,float)
tmp = None
tmp1 = None
if (((not isBool) and vIsFloat) and ((type(t) == type) and (t == Int))):
f = v
tmp1 = (((f != Math.POSITIVE_INFINITY) and ((f != Math.NEGATIVE_INFINITY))) and (not python_lib_Math.isnan(f)))
else:
tmp1 = False
if tmp1:
tmp1 = None
try:
tmp1 = int(v)
except BaseException as _g:
None
tmp1 = None
tmp = (v == tmp1)
else:
tmp = False
if ((tmp and ((v <= 2147483647))) and ((v >= -2147483648))):
return True
if (((not isBool) and ((type(t) == type) and (t == Float))) and isinstance(v,(float, int))):
return True
if ((type(t) == type) and (t == str)):
return isinstance(v,str)
isEnumType = ((type(t) == type) and (t == Enum))
if ((isEnumType and python_lib_Inspect.isclass(v)) and hasattr(v,"_hx_constructs")):
return True
if isEnumType:
return False
isClassType = ((type(t) == type) and (t == Class))
if ((((isClassType and (not isinstance(v,Enum))) and python_lib_Inspect.isclass(v)) and hasattr(v,"_hx_class_name")) and (not hasattr(v,"_hx_constructs"))):
return True
if isClassType:
return False
tmp = None
try:
tmp = isinstance(v,t)
except BaseException as _g:
None
tmp = False
if tmp:
return True
if python_lib_Inspect.isclass(t):
cls = t
loop = None
def _hx_local_1(intf):
f = (intf._hx_interfaces if (hasattr(intf,"_hx_interfaces")) else [])
if (f is not None):
_g = 0
while (_g < len(f)):
i = (f[_g] if _g >= 0 and _g < len(f) else None)
_g = (_g + 1)
if (i == cls):
return True
else:
l = loop(i)
if l:
return True
return False
else:
return False
loop = _hx_local_1
currentClass = v.__class__
result = False
while (currentClass is not None):
if loop(currentClass):
result = True
break
currentClass = python_Boot.getSuperClass(currentClass)
return result
else:
return False
@staticmethod
def string(s):
return python_Boot.toString1(s,"")
@staticmethod
def parseInt(x):
if (x is None):
return None
_hx_len = len(x)
index = 0
while (index < _hx_len):
if (not (x[index] in " \n\r\t\x0B\x0C")):
break
index = (index + 1)
isNegative = None
if (index < _hx_len):
sign = x[index]
if ((sign == "-") or ((sign == "+"))):
index = (index + 1)
isNegative = (sign == "-")
else:
isNegative = False
isHexadecimal = None
if ((index + 1) < _hx_len):
cur = x[index]
next = x[(index + 1)]
isHexadecimal = ((cur == "0") and (((next == "x") or ((next == "X")))))
else:
isHexadecimal = False
if isHexadecimal:
index = (index + 2)
cur = index
if isHexadecimal:
while (cur < _hx_len):
if (not (x[cur] in "0123456789abcdefABCDEF")):
break
cur = (cur + 1)
else:
while (cur < _hx_len):
if (not (x[cur] in "0123456789")):
break
cur = (cur + 1)
firstInvalidIndex = cur
if (index == firstInvalidIndex):
return None
result = int(HxString.substring(x,index,firstInvalidIndex),(16 if isHexadecimal else 10))
if isNegative:
return -result
else:
return result
@staticmethod
def shortenPossibleNumber(x):
r = ""
_g = 0
_g1 = len(x)
while (_g < _g1):
i = _g
_g = (_g + 1)
c = ("" if (((i < 0) or ((i >= len(x))))) else x[i])
_g2 = HxString.charCodeAt(c,0)
if (_g2 is None):
break
else:
_g3 = _g2
if (((((((((((_g3 == 57) or ((_g3 == 56))) or ((_g3 == 55))) or ((_g3 == 54))) or ((_g3 == 53))) or ((_g3 == 52))) or ((_g3 == 51))) or ((_g3 == 50))) or ((_g3 == 49))) or ((_g3 == 48))) or ((_g3 == 46))):
r = (("null" if r is None else r) + ("null" if c is None else c))
else:
break
return r
@staticmethod
def parseFloat(x):
try:
return float(x)
except BaseException as _g:
None
if (x is not None):
r1 = Std.shortenPossibleNumber(x)
if (r1 != x):
return Std.parseFloat(r1)
return Math.NaN
Std._hx_class = Std
class Float: pass
class Int: pass
class Bool: pass
class Dynamic: pass
class StringBuf:
_hx_class_name = "StringBuf"
__slots__ = ("b",)
_hx_fields = ["b"]
def __init__(self):
self.b = python_lib_io_StringIO()
StringBuf._hx_class = StringBuf
class StringTools:
_hx_class_name = "StringTools"
__slots__ = ()
_hx_statics = ["isSpace", "ltrim", "rtrim", "trim", "replace"]
@staticmethod
def isSpace(s,pos):
if (((len(s) == 0) or ((pos < 0))) or ((pos >= len(s)))):
return False
c = HxString.charCodeAt(s,pos)
if (not (((c > 8) and ((c < 14))))):
return (c == 32)
else:
return True
@staticmethod
def ltrim(s):
l = len(s)
r = 0
while ((r < l) and StringTools.isSpace(s,r)):
r = (r + 1)
if (r > 0):
return HxString.substr(s,r,(l - r))
else:
return s
@staticmethod
def rtrim(s):
l = len(s)
r = 0
while ((r < l) and StringTools.isSpace(s,((l - r) - 1))):
r = (r + 1)
if (r > 0):
return HxString.substr(s,0,(l - r))
else:
return s
@staticmethod
def trim(s):
return StringTools.ltrim(StringTools.rtrim(s))
@staticmethod
def replace(s,sub,by):
_this = (list(s) if ((sub == "")) else s.split(sub))
return by.join([python_Boot.toString1(x1,'') for x1 in _this])
StringTools._hx_class = StringTools
class ValueType(Enum):
__slots__ = ()
_hx_class_name = "ValueType"
_hx_constructs = ["TNull", "TInt", "TFloat", "TBool", "TObject", "TFunction", "TClass", "TEnum", "TUnknown"]
@staticmethod
def TClass(c):
return ValueType("TClass", 6, (c,))
@staticmethod
def TEnum(e):
return ValueType("TEnum", 7, (e,))
ValueType.TNull = ValueType("TNull", 0, ())
ValueType.TInt = ValueType("TInt", 1, ())
ValueType.TFloat = ValueType("TFloat", 2, ())
ValueType.TBool = ValueType("TBool", 3, ())
ValueType.TObject = ValueType("TObject", 4, ())
ValueType.TFunction = ValueType("TFunction", 5, ())
ValueType.TUnknown = ValueType("TUnknown", 8, ())
ValueType._hx_class = ValueType
class Type:
_hx_class_name = "Type"
__slots__ = ()
_hx_statics = ["typeof"]
@staticmethod
def typeof(v):
if (v is None):
return ValueType.TNull
elif isinstance(v,bool):
return ValueType.TBool
elif isinstance(v,int):
return ValueType.TInt
elif isinstance(v,float):
return ValueType.TFloat
elif isinstance(v,str):
return ValueType.TClass(str)
elif isinstance(v,list):
return ValueType.TClass(list)
elif (isinstance(v,_hx_AnonObject) or python_lib_Inspect.isclass(v)):
return ValueType.TObject
elif isinstance(v,Enum):
return ValueType.TEnum(v.__class__)
elif (isinstance(v,type) or hasattr(v,"_hx_class")):
return ValueType.TClass(v.__class__)
elif callable(v):
return ValueType.TFunction
else:
return ValueType.TUnknown
Type._hx_class = Type
class haxe_IMap:
_hx_class_name = "haxe.IMap"
__slots__ = ()
haxe_IMap._hx_class = haxe_IMap
class haxe_Exception(Exception):
_hx_class_name = "haxe.Exception"
__slots__ = ("_hx___nativeStack", "_hx___skipStack", "_hx___nativeException", "_hx___previousException")
_hx_fields = ["__nativeStack", "__skipStack", "__nativeException", "__previousException"]
_hx_methods = ["unwrap", "get_native"]
_hx_statics = ["caught", "thrown"]
_hx_interfaces = []
_hx_super = Exception
def __init__(self,message,previous = None,native = None):
self._hx___previousException = None
self._hx___nativeException = None
self._hx___nativeStack = None
self._hx___skipStack = 0
super().__init__(message)
self._hx___previousException = previous
if ((native is not None) and Std.isOfType(native,BaseException)):
self._hx___nativeException = native
self._hx___nativeStack = haxe_NativeStackTrace.exceptionStack()
else:
self._hx___nativeException = self
infos = python_lib_Traceback.extract_stack()
if (len(infos) != 0):
infos.pop()
infos.reverse()
self._hx___nativeStack = infos
def unwrap(self):
return self._hx___nativeException
def get_native(self):
return self._hx___nativeException
@staticmethod
def caught(value):
if Std.isOfType(value,haxe_Exception):
return value
elif Std.isOfType(value,BaseException):
return haxe_Exception(str(value),None,value)
else:
return haxe_ValueException(value,None,value)
@staticmethod
def thrown(value):
if Std.isOfType(value,haxe_Exception):
return value.get_native()
elif Std.isOfType(value,BaseException):
return value
else:
e = haxe_ValueException(value)
e._hx___skipStack = (e._hx___skipStack + 1)
return e
haxe_Exception._hx_class = haxe_Exception
class haxe_NativeStackTrace:
_hx_class_name = "haxe.NativeStackTrace"
__slots__ = ()
_hx_statics = ["saveStack", "exceptionStack"]
@staticmethod
def saveStack(exception):
pass
@staticmethod
def exceptionStack():
exc = python_lib_Sys.exc_info()
if (exc[2] is not None):
infos = python_lib_Traceback.extract_tb(exc[2])
infos.reverse()
return infos
else:
return []
haxe_NativeStackTrace._hx_class = haxe_NativeStackTrace
class haxe__Template_TemplateExpr(Enum):
__slots__ = ()
_hx_class_name = "haxe._Template.TemplateExpr"
_hx_constructs = ["OpVar", "OpExpr", "OpIf", "OpStr", "OpBlock", "OpForeach", "OpMacro"]
@staticmethod
def OpVar(v):
return haxe__Template_TemplateExpr("OpVar", 0, (v,))
@staticmethod
def OpExpr(expr):
return haxe__Template_TemplateExpr("OpExpr", 1, (expr,))
@staticmethod
def OpIf(expr,eif,eelse):
return haxe__Template_TemplateExpr("OpIf", 2, (expr,eif,eelse))
@staticmethod
def OpStr(str):
return haxe__Template_TemplateExpr("OpStr", 3, (str,))
@staticmethod
def OpBlock(l):
return haxe__Template_TemplateExpr("OpBlock", 4, (l,))
@staticmethod
def OpForeach(expr,loop):
return haxe__Template_TemplateExpr("OpForeach", 5, (expr,loop))
@staticmethod
def OpMacro(name,params):
return haxe__Template_TemplateExpr("OpMacro", 6, (name,params))
haxe__Template_TemplateExpr._hx_class = haxe__Template_TemplateExpr
class haxe_iterators_ArrayIterator:
_hx_class_name = "haxe.iterators.ArrayIterator"
__slots__ = ("array", "current")
_hx_fields = ["array", "current"]
_hx_methods = ["hasNext", "next"]
def __init__(self,array):
self.current = 0
self.array = array
def hasNext(self):
return (self.current < len(self.array))
def next(self):
def _hx_local_3():
def _hx_local_2():
_hx_local_0 = self
_hx_local_1 = _hx_local_0.current
_hx_local_0.current = (_hx_local_1 + 1)
return _hx_local_1
return python_internal_ArrayImpl._get(self.array, _hx_local_2())
return _hx_local_3()
haxe_iterators_ArrayIterator._hx_class = haxe_iterators_ArrayIterator
class haxe_Template:
_hx_class_name = "haxe.Template"
__slots__ = ("expr", "context", "macros", "stack", "buf")
_hx_fields = ["expr", "context", "macros", "stack", "buf"]
_hx_methods = ["execute", "resolve", "parseTokens", "parseBlock", "parse", "parseExpr", "makeConst", "makePath", "makeExpr", "skipSpaces", "makeExpr2", "run"]
_hx_statics = ["splitter", "expr_splitter", "expr_trim", "expr_int", "expr_float", "globals", "hxKeepArrayIterator"]
def __init__(self,_hx_str):
self.buf = None
self.stack = None
self.macros = None
self.context = None
self.expr = None
tokens = self.parseTokens(_hx_str)
self.expr = self.parseBlock(tokens)
if (not tokens.isEmpty()):
raise haxe_Exception.thrown((("Unexpected '" + Std.string(tokens.first().s)) + "'"))
def execute(self,context,macros = None):
self.macros = (_hx_AnonObject({}) if ((macros is None)) else macros)
self.context = context
self.stack = haxe_ds_List()
self.buf = StringBuf()
self.run(self.expr)
return self.buf.b.getvalue()
def resolve(self,v):
if (v == "__current__"):
return self.context
if Reflect.isObject(self.context):
value = Reflect.getProperty(self.context,v)
if ((value is not None) or python_Boot.hasField(self.context,v)):
return value
_g_head = self.stack.h
while (_g_head is not None):
val = _g_head.item
_g_head = _g_head.next
ctx = val
value = Reflect.getProperty(ctx,v)
if ((value is not None) or python_Boot.hasField(ctx,v)):
return value
return Reflect.field(haxe_Template.globals,v)
def parseTokens(self,data):
tokens = haxe_ds_List()
while True:
_this = haxe_Template.splitter
_this.matchObj = python_lib_Re.search(_this.pattern,data)
if (not ((_this.matchObj is not None))):
break
_this1 = haxe_Template.splitter
p_pos = _this1.matchObj.start()
p_len = (_this1.matchObj.end() - _this1.matchObj.start())
if (p_pos > 0):
tokens.add(_hx_AnonObject({'p': HxString.substr(data,0,p_pos), 's': True, 'l': None}))
if (HxString.charCodeAt(data,p_pos) == 58):
tokens.add(_hx_AnonObject({'p': HxString.substr(data,(p_pos + 2),(p_len - 4)), 's': False, 'l': None}))
_this2 = haxe_Template.splitter
data = HxString.substr(_this2.matchObj.string,_this2.matchObj.end(),None)
continue
parp = (p_pos + p_len)
npar = 1
params = []
part = ""
while True:
c = HxString.charCodeAt(data,parp)
parp = (parp + 1)
if (c == 40):
npar = (npar + 1)
elif (c == 41):
npar = (npar - 1)
if (npar <= 0):
break
elif (c is None):
raise haxe_Exception.thrown("Unclosed macro parenthesis")
if ((c == 44) and ((npar == 1))):
params.append(part)
part = ""
else:
part = (("null" if part is None else part) + HxOverrides.stringOrNull("".join(map(chr,[c]))))
params.append(part)
tokens.add(_hx_AnonObject({'p': haxe_Template.splitter.matchObj.group(2), 's': False, 'l': params}))
data = HxString.substr(data,parp,(len(data) - parp))
if (len(data) > 0):
tokens.add(_hx_AnonObject({'p': data, 's': True, 'l': None}))
return tokens
def parseBlock(self,tokens):
l = haxe_ds_List()
while True:
t = tokens.first()
if (t is None):
break
if ((not t.s) and ((((t.p == "end") or ((t.p == "else"))) or ((HxString.substr(t.p,0,7) == "elseif "))))):
break
l.add(self.parse(tokens))
if (l.length == 1):
return l.first()
return haxe__Template_TemplateExpr.OpBlock(l)
def parse(self,tokens):
t = tokens.pop()
p = t.p
if t.s:
return haxe__Template_TemplateExpr.OpStr(p)
if (t.l is not None):
pe = haxe_ds_List()
_g = 0
_g1 = t.l
while (_g < len(_g1)):
p1 = (_g1[_g] if _g >= 0 and _g < len(_g1) else None)
_g = (_g + 1)
pe.add(self.parseBlock(self.parseTokens(p1)))
return haxe__Template_TemplateExpr.OpMacro(p,pe)
def _hx_local_2(kwd):
pos = -1
length = len(kwd)
if (HxString.substr(p,0,length) == kwd):
pos = length
_g_offset = 0
_g_s = HxString.substr(p,length,None)
while (_g_offset < len(_g_s)):
index = _g_offset
_g_offset = (_g_offset + 1)
c = ord(_g_s[index])
if (c == 32):
pos = (pos + 1)
else:
break
return pos
kwdEnd = _hx_local_2
pos = kwdEnd("if")
if (pos > 0):
p = HxString.substr(p,pos,(len(p) - pos))
e = self.parseExpr(p)
eif = self.parseBlock(tokens)
t = tokens.first()
eelse = None
if (t is None):
raise haxe_Exception.thrown("Unclosed 'if'")
if (t.p == "end"):
tokens.pop()
eelse = None
elif (t.p == "else"):
tokens.pop()
eelse = self.parseBlock(tokens)
t = tokens.pop()
if ((t is None) or ((t.p != "end"))):
raise haxe_Exception.thrown("Unclosed 'else'")
else:
t.p = HxString.substr(t.p,4,(len(t.p) - 4))
eelse = self.parse(tokens)
return haxe__Template_TemplateExpr.OpIf(e,eif,eelse)
pos = kwdEnd("foreach")
if (pos >= 0):
p = HxString.substr(p,pos,(len(p) - pos))
e = self.parseExpr(p)
efor = self.parseBlock(tokens)
t = tokens.pop()
if ((t is None) or ((t.p != "end"))):
raise haxe_Exception.thrown("Unclosed 'foreach'")
return haxe__Template_TemplateExpr.OpForeach(e,efor)
_this = haxe_Template.expr_splitter
_this.matchObj = python_lib_Re.search(_this.pattern,p)
if (_this.matchObj is not None):
return haxe__Template_TemplateExpr.OpExpr(self.parseExpr(p))
return haxe__Template_TemplateExpr.OpVar(p)
def parseExpr(self,data):
l = haxe_ds_List()
expr = data
while True:
_this = haxe_Template.expr_splitter
_this.matchObj = python_lib_Re.search(_this.pattern,data)
if (not ((_this.matchObj is not None))):
break
_this1 = haxe_Template.expr_splitter
p_pos = _this1.matchObj.start()
p_len = (_this1.matchObj.end() - _this1.matchObj.start())
k = (p_pos + p_len)
if (p_pos != 0):
l.add(_hx_AnonObject({'p': HxString.substr(data,0,p_pos), 's': True}))
p = haxe_Template.expr_splitter.matchObj.group(0)
startIndex = None
l.add(_hx_AnonObject({'p': p, 's': (((p.find("\"") if ((startIndex is None)) else HxString.indexOfImpl(p,"\"",startIndex))) >= 0)}))
_this2 = haxe_Template.expr_splitter
data = HxString.substr(_this2.matchObj.string,_this2.matchObj.end(),None)
if (len(data) != 0):
_g_offset = 0
_g_s = data
while (_g_offset < len(_g_s)):
_g_key = _g_offset
s = _g_s
index = _g_offset
_g_offset = (_g_offset + 1)
_g_value = (-1 if ((index >= len(s))) else ord(s[index]))
i = _g_key
c = _g_value
if (c != 32):
l.add(_hx_AnonObject({'p': HxString.substr(data,i,None), 's': True}))
break
e = None
try:
e = self.makeExpr(l)
if (not l.isEmpty()):
raise haxe_Exception.thrown(l.first().p)
except BaseException as _g:
None
_g1 = haxe_Exception.caught(_g).unwrap()
if Std.isOfType(_g1,str):
s = _g1
raise haxe_Exception.thrown(((("Unexpected '" + ("null" if s is None else s)) + "' in ") + ("null" if expr is None else expr)))
else:
raise _g
def _hx_local_0():
try:
return e()
except BaseException as _g:
None
exc = haxe_Exception.caught(_g).unwrap()
raise haxe_Exception.thrown(((("Error : " + Std.string(exc)) + " in ") + ("null" if expr is None else expr)))
return _hx_local_0
def makeConst(self,v):
_this = haxe_Template.expr_trim
_this.matchObj = python_lib_Re.search(_this.pattern,v)
v = haxe_Template.expr_trim.matchObj.group(1)
if (HxString.charCodeAt(v,0) == 34):
_hx_str = HxString.substr(v,1,(len(v) - 2))
def _hx_local_0():
return _hx_str
return _hx_local_0
_this = haxe_Template.expr_int
_this.matchObj = python_lib_Re.search(_this.pattern,v)
if (_this.matchObj is not None):
i = Std.parseInt(v)
def _hx_local_1():
return i
return _hx_local_1
_this = haxe_Template.expr_float
_this.matchObj = python_lib_Re.search(_this.pattern,v)
if (_this.matchObj is not None):
f = Std.parseFloat(v)
def _hx_local_2():
return f
return _hx_local_2
me = self
def _hx_local_3():
return me.resolve(v)
return _hx_local_3
def makePath(self,e,l):
p = l.first()
if ((p is None) or ((p.p != "."))):
return e
l.pop()
field = l.pop()
if ((field is None) or (not field.s)):
raise haxe_Exception.thrown(field.p)
f = field.p
_this = haxe_Template.expr_trim
_this.matchObj = python_lib_Re.search(_this.pattern,f)
f = haxe_Template.expr_trim.matchObj.group(1)
def _hx_local_1():
def _hx_local_0():
return Reflect.field(e(),f)
return self.makePath(_hx_local_0,l)
return _hx_local_1()
def makeExpr(self,l):
return self.makePath(self.makeExpr2(l),l)
def skipSpaces(self,l):
p = l.first()
while (p is not None):
_g_offset = 0
_g_s = p.p
while (_g_offset < len(_g_s)):
index = _g_offset
_g_offset = (_g_offset + 1)
c = ord(_g_s[index])
if (c != 32):
return
l.pop()
p = l.first()
def makeExpr2(self,l):
self.skipSpaces(l)
p = l.pop()
self.skipSpaces(l)
if (p is None):
raise haxe_Exception.thrown("<eof>")
if p.s:
return self.makeConst(p.p)
_g = p.p
if (_g == "!"):
e = self.makeExpr(l)
def _hx_local_0():
v = e()
if (v is not None):
return (v == False)
else:
return True
return _hx_local_0
elif (_g == "("):
self.skipSpaces(l)
e1 = self.makeExpr(l)
self.skipSpaces(l)
p1 = l.pop()
if ((p1 is None) or p1.s):
raise haxe_Exception.thrown(p1)
if (p1.p == ")"):
return e1
self.skipSpaces(l)
e2 = self.makeExpr(l)
self.skipSpaces(l)
p2 = l.pop()
self.skipSpaces(l)
if ((p2 is None) or ((p2.p != ")"))):
raise haxe_Exception.thrown(p2)
_g = p1.p
_hx_local_1 = len(_g)
if (_hx_local_1 == 1):
if (_g == "*"):
def _hx_local_2():
return (e1() * e2())
return _hx_local_2
elif (_g == "+"):
def _hx_local_3():
return python_Boot._add_dynamic(e1(),e2())
return _hx_local_3
elif (_g == "-"):
def _hx_local_4():
return (e1() - e2())
return _hx_local_4
elif (_g == "/"):
def _hx_local_5():
return (e1() / e2())
return _hx_local_5
elif (_g == "<"):
def _hx_local_6():
return (e1() < e2())
return _hx_local_6
elif (_g == ">"):
def _hx_local_7():
return (e1() > e2())