Preserve .brackets in quoted HyStrings
This commit is contained in:
parent
eb23ddc1e2
commit
deb801edab
@ -745,6 +745,12 @@ class HyASTCompiler(object):
|
|||||||
return imports, HyExpression([HySymbol(name),
|
return imports, HyExpression([HySymbol(name),
|
||||||
HyString(form)]).replace(form), False
|
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),
|
return imports, HyExpression([HySymbol(name),
|
||||||
form]).replace(form), False
|
form]).replace(form), False
|
||||||
|
|
||||||
|
@ -287,9 +287,7 @@ bracket_string_re = next(r.re for r in lexer.rules if r.name == 'BRACKETSTRING')
|
|||||||
def t_bracket_string(p):
|
def t_bracket_string(p):
|
||||||
m = bracket_string_re.match(p[0].value)
|
m = bracket_string_re.match(p[0].value)
|
||||||
delim, content = m.groups()
|
delim, content = m.groups()
|
||||||
s = HyString(content)
|
return HyString(content, brackets=delim)
|
||||||
s.brackets = delim
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
@pg.production("identifier : IDENTIFIER")
|
@pg.production("identifier : IDENTIFIER")
|
||||||
|
@ -65,7 +65,10 @@ class HyString(HyObject, str_type):
|
|||||||
scripts. It's either a ``str`` or a ``unicode``, depending on the
|
scripts. It's either a ``str`` or a ``unicode``, depending on the
|
||||||
Python version.
|
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
|
_wrappers[str_type] = HyString
|
||||||
|
|
||||||
|
@ -1197,6 +1197,12 @@
|
|||||||
(assert (= (eval `(get ~d ~k)) 2)))
|
(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 []
|
(defn test-import-syntax []
|
||||||
"NATIVE: test the import syntax."
|
"NATIVE: test the import syntax."
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user