Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Fixed up line counter stuff, now for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Arghnews committed Feb 14, 2017
1 parent 026f3f8 commit 5945242
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Binary file removed .baba.py.swp
Binary file not shown.
11 changes: 7 additions & 4 deletions baba.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ def tokenize(code):
if kind == "Newline":
line_start = mo.end()
line_number += 1
elif kind == "Empty" or kind == "Comment":
elif kind == "Comment":
line_number += 1
elif kind == "Empty":
pass
elif kind == 'Error':
raise RuntimeError('%r unexpected on line %d, could not interpret token' % (value, line_number))
Expand All @@ -138,15 +140,15 @@ def tokenize(code):
# strip [==[ from start of long string
num_square_brackets = 0
prefix_suffix = 0
for v in value:
if v == '\n':
line_number += 1
for v in value:
prefix_suffix += 1
if v == "[":
num_square_brackets += 1
if num_square_brackets == 2:
value = value[prefix_suffix:]
# strip newline if first char
if value[0] == '\n':
value = value[1:]
break

# strip ]==] from end of long string
Expand All @@ -155,6 +157,7 @@ def tokenize(code):
pass
elif kind == "Name" and value in keywords:
kind = "Keyword" # to convert keywords picked up as names to keywords

column = mo.start() - line_start
yield Token(kind, value, line_number, column)

Expand Down
8 changes: 7 additions & 1 deletion example.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
function main(argsv)
do
something.thing()
something[3].thing()
-- something
-- something
-- something
str = [==[
bla
balblabla]==]
local a = function(lambda_arg) end
b = function(lambda_arg2) end
end
Expand Down

0 comments on commit 5945242

Please sign in to comment.