Skip to content

Commit 0253ec0

Browse files
committed
In work btw for non naive parser
1 parent 5cd1a6c commit 0253ec0

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

stroll/src/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def getcliargs() -> str:
99
with open(args.FILENAME, "r") as f:
1010
result = f.read()
1111

12-
if not args.FILENAME.endswith(".calx"):
12+
if not args.FILENAME.endswith(".sr"):
1313
print(Extensionerror(result, "Change the file extension"))
1414
terminate()
1515
return result

stroll/src/lexer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from errors import Syntaxerror, Extensionerror, Miscerror, terminate
2-
31
def tokenize(s: str):
42
tokens = []
53
i, n = 0, len(s)

stroll/src/nonnaiveparser.sr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(print "with open('file.txt') as f: x = f.read();print(x, ')')")

stroll/src/parser.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,24 @@ def atom(token):
99
except ValueError:
1010
return str(token)
1111

12-
def parse(tokens):
13-
#print(tokens)
12+
def parse(tokens, inquote=False, quotetype=None):
13+
print(tokens)
1414
token = tokens.pop(0)
1515

16-
if token == '(':
16+
if token == "'" or token == '"' or token == "\'" or token == '\"':
17+
if inquote:
18+
if token == quotetype:
19+
inquote = False
20+
quotetype=None
21+
else:
22+
inquote = True
23+
quotetype == quotetype
24+
25+
if token == '(' and inquote==False:
1726
L = []
1827

1928
while tokens[0] != ')':
20-
L.append(parse(tokens))
29+
L.append(parse(tokens, inquote, quotetype))
2130
tokens.pop(0)
2231
return L
2332
else:

0 commit comments

Comments
 (0)