Preserve .brackets in quoted HyStrings

This commit is contained in:
Kodi Arfer 2017-09-08 11:23:58 -07:00
parent eb23ddc1e2
commit deb801edab
4 changed files with 17 additions and 4 deletions

View File

@ -745,6 +745,12 @@ class HyASTCompiler(object):
return imports, HyExpression([HySymbol(name),
HyString(form)]).replace(form), False
elif isinstance(form, HyString):
x = [HySymbol(name), form]
if form.brackets is not None:
x.extend([HyKeyword(":brackets"), form.brackets])
return imports, HyExpression(x).replace(form), False
return imports, HyExpression([HySymbol(name),
form]).replace(form), False

View File

@ -287,9 +287,7 @@ bracket_string_re = next(r.re for r in lexer.rules if r.name == 'BRACKETSTRING')
def t_bracket_string(p):
m = bracket_string_re.match(p[0].value)
delim, content = m.groups()
s = HyString(content)
s.brackets = delim
return s
return HyString(content, brackets=delim)
@pg.production("identifier : IDENTIFIER")

View File

@ -65,7 +65,10 @@ class HyString(HyObject, str_type):
scripts. It's either a ``str`` or a ``unicode``, depending on the
Python version.
"""
pass
def __new__(cls, s=None, brackets=None):
value = super(HyString, cls).__new__(cls, s)
value.brackets = brackets
return value
_wrappers[str_type] = HyString

View File

@ -1197,6 +1197,12 @@
(assert (= (eval `(get ~d ~k)) 2)))
(defn test-quote-bracket-string-delim []
(assert (= (. '#[my delim[hello world]my delim] brackets) "my delim"))
(assert (= (. '#[[squid]] brackets) ""))
(assert (none? (. '"squid" brackets))))
(defn test-import-syntax []
"NATIVE: test the import syntax."