Skip to content

Commit

Permalink
Merge pull request #19 from gilch/lax-gensyms
Browse files Browse the repository at this point in the history
Allow ``xAUTO..._`` to match any number in document tests
  • Loading branch information
gilch authored Jun 16, 2019
2 parents b6ca386 + a14770c commit 0b43d60
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ gensym.
#> `($#hiss $#hiss)
#..
>>> (lambda *xAUTO0_:xAUTO0_)(
... '_hissxAUTO16_',
... '_hissxAUTO16_')
('_hissxAUTO16_', '_hissxAUTO16_')
... '_hissxAUTO..._',
... '_hissxAUTO..._')
('_hissxAUTO..._', '_hissxAUTO..._')

```

Expand Down
6 changes: 5 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def evaluate(self, example, parser=Parser()):
parser.compiler.ns = example.namespace
hissp = parser.reads(lissp)
compiled = parser.compiler.compile(hissp) + "\n"
assert compiled == python, dedent(
assert norm_gensym_eq(compiled, python), dedent(
f"""
EXPECTED PYTHON:
{indent(python, " ")}
Expand All @@ -58,6 +58,10 @@ def evaluate(self, example, parser=Parser()):
return super().evaluate(example)


def norm_gensym_eq(compiled, python):
"""The special gensym suffix ``xAUTO..._`` will match any number."""
return re.fullmatch(re.sub(r'xAUTO\\\.\\\.\\\._', r'xAUTO\\d+_', re.escape(python)), compiled)

class Globs(Container):
def __init__(self, *globs):
self.globs = globs
Expand Down
24 changes: 11 additions & 13 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,44 @@

import os
import sys
sys.path.insert(0, os.path.abspath('../src'))

sys.path.insert(0, os.path.abspath("../src"))


# -- Project information -----------------------------------------------------

project = 'Hissp'
copyright = '2019, Matthew Egan Odendahl'
author = 'Matthew Egan Odendahl'
project = "Hissp"
copyright = "2019, Matthew Egan Odendahl"
author = "Matthew Egan Odendahl"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
]
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'nature'
html_theme = "nature"
html_theme_options = dict(sidebarwidth=300)

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
8 changes: 5 additions & 3 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -757,11 +757,13 @@ Within a template, the same gensym name always makes the same gensym::
#> `($#hiss $#hiss)
#..
>>> (lambda *xAUTO0_:xAUTO0_)(
... '_hissxAUTO21_',
... '_hissxAUTO21_')
('_hissxAUTO21_', '_hissxAUTO21_')
... '_hissxAUTO..._',
... '_hissxAUTO..._')
('_hissxAUTO..._', '_hissxAUTO..._')

But each new template increments the counter.
(The numbers have been elided to make the doctests work, but they're the same
as well. E.g. ``_hissxAUTO42_``. Try it.)
Gensyms are mainly used to prevent accidental name collisions in generated code.

Data Structures
Expand Down
4 changes: 4 additions & 0 deletions tests/test_basic.lissp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
`(entuple 'entuple))

(deftype TestBasic (unittest..TestCase)
test_same_gensym
(lambda (self)
(.assertEqual self : :* `($#test $#test)))

test_qualified_symbol
(lambda (self)
(.assertEqual self
Expand Down

0 comments on commit 0b43d60

Please sign in to comment.