Skip to content

Commit

Permalink
Remove unnecessary optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
evhub committed May 5, 2024
1 parent 89825ed commit 1790eab
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 26 deletions.
2 changes: 1 addition & 1 deletion DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ If the `--strict` (`-s` for short) flag is enabled, Coconut will perform additio
The style issues which will cause `--strict` to throw an error are:

- mixing of tabs and spaces
- use of `"hello" "world"` implicit string concatenation (use `+` instead for clarity; Coconut will compile the `+` away)
- use of `"hello" "world"` implicit string concatenation (use explicit `+` instead)
- use of `from __future__` imports (Coconut does these automatically)
- inheriting from `object` in classes (Coconut does this automatically)
- semicolons at end of lines
Expand Down
19 changes: 1 addition & 18 deletions coconut/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,6 @@ def bind(cls):
cls.unsafe_typedef_tuple <<= attach(cls.unsafe_typedef_tuple_ref, cls.method("unsafe_typedef_tuple_handle"))
cls.impl_call <<= attach(cls.impl_call_ref, cls.method("impl_call_handle"))
cls.protocol_intersect_expr <<= attach(cls.protocol_intersect_expr_ref, cls.method("protocol_intersect_expr_handle"))
cls.and_expr <<= attach(cls.and_expr_ref, cls.method("and_expr_handle"))

# these handlers just do strict/target checking
cls.u_string <<= attach(cls.u_string_ref, cls.method("u_string_check"))
Expand Down Expand Up @@ -4575,7 +4574,7 @@ def string_atom_handle(self, original, loc, tokens, allow_silent_concat=False):
return tokens[0]
else:
if not allow_silent_concat:
self.strict_err_or_warn("found Python-style implicit string concatenation (use explicit '+' for clarity; Coconut will compile it away)", original, loc)
self.strict_err_or_warn("found Python-style implicit string concatenation (use explicit '+' instead)", original, loc)
if any(s.endswith(")") for s in tokens): # has .format() calls
# parens are necessary for string_atom_handle
return "(" + " + ".join(tokens) + ")"
Expand All @@ -4586,22 +4585,6 @@ def string_atom_handle(self, original, loc, tokens, allow_silent_concat=False):

string_atom_handle.ignore_one_token = True

def and_expr_handle(self, original, loc, tokens):
"""Handle expressions that could be explicit string concatenation."""
item, labels = tokens[0]
out = [item]
all_items = [item]
is_str_concat = "IS_STR" in labels
for i in range(1, len(tokens), 2):
op, (item, labels) = tokens[i:i + 2]
out += [op, item]
all_items.append(item)
is_str_concat = is_str_concat and "IS_STR" in labels and op == "+"
if is_str_concat:
return self.string_atom_handle(original, loc, all_items, allow_silent_concat=True)
else:
return " ".join(out)

def unsafe_typedef_tuple_handle(self, original, loc, tokens):
"""Handle Tuples in typedefs."""
tuple_items = self.testlist_star_expr_handle(original, loc, tokens)
Expand Down
7 changes: 2 additions & 5 deletions coconut/compiler/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
using_fast_grammar_methods,
disambiguate_literal,
any_of,
add_labels,
)


Expand Down Expand Up @@ -1370,8 +1369,7 @@ class Grammar(object):
# for known_atom, type should be known at compile time
known_atom = (
const_atom
# IS_STR is used by and_expr_handle
| string_atom("IS_STR")
| string_atom
| list_item
| dict_literal
| dict_comp
Expand Down Expand Up @@ -1580,8 +1578,7 @@ class Grammar(object):
shift,
amp,
)
and_expr = Forward()
and_expr_ref = tokenlist(attach(term, add_labels), term_op, allow_trailing=False, suppress=False)
and_expr = exprlist(term, term_op)

protocol_intersect_expr = Forward()
protocol_intersect_expr_ref = tokenlist(and_expr, amp_colon, allow_trailing=False)
Expand Down
2 changes: 0 additions & 2 deletions coconut/tests/src/extras.coco
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,6 @@ def g(x) = x
assert "builder" in parse("[def x -> (x, y) for y in range(10)]", "lenient")
assert parse("[def x -> (x, y) for y in range(10)]", "lenient").count("def") == 2
assert parse("123 # derp", "lenient") == "123 # derp"
assert parse('"abc" "xyz"', "lenient") == "'abcxyz'"
assert parse('"abc" + "def" + "ghi"', "lenient") == "'abcdefghi'"

return True

Expand Down

0 comments on commit 1790eab

Please sign in to comment.