Skip to content

Commit

Permalink
Fix comment handling in kernel
Browse files Browse the repository at this point in the history
Resolves    #851.
  • Loading branch information
evhub committed Aug 21, 2024
1 parent 13b31f6 commit dd52a7e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions coconut/compiler/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1925,6 +1925,12 @@ def rem_comment(line):
return base


def get_comment(line):
"""Extract a comment from a line if it has one."""
base, comment = split_comment(line)
return comment


def should_indent(code):
"""Determines whether the next line should be indented."""
last_line = rem_comment(code.splitlines()[-1])
Expand Down
7 changes: 5 additions & 2 deletions coconut/icoconut/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from coconut.terminal import logger
from coconut.util import override, memoize_with_exceptions, replace_all
from coconut.compiler import Compiler
from coconut.compiler.util import should_indent, paren_change
from coconut.compiler.util import should_indent, paren_change, get_comment
from coconut.command.util import Runner

try:
Expand Down Expand Up @@ -214,7 +214,10 @@ def _coconut_assemble_logical_lines():
level += paren_change(no_strs_line)

# put line in parts and break if done
if level < 0:
if get_comment(line):
parts.append(line)
break
elif level < 0:
parts.append(line)
elif no_strs_line.endswith("\\"):
parts.append(line[:-1])
Expand Down
2 changes: 1 addition & 1 deletion coconut/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
VERSION = "3.1.1"
VERSION_NAME = None
# False for release, int >= 1 for develop
DEVELOP = 3
DEVELOP = 4
ALPHA = False # for pre releases rather than post releases

assert DEVELOP is False or DEVELOP >= 1, "DEVELOP must be False or an int >= 1"
Expand Down
9 changes: 9 additions & 0 deletions coconut/tests/src/extras.coco
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,15 @@ def test_kernel() -> bool:
assert captured_msg_content is None
assert captured_msg_type["content"]["data"]["text/plain"] == "'()'"

assert k.do_execute("""[
"hey",
# "there", # dont want this value now
"is comment"
]""", False, True, {}, True) |> unwrap_future$(loop) |> .["status"] == "ok"
captured_msg_type, captured_msg_content = fake_session.captured_messages[-1]
assert captured_msg_content is None
assert captured_msg_type["content"]["data"]["text/plain"] == "['hey', 'is comment']"

return True


Expand Down

0 comments on commit dd52a7e

Please sign in to comment.