Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa68083

Browse files
Add EOLComment as a token.
Add and update tests.
1 parent 3eaf490 commit fa68083

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

src/lpython/parser/tokenizer.re

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ std::string token2text(const int token)
808808

809809
T(TK_STRING, "string")
810810
T(TK_COMMENT, "comment")
811+
T(TK_EOLCOMMENT, "eolcomment")
811812
T(TK_LABEL, "label")
812813

813814
T(TK_DBL_DOT, "..")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "cpp-comment1-2f8ab90",
3+
"cmd": "lpython --no-color --show-tokens {infile} -o {outfile}",
4+
"infile": "tests/tokens/comment1.py",
5+
"infile_hash": "27258459bf39e8c5bcaa41e7fef8a593775a915273787edc46c73b4d",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": "cpp-comment1-2f8ab90.stdout",
9+
"stdout_hash": "da6cd47ba8ae6f208980f8e2b43c6b8eea0ccacf90b54fde79d3e55e",
10+
"stderr": null,
11+
"stderr_hash": null,
12+
"returncode": 0
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(TOKEN "eolcomment") 0:10
2+
(TOKEN "identifier" def) 11:13
3+
(TOKEN "identifier" test) 15:18
4+
(TOKEN "(") 19:19
5+
(TOKEN ")") 20:20
6+
(TOKEN ":") 21:21
7+
(TOKEN "eolcomment") 23:34
8+
(TOKEN "comment") 39:50
9+
(KEYWORD "print") 55:59
10+
(TOKEN "(") 60:60
11+
(TOKEN ")") 61:61
12+
(NEWLINE) 62:62
13+
(TOKEN "comment") 63:74
14+
(TOKEN "identifier" test) 75:78
15+
(TOKEN "(") 79:79
16+
(TOKEN ")") 80:80
17+
(TOKEN "eolcomment") 82:93
18+
(TOKEN "comment") 94:105
19+
(NEWLINE) 106:106
20+
(TOKEN "comment") 107:110
21+
(TOKEN "comment") 111:123
22+
(TOKEN "comment") 124:134
23+
(EOF) 135:135

tests/tests.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,7 @@ asr = true
217217
[[test]]
218218
filename = "tokens/docstring1.py"
219219
tokens = true
220+
221+
[[test]]
222+
filename = "tokens/comment1.py"
223+
tokens = true

tests/tokens/comment1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#Comment 1
2+
def test(): # Comment 2
3+
# Comment 3
4+
print()
5+
# Comment 4
6+
test() # Comment 5
7+
# Comment 5
8+
9+
# A
10+
# Multi-line
11+
# Comments

0 commit comments

Comments
 (0)