Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_lex_bracket_strings():
objs = tokenize("#[my delim[hello world]my delim]")
assert objs == [HyString("hello world")]
assert objs[0].brackets == "my delim"
objs = tokenize("#[[squid]]")
assert objs == [HyString("squid")]
assert objs[0].brackets == ""
def hash_other(state, p):
# p == [(Token('HASHOTHER', '#foo'), bar)]
st = p[0].getstr()[1:]
str_object = HyString(st)
expr = p[1]
return HyExpression([HySymbol("dispatch-tag-macro"), str_object, expr])
imports.update(f_imps)
if splice:
contents.append(HyExpression([
HySymbol("list"),
HyExpression([HySymbol("or"), f_contents, HyList()])]))
else:
contents.append(HyList([f_contents]))
if form:
# If there are arguments, they can be spliced
# so we build a sum...
body = [HyExpression([HySymbol("+"), HyList()] + contents)]
else:
body = [HyList()]
elif isinstance(form, HySymbol):
body = [HyString(form)]
elif isinstance(form, HyKeyword):
body = [HyString(form.name)]
elif isinstance(form, HyString):
if form.is_format:
body.extend([HyKeyword("is_format"), form.is_format])
if form.brackets is not None:
body.extend([HyKeyword("brackets"), form.brackets])
ret = HyExpression([HySymbol(name)] + body).replace(form)
return imports, ret, False
def __new__(cls, s=None, brackets=None):
value = super(HyString, cls).__new__(cls, s)
value.brackets = brackets
return value
expr, module=module or None, names=names, level=level)
elif require(ast_module, self.module, assignments=assignments,
prefix=prefix):
# Actually calling `require` is necessary for macro expansions
# occurring during compilation.
self.imports['hy.macros'].update([None])
# The `require` we're creating in AST is the same as above, but used at
# run-time (e.g. when modules are loaded via bytecode).
ret += self.compile(HyExpression([
HySymbol('hy.macros.require'),
HyString(ast_module),
HySymbol('None'),
HyKeyword('assignments'),
(HyString("ALL") if assignments == "ALL" else
[[HyString(k), HyString(v)] for k, v in assignments]),
HyKeyword('prefix'),
HyString(prefix)]).replace(expr))
return ret
def compile_dispatch_tag_macro(self, expr, root, tag, arg):
return self.compile(tag_macroexpand(
HyString(mangle(tag)).replace(tag),
arg,
self.module))
STR = some(lambda x: isinstance(x, HyString))