Skip to content

Commit dd52a7e

Browse files
committed
Fix comment handling in kernel
Resolves #851.
1 parent 13b31f6 commit dd52a7e

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

coconut/compiler/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,12 @@ def rem_comment(line):
19251925
return base
19261926

19271927

1928+
def get_comment(line):
1929+
"""Extract a comment from a line if it has one."""
1930+
base, comment = split_comment(line)
1931+
return comment
1932+
1933+
19281934
def should_indent(code):
19291935
"""Determines whether the next line should be indented."""
19301936
last_line = rem_comment(code.splitlines()[-1])

coconut/icoconut/root.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from coconut.terminal import logger
4949
from coconut.util import override, memoize_with_exceptions, replace_all
5050
from coconut.compiler import Compiler
51-
from coconut.compiler.util import should_indent, paren_change
51+
from coconut.compiler.util import should_indent, paren_change, get_comment
5252
from coconut.command.util import Runner
5353

5454
try:
@@ -214,7 +214,10 @@ def _coconut_assemble_logical_lines():
214214
level += paren_change(no_strs_line)
215215

216216
# put line in parts and break if done
217-
if level < 0:
217+
if get_comment(line):
218+
parts.append(line)
219+
break
220+
elif level < 0:
218221
parts.append(line)
219222
elif no_strs_line.endswith("\\"):
220223
parts.append(line[:-1])

coconut/root.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
VERSION = "3.1.1"
2727
VERSION_NAME = None
2828
# False for release, int >= 1 for develop
29-
DEVELOP = 3
29+
DEVELOP = 4
3030
ALPHA = False # for pre releases rather than post releases
3131

3232
assert DEVELOP is False or DEVELOP >= 1, "DEVELOP must be False or an int >= 1"

coconut/tests/src/extras.coco

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,15 @@ def test_kernel() -> bool:
612612
assert captured_msg_content is None
613613
assert captured_msg_type["content"]["data"]["text/plain"] == "'()'"
614614

615+
assert k.do_execute("""[
616+
"hey",
617+
# "there", # dont want this value now
618+
"is comment"
619+
]""", False, True, {}, True) |> unwrap_future$(loop) |> .["status"] == "ok"
620+
captured_msg_type, captured_msg_content = fake_session.captured_messages[-1]
621+
assert captured_msg_content is None
622+
assert captured_msg_type["content"]["data"]["text/plain"] == "['hey', 'is comment']"
623+
615624
return True
616625

617626

0 commit comments

Comments
 (0)