Skip to content

Commit

Permalink
Fix some things
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrink10 committed Jul 29, 2019
1 parent 6aeffc2 commit fc3a33f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/basilisp/core.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -1947,9 +1947,23 @@

(defmacro ..
"Expand into nested method calls on the returned objects from previous
method calls."
method calls.
Successive method invocations are represented as successive lists:
(.. \"abc\" (lower)) ;=> (. \"abc\" lower)
(.. \"abc\" lower (split \",\")) ;=> (. (. \"abc\" lower) split \",\")
Methods invoked without arguments may be supplied as bare symbols."
[x & method-calls]
)
(if (seq method-calls)
(let [joining (first method-calls)]
`(..
~(if (seq? joining)
(apply list '. x joining)
(list '. x joining))
~@(rest method-calls)))
x))

(defmacro new
"Create a new instance of class with args.
Expand Down
7 changes: 4 additions & 3 deletions src/basilisp/lang/compiler/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
# Constants used in analyzing
AS = kw.keyword("as")
IMPLEMENTS = kw.keyword("implements")
ns_name_chars = re.compile(r"\w|-|\+|\*|\?|/|\=|\\|!|&|%|>|<|\$")
_BUILTINS_NS = "python"

# Symbols to be ignored for unused symbol warnings
Expand Down Expand Up @@ -2048,7 +2049,7 @@ def _list_node(ctx: AnalyzerContext, form: ISeq) -> Node:
return handle_special_form(ctx, form)
elif s.name.startswith(".-"):
return _host_prop_ast(ctx, form)
elif s.name.startswith("."):
elif s.name.startswith(".") and reader.name_chars.match(s.name[1:]):
return _host_call_ast(ctx, form)

return _invoke_ast(ctx, form)
Expand Down Expand Up @@ -2094,7 +2095,7 @@ def __resolve_namespaced_symbol( # pylint: disable=too-many-branches
form=form, class_=class_, target=target, env=ctx.get_node_env()
)

if "." in form.name:
if "." in form.name and form.name != "..":
raise AnalyzerException(
"symbol names may not contain the '.' operator", form=form
)
Expand Down Expand Up @@ -2206,7 +2207,7 @@ def _resolve_sym(
# (Classname. *args)
# (aliased.Classname. *args)
# (fully.qualified.Classname. *args)
if form.ns is None and form.name.endswith("."):
if form.ns is None and form.name.endswith(".") and form.name != "..":
try:
ns, name = form.name[:-1].rsplit(".", maxsplit=1)
form = sym.symbol(name, ns=ns)
Expand Down
1 change: 1 addition & 0 deletions src/basilisp/lang/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from basilisp.util import Maybe, partition

ns_name_chars = re.compile(r"\w|-|\+|\*|\?|/|\=|\\|!|&|%|>|<|\$|\.")
name_chars = re.compile(r"\w|-|\+|\*|\?|/|\=|\\|!|&|%|>|<|\$")
alphanumeric_chars = re.compile(r"\w")
begin_num_chars = re.compile(r"[0-9\-]")
num_chars = re.compile("[0-9]")
Expand Down
6 changes: 6 additions & 0 deletions tests/basilisp/core_macros_test.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@
(is (= nil (comment 1)))
(is (= nil (comment [1 2 3]))))

(deftest double-dot-test
(is (= "abc" (.. "abc")))
(is (= "ABC" (.. "abc" (upper))))
(is (not (.. "abc" (upper) (islower))))
(is (= #py ["A" "B" "C"] (.. "a,b,c" upper (split ",")))))

(deftest if-let-test
(is (= :a (if-let [a :a] a :b)))
(is (= 2 (if-let [a 1] (inc a) :b)))
Expand Down

0 comments on commit fc3a33f

Please sign in to comment.