-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
830 lines (654 loc) · 26.4 KB
/
models.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
import operator
from contextlib import contextmanager
from functools import reduce
from itertools import groupby
from math import isinf, isnan
# from traceback import print_exc
from colorama import Fore
from hy import _initialize_env_var
from hy.errors import HyWrapperError
PRETTY = True
COLORED = _initialize_env_var("HY_COLORED_AST_OBJECTS", False)
@contextmanager
def pretty(pretty=True):
"""
Context manager to temporarily enable
or disable pretty-printing of Hy model reprs.
"""
global PRETTY
old, PRETTY = PRETTY, pretty
try:
yield
finally:
PRETTY = old
class _ColoredModel:
"""
Mixin that provides a helper function for models that have color.
"""
def _colored(self, text):
if COLORED:
return self.color + text + Fore.RESET
else:
return text
class Object:
"An abstract base class for Hy models, which represent forms."
"""
The position properties (`start_line`, `end_line`, `start_column`,
`end_column`) are each 1-based and inclusive. For example, a symbol
`abc` starting at the first column would have `start_column` 1 and
`end_column` 3.
"""
properties = ["module", "_start_line", "_end_line", "_start_column", "_end_column"]
def replace(self, other, recursive=False):
if isinstance(other, Object):
for attr in self.properties:
if not hasattr(self, attr) and hasattr(other, attr):
setattr(self, attr, getattr(other, attr))
else:
raise TypeError(
"Can't replace a non Hy object '{}' with a Hy object '{}'".format(
repr(other), repr(self)
)
)
return self
@property
def start_line(self):
return getattr(self, "_start_line", 1)
@start_line.setter
def start_line(self, value):
self._start_line = value
@property
def start_column(self):
return getattr(self, "_start_column", 1)
@start_column.setter
def start_column(self, value):
self._start_column = value
@property
def end_line(self):
return getattr(self, "_end_line", 1)
@end_line.setter
def end_line(self, value):
self._end_line = value
@property
def end_column(self):
return getattr(self, "_end_column", 1)
@end_column.setter
def end_column(self, value):
self._end_column = value
def __repr__(self):
return (
f"hy.models.{self.__class__.__name__}" f"({super(Object, self).__repr__()})"
)
def __eq__(self, other):
return type(self) is type(other) and super().__eq__(other)
def __ne__(self, other):
# We need this in case another superclass of our subclass
# overrides `__ne__`.
return object.__ne__(self, other)
def __hash__(self):
return super().__hash__()
_wrappers = {}
_seen = set()
def as_model(x):
"""Recursively promote an object ``x`` into its canonical model form.
When creating macros its possible to return non-Hy model objects or
even create an expression with non-Hy model elements::
=> (defmacro hello []
... "world!")
=> (defmacro print-inc [a]
... `(print ~(+ a 1)))
=> (print-inc 1)
2 ; in this case the unquote form (+ 1 1) would splice the literal
; integer ``2`` into the print statement, *not* the model representation
; ``(hy.model.Integer 2)``
This is perfectly fine, because Hy autoboxes these literal values into their
respective model forms at compilation time.
The one case where this distinction between the spliced composit form and
the canonical model tree representation matters, is when comparing some
spliced model tree with another known tree::
=> (= `(print ~(+ 1 1)) '(print 2))
False ; False because the literal int ``2`` in the spliced form is not
; equal to the ``(hy.model.Integer 2)`` value in the known form.
=> (= (hy.as-model `(print ~(+ 1 1)) '(print 2)))
True ; True because ``as-model`` has walked the expression and promoted
; the literal int ``2`` to its model for ``(hy.model.Integer 2)``
"""
if id(x) in _seen:
raise HyWrapperError("Self-referential structure detected in {!r}".format(x))
new = _wrappers.get(type(x), lambda y: y)(x)
if not isinstance(new, Object):
raise HyWrapperError("Don't know how to wrap {!r}: {!r}".format(type(x), x))
if isinstance(x, Object):
new = new.replace(x, recursive=False)
return new
def replace_hy_obj(obj, other):
return as_model(obj).replace(other)
def repr_indent(obj):
return repr(obj).replace("\n", "\n ")
def is_unpack(kind, x):
return isinstance(x, Expression) and len(x) > 0 and x[0] == Symbol("unpack-" + kind)
class String(Object, str):
"""
Represents a literal string (:class:`str`).
:ivar brackets: The custom delimiter used by the bracket string that parsed to this
object, or :data:`None` if it wasn't a bracket string. The outer square brackets
and ``#`` aren't included, so the ``brackets`` attribute of the literal
``#[[hello]]`` is the empty string.
"""
def __new__(cls, s=None, brackets=None):
value = super().__new__(cls, s)
if brackets is not None and f"]{brackets}]" in value:
raise ValueError(f"Syntactically illegal bracket string: {s!r}")
value.brackets = brackets
return value
def __repr__(self):
return "hy.models.String({}{})".format(
super(Object, self).__repr__(),
"" if self.brackets is None else f", brackets={self.brackets!r}",
)
def __add__(self, other):
return self.__class__(super().__add__(other))
_wrappers[str] = String
class Bytes(Object, bytes):
"""
Represents a literal bytestring (:class:`bytes`).
"""
pass
_wrappers[bytes] = Bytes
class Symbol(Object, str):
"""
Represents a symbol.
Symbol objects behave like strings under operations like :hy:func:`get`,
:func:`len`, and :class:`bool`; in particular, ``(bool (hy.models.Symbol "False"))`` is true. Use :hy:func:`hy.eval` to evaluate a symbol.
"""
def __new__(cls, s, from_parser=False):
s = str(s)
if not from_parser:
# Check that the symbol is syntactically legal.
# import here to prevent circular imports.
from hy.reader.hy_reader import symbol_like
sym = symbol_like(s)
if not isinstance(sym, Symbol):
raise ValueError(f"Syntactically illegal symbol: {s!r}")
return sym
return super().__new__(cls, s)
_wrappers[bool] = lambda x: Symbol("True") if x else Symbol("False")
_wrappers[type(None)] = lambda foo: Symbol("None")
class Keyword(Object):
"""
Represents a keyword, such as ``:foo``.
:ivar name: The string content of the keyword, not including the leading ``:``. No
mangling is performed.
"""
__match_args__ = ("name",)
def __init__(self, value, from_parser=False):
value = str(value)
if not from_parser:
# Check that the keyword is syntactically legal.
# import here to prevent circular imports.
from hy.reader.hy_reader import HyReader
from hy.reader.reader import isnormalizedspace
if value and (
"." in value
or any(isnormalizedspace(c) for c in value)
or HyReader.NON_IDENT.intersection(value)
):
raise ValueError(f'Syntactically illegal keyword: {":" + value!r}')
self.name = value
def __repr__(self):
return f"hy.models.{self.__class__.__name__}({self.name!r})"
def __str__(self):
return ":%s" % self.name
def __hash__(self):
return hash(self.name)
def __eq__(self, other):
if not isinstance(other, Keyword):
return NotImplemented
return self.name == other.name
def __ne__(self, other):
if not isinstance(other, Keyword):
return NotImplemented
return self.name != other.name
def __bool__(self):
"""The empty keyword ``:`` is false. All others are true."""
return bool(self.name)
_sentinel = object()
def __call__(self, data, default=_sentinel):
"""Get the element of ``data`` named ``(hy.mangle self.name)``. Thus, ``(:foo
bar)`` is equivalent to ``(get bar "foo")`` (which is different from
``(get bar :foo)``; dictionary keys are typically strings, not
:class:`hy.models.Keyword` objects).
The optional second parameter is a default value; if provided, any
:class:`KeyError` from :hy:func:`get` will be caught, and the default returned
instead."""
from hy.reader import mangle
try:
return data[mangle(self.name)]
except KeyError:
if default is Keyword._sentinel:
raise
return default
def strip_digit_separators(number):
# Don't strip a _ or , if it's the first character, as _42 and
# ,42 aren't valid numbers
return (
number[0] + number[1:].replace("_", "").replace(",", "")
if isinstance(number, str) and len(number) > 1
else number
)
class Integer(Object, int):
"""
Represents a literal integer (:class:`int`).
"""
def __new__(cls, number, *args, **kwargs):
if isinstance(number, str):
number = strip_digit_separators(number)
bases = {"0x": 16, "0o": 8, "0b": 2}
for leader, base in bases.items():
if number.startswith(leader):
# We've got a string, known leader, set base.
number = int(number, base=base)
break
else:
# We've got a string, no known leader; base 10.
number = int(number, base=10)
else:
# We've got a non-string; convert straight.
number = int(number)
return super().__new__(cls, number)
_wrappers[int] = Integer
def check_inf_nan_cap(arg, value):
if isinstance(arg, str):
if isinf(value) and "i" in arg.lower() and "Inf" not in arg:
raise ValueError('Inf must be capitalized as "Inf"')
if isnan(value) and "NaN" not in arg:
raise ValueError('NaN must be capitalized as "NaN"')
class Float(Object, float):
"""
Represents a literal floating-point real number (:class:`float`).
"""
def __new__(cls, num, *args, **kwargs):
value = super().__new__(cls, strip_digit_separators(num))
check_inf_nan_cap(num, value)
return value
_wrappers[float] = Float
class Complex(Object, complex):
"""
Represents a literal floating-point complex number (:class:`complex`).
"""
def __new__(cls, real, imag=0, *args, **kwargs):
if isinstance(real, str):
value = super().__new__(cls, strip_digit_separators(real))
p1, _, p2 = real.lstrip("+-").replace("-", "+").partition("+")
check_inf_nan_cap(p1, value.imag if "j" in p1 else value.real)
if p2:
check_inf_nan_cap(p2, value.imag)
return value
return super().__new__(cls, real, imag)
_wrappers[complex] = Complex
class Sequence(Object, tuple, _ColoredModel):
"""
An abstract base class for sequence-like forms. Sequence models can be operated on
like tuples: you can iterate over them, index into them, and append them with ``+``,
but you can't add, remove, or replace elements. Appending a sequence to another
iterable object reuses the class of the left-hand-side object, which is useful when
e.g. you want to concatenate models in a macro.
"""
def replace(self, other, recursive=True):
if recursive:
for x in self:
replace_hy_obj(x, other)
Object.replace(self, other)
return self
def __add__(self, other):
return self.__class__(
super().__add__(tuple(other) if isinstance(other, list) else other)
)
def __getslice__(self, start, end):
return self.__class__(super().__getslice__(start, end))
def __getitem__(self, item):
ret = super().__getitem__(item)
if isinstance(item, slice):
return self.__class__(ret)
return ret
color = None
def __repr__(self):
return self._pretty_str() if PRETTY else super().__repr__()
def __str__(self):
return self._pretty_str()
def _pretty_str(self):
with pretty():
if self:
return self._colored(
"hy.models.{}{}\n {}{}".format(
self._colored(self.__class__.__name__),
self._colored("(["),
self._colored(",\n ").join(map(repr_indent, self)),
self._colored("])"),
)
)
else:
return self._colored(f"hy.models.{self.__class__.__name__}()")
class FComponent(Sequence):
"""
An analog of :class:`ast.FormattedValue`. The first node in the contained sequence
is the value being formatted. The rest of the sequence contains the nodes in the
format spec (if any).
"""
def __new__(cls, s=None, conversion=None):
value = super().__new__(cls, s)
value.conversion = conversion
return value
def replace(self, other, recursive=True):
super().replace(other, recursive)
if hasattr(other, "conversion"):
self.conversion = other.conversion
return self
def __repr__(self):
return "hy.models.FComponent({})".format(
super(Object, self).__repr__() + ", conversion=" + repr(self.conversion)
)
def _string_in_node(string, node):
if isinstance(node, String) and string in node:
return True
elif isinstance(node, (FComponent, FString)):
return any(_string_in_node(string, node) for node in node)
else:
return False
class FString(Sequence):
"""
Represents a format string as an iterable collection of :class:`hy.models.String`
and :class:`hy.models.FComponent`. The design mimics :class:`ast.JoinedStr`.
:ivar brackets: As in :class:`hy.models.String`.
"""
def __new__(cls, s=None, brackets=None):
value = super().__new__(
cls,
# Join adjacent string nodes for the sake of equality
# testing.
(
node
for is_string, components in groupby(s, lambda x: isinstance(x, String))
for node in (
[reduce(operator.add, components)] if is_string else components
)
),
)
if brackets is not None and _string_in_node(f"]{brackets}]", value):
raise ValueError(f"Syntactically illegal bracket string: {s!r}")
value.brackets = brackets
return value
def __repr__(self):
return self._suffixize(super().__repr__())
def __str__(self):
return self._suffixize(super().__str__())
def _suffixize(self, x):
if self.brackets is None:
return x
return "{}{}brackets={!r})".format(
x[:-1], # Clip off the final close paren
"" if x[-2] == "(" else ", ",
self.brackets,
)
class List(Sequence):
"""
Represents a literal :class:`list`.
Many macros use this model type specially, for something other than defining a
:class:`list`. For example, :hy:func:`defn` expects its function parameters as a
square-bracket-delimited list, and :hy:func:`for` expects a list of iteration
clauses.
"""
color = Fore.CYAN
def recwrap(f):
def lambda_to_return(l):
_seen.add(id(l))
try:
return f(as_model(x) for x in l)
finally:
_seen.remove(id(l))
return lambda_to_return
_wrappers[FComponent] = recwrap(FComponent)
_wrappers[FString] = lambda fstr: FString(
(as_model(x) for x in fstr), brackets=fstr.brackets
)
_wrappers[List] = recwrap(List)
_wrappers[list] = recwrap(List)
class Dict(Sequence, _ColoredModel):
"""
Represents a literal :class:`dict`. ``keys``, ``values``, and ``items`` methods are
provided, each returning a list, although this model type does none of the
normalization of a real :class:`dict`. In the case of an odd number of child models,
``keys`` returns the last child whereas ``values`` and ``items`` ignores it.
"""
color = Fore.GREEN
def _pretty_str(self):
with pretty():
if self:
pairs = []
for k, v in zip(self[::2], self[1::2]):
k, v = repr_indent(k), repr_indent(v)
pairs.append(
("{0}{c}\n {1}\n " if "\n" in k + v else "{0}{c} {1}").format(
k, v, c=self._colored(",")
)
)
if len(self) % 2 == 1:
pairs.append(
"{} {}\n".format(repr_indent(self[-1]), self._colored("# odd"))
)
return "{}\n {}{}".format(
self._colored("hy.models.Dict(["),
"{c}\n ".format(c=self._colored(",")).join(pairs),
self._colored("])"),
)
else:
return self._colored("hy.models.Dict()")
def keys(self):
return list(self[0::2])
def values(self):
return list(self[1::2])
def items(self):
return list(zip(self.keys(), self.values()))
def _dict_wrapper(d):
_seen.add(id(d))
try:
return Dict(as_model(x) for x in sum(d.items(), ()))
finally:
_seen.remove(id(d))
_wrappers[Dict] = recwrap(Dict)
_wrappers[dict] = _dict_wrapper
class Expression(Sequence):
"""
Represents a parenthesized Hy expression.
"""
color = Fore.YELLOW
_wrappers[Expression] = recwrap(Expression)
class Set(Sequence):
"""
Represents a literal :class:`set`. Unlike actual sets, the model retains duplicates
and the order of elements.
"""
color = Fore.RED
_wrappers[Set] = recwrap(Set)
_wrappers[set] = recwrap(Set)
class Tuple(Sequence):
"""
Represents a literal :class:`tuple`.
"""
color = Fore.BLUE
_wrappers[Tuple] = recwrap(Tuple)
_wrappers[tuple] = recwrap(Tuple)
from hy.debugger import myTryExceptMacro, showStackTrace, importReloading, stripTryExcept
import sys
class Lazy(Object):
"""
The output of :hy:func:`hy.read-many`. It represents a sequence of forms, and can be
treated as an iterator. Reading each form lazily, only after evaluating the previous
form, is necessary to handle reader macros correctly; see :hy:func:`hy.read-many`.
"""
def __init__(
self,
gen,
stream=None,
filename=None,
skip_shebang=False,
protect_toplevel=True, # set to False when "-T" in sys.argv
temaps={}, # set it to None when you have "-L" flag in sys.argv
disable_showstack=False,
disable_reloading=False,
debug=False
):
super().__init__()
import sys
from hy.config import config
if (not config['line-by-line']) or any([(a in sys.argv) for a in ["--no-line-by-line-try-except",'-L']]):
temaps = None
if (not config['toplevel']) or any([(a in sys.argv) for a in ['-T','--no-toplevel-try-except']]):
protect_toplevel = False
if (config['disable-showstack']) or any([(a in sys.argv) for a in ['-K','--no-show-stack']]):
disable_showstack = True
if (config['disable-reloading']) or any([(a in sys.argv) for a in ['-R','--no-reloading']]):
disable_reloading=True
self.disable_reloading=disable_reloading
self.disable_showstack = disable_showstack
self._gen1 = gen # are you sure this fucking works?
# you may need three generators.
# you may obtain the same shit.
self.stream = stream
self.debug=debug
self.filename = filename
self.temaps = temaps # setting it to None will disable tryexcept protection in fine-grained level. not recommended though.
self.skip_shebang = skip_shebang
pos = stream.tell()
self.source = stream.read()
# are we skipping shebang?
# if shebang is skipped, we don't take care of that, shall we?
# anyway, the position is just the same.
stream.seek(pos)
from io import StringIO
from hy.reader import HyReader
self.mstream = StringIO(self.source)
# get the try-except ranges right fucking here.
if self.temaps == {}:
if self.debug:
print("____scan twice?____",file=sys.stderr)
# do it here?
self.mstream2 = StringIO(self.source)
cnt = 0
self.mreader2 = HyReader()
self._gen2 = self.mreader2.parse(
stream=self.mstream2, filename=self.filename
)
while True:
# maybe you just cannot raise exception before iteration? maybe you are just unsure about the shit it will do?
try:
form = next(
self._gen2
) # but you cannot get it at the first place. you may have a second try.
# we don't take care of this form.
# form=next(self.mgen)
tryexcept_ranges = self.mreader2.tryexcept_ranges
# and you should do copy that.
self.temaps.update(
{cnt: tryexcept_ranges.copy()}
) # are you sure you want to update?
self.mreader2.tryexcept_ranges = []
cnt += 1
except:
break
# you shall generate all things according till error for this mgen to fetch all sort of things.
# can you assure that? does that fucking work?
self.mreader = HyReader(temaps=self.temaps)
self._gen = self.mreader.parse(self.mstream, self.filename)
else:
if self.debug:
print("____not going to scan twice.____",file=sys.stderr)
self.mreader = None
self._gen = gen # what is this fucking generator?
# self.mreader = HyReader(temaps = None) # fuck?
# self._gen =self.mreader.parse(self.mstream, self.filename)
# self._gen = gen
# handle expressions differently?
# see if the symbol is located somewhere in this namespace. see if there's chance to reload the definition of the damn symbol.
# but most importantly, the damn repl shall be brought here.
# this gen is the reader object. damn.
# how to obtain this shit twice? copy the source code in first place? right fucking here?
# also whats the call for hy.read, which only read one single form?
self.counter = 0
# how to parse it twice?
self.protect_toplevel = protect_toplevel
self.imported_reloading=False
def __iter__(self):
import sys
# wrap this damn shit. PLEASE?
# from hy.models import Expression
# import sys
for elem in self._gen:
# feed with some learned knowledge first, please.
# print("TYPE OF FORM:", type(elem), file=sys.stderr)
# you only prevent shit from here. you need to prevent shit from
# if type(elem) != Expression: #wrap every shit into try-except?
# how to forgive code inside try...except?
# you shall preprocess this shit. for debugging, let's stop using protect_toplevel
if self.counter ==0:
if not self.disable_reloading:
if not self.imported_reloading:
elem=importReloading(elem)
self.imported_reloading=True
# analyze this shit again. PLEASE?
# re-enable this after you are done with temaps.
if self.protect_toplevel:
if self.debug:
print("TOPLEVEL ENABLED", file=sys.stderr)
elem = stripTryExcept(elem)
elem = myTryExceptMacro(
elem, checkExpression=True, skipAssertions=False, topLevel=True
) # will wrap everything.
else:
# toplevel is not enabled. it is raised.
elem = showStackTrace(elem, disable_showstack=self.disable_showstack) # are you fucking sure this fucking works?
# when this shit is not wrapped around shit, it is working.
import sys
debug=False
if self.debug:
print("____", file=sys.stderr)
elem_str=str(elem)
elem_str=elem_str.replace('hy.models.Expression(','E(')
elem_str=elem_str.replace('hy.models.List(','L(')
elem_str=elem_str.replace('hy.models.Symbol(','S(')
elem_str=elem_str.replace('hy.models.String(','STR(')
elem_str=elem_str.replace('hy.models.Integer(','I(')
elem_str=elem_str.replace('hy.models.Keyword(','K(')
print("<FINAL FORM>:", elem_str, file=sys.stderr)
print("____", file=sys.stderr)
yield elem
# and do something afterwards?
if self.mreader:
self.counter += 1
self.mreader.counter += 1
# yield from self._gen
# wtf is this yield from?
def procelem(self, elem):
if self.counter ==0:
if not self.disable_reloading:
if not self.imported_reloading:
elem=importReloading(elem)
self.imported_reloading=True
if self.protect_toplevel:
if self.debug:
print("TOPLEVEL ENABLED", file=sys.stderr)
elem = myTryExceptMacro(
elem, checkExpression=True, skipAssertions=False, topLevel=True
) # will wrap everything.
else:
elem = showStackTrace(elem, disable_showstack=self.disable_showstack)
if self.mreader:
self.counter += 1
self.mreader.counter += 1
return elem
def __next__(self):
## what is this shitty next?
import sys
elem = self._gen.__next__() # what the fuck is this next?
elem=self.procelem(elem)
return elem