From b4925c6ec557d8e529273258b2da2d2cc82e9cd9 Mon Sep 17 00:00:00 2001 From: gilch Date: Sat, 23 Dec 2023 00:24:49 -0700 Subject: [PATCH] WIP: one # --- src/hissp/macros.lissp | 10 +++++----- src/hissp/reader.py | 11 +++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/hissp/macros.lissp b/src/hissp/macros.lissp index 7889d9c76..f3e1c6b69 100644 --- a/src/hissp/macros.lissp +++ b/src/hissp/macros.lissp @@ -883,7 +883,7 @@ Hidden doctest adds bundled macros for REPL-consistent behavior. ;; >>> b'Fully-qualified b# macro at read time.' ;; b'Fully-qualified b# macro at read time.' ;; - ;; #> H:##b"Read-time b# via alias." + ;; #> =H:#b"Read-time b# via alias." ;; >>> b'Read-time b# via alias.' ;; b'Read-time b# via alias.' ;; @@ -963,8 +963,8 @@ Hidden doctest adds bundled macros for REPL-consistent behavior. .. code-block:: REPL - #> @##str.swapcase - #..@##str.title + #> =@#str.swapcase + #..=@#str.title #..(define spam 'spam) ; Unlike Python def, not always a function. >>> # hissp.macros.._macro_.define ... __import__('builtins').globals().update( @@ -2828,7 +2828,7 @@ Creates a lambda of arity {X} containing a `^*#` .. code-block:: REPL - #> (op#add 5 file=spy##sys..stdout(op#mul 7 3)) + #> (op#add 5 file=spy#sys..stdout(op#mul 7 3)) >>> __import__('operator').add( ... (5), ... # hissp.._macro_._spy @@ -2861,7 +2861,7 @@ Creates a lambda of arity {X} containing a `^*#` .. code-block:: REPL - #> file=time##sys..stdout(time..sleep .05) + #> file=time#sys..stdout(time..sleep .05) >>> # hissp.macros.._macro_.let ... (lambda _QzPMWTVFTZz_time=__import__('time').time_ns: ... # hissp.macros.._macro_.letQz_from diff --git a/src/hissp/reader.py b/src/hissp/reader.py index 7952c475e..2279555a1 100644 --- a/src/hissp/reader.py +++ b/src/hissp/reader.py @@ -75,7 +75,7 @@ |['`,] |[.][#] # Any atom that ends in ``#``, but not ``.#`` or ``\#``. - |(?:[^\\ \n"();#]|\\.)*(?:[^.\\ \n"();#]|\\.)[#]+ + |(?:[^\\ \n"();#]|\\.)*(?:[^.\\ \n"();#]|\\.)[#] ) |(?P [#]? # raw? @@ -436,12 +436,11 @@ def _get_counter(self) -> int: def _custom_macro(self, form, tag: str): assert tag.endswith("#") - arity = tag.replace(R"\#", "").count("#") + arity = tag.replace(R"\=", "").count("=") + *keywords, label = re.findall(r"((?:[^=\\]|\\.)*[=#])", tag) + arity += bool(label) assert arity > 0 - *keywords, label = re.findall(r"((?:[^=\\]|\\.)*(?:=|#+))", tag) - if len(keywords) > arity: - raise SyntaxError(f"Not enough # for each = in {tag!r}") - label = label[:-arity] + label = label[:-1] label = force_munge(self.escape(label)) label = re.sub(r"(^\.)", lambda m: force_qz_encode(m[1]), label) fn: Fn[[str], Fn] = self._fully_qualified if ".." in label else self._local