Skip to content

Commit

Permalink
WIP: one #
Browse files Browse the repository at this point in the history
  • Loading branch information
gilch committed Dec 23, 2023
1 parent f72893a commit b4925c6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/hissp/macros.lissp
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
;;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -2828,7 +2828,7 @@ Creates a lambda of arity {X} containing a `^*#<QzHAT_QzSTAR_QzHASH_>`

.. 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
Expand Down Expand Up @@ -2861,7 +2861,7 @@ Creates a lambda of arity {X} containing a `^*#<QzHAT_QzSTAR_QzHASH_>`

.. 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
Expand Down
11 changes: 5 additions & 6 deletions src/hissp/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
|['`,]
|[.][#]
# Any atom that ends in ``#``, but not ``.#`` or ``\#``.
|(?:[^\\ \n"();#]|\\.)*(?:[^.\\ \n"();#]|\\.)[#]+
|(?:[^\\ \n"();#]|\\.)*(?:[^.\\ \n"();#]|\\.)[#]
)
|(?P<string>
[#]? # raw?
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b4925c6

Please sign in to comment.