Skip to content

Commit ab41e43

Browse files
committed
Make Lexer return the null terminator character if there's no characters left in peek and consume functions
1 parent 97af158 commit ab41e43

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Lexer/Lexer.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ local function Lexer(expression, operators, charPos)
5555
local errors = {}
5656
local charStream, curChar, curCharPos
5757
if expression then
58-
expression = expression .. "\0"
58+
expression = expression
5959
charStream = stringToTable(expression)
6060
curChar = charStream[charPos or 1]
6161
curCharPos = charPos or 1
@@ -70,15 +70,15 @@ local function Lexer(expression, operators, charPos)
7070
--- Gets the next character from the character stream.
7171
-- @return <String> char The next character.
7272
local function peek()
73-
return charStream[curCharPos + 1]
73+
return charStream[curCharPos + 1] or "\0"
7474
end
7575

7676
--- Consumes the next character from the character stream.
7777
-- @param <Number?> n=1 The amount of characters to go ahead.
7878
-- @return <String> char The next character.
7979
local function consume(n)
8080
local newCurCharPos = curCharPos + (n or 1)
81-
local newCurChar = charStream[newCurCharPos]
81+
local newCurChar = charStream[newCurCharPos] or "\0"
8282
curCharPos = newCurCharPos
8383
curChar = newCurChar
8484
return newCurChar
@@ -309,7 +309,7 @@ local function Lexer(expression, operators, charPos)
309309
local function resetToInitialState(expression, givenOperators)
310310
-- If charStream is a string convert it to a table of characters
311311
if expression then
312-
expression = expression .. "\0"
312+
expression = expression
313313
charStream = stringToTableCache[expression] or stringToTable(expression)
314314
curChar = charStream[1]
315315
curCharPos = 1

0 commit comments

Comments
 (0)