Compare commits

..

3 Commits

Author SHA1 Message Date
7889f4c27a Fix last token not getting tokenized 2024-01-15 21:28:40 +01:00
23269baa0b Make numbers in basic test distinct 2023-11-28 04:06:51 +01:00
d0357f0a3a Fix numbers being tokenized as names 2023-11-28 04:04:57 +01:00
3 changed files with 12 additions and 3 deletions

View File

@ -1496,7 +1496,7 @@ pub fn parse(tokens: []Token, allocator: *std.heap.ArenaAllocator) !ChunkNode
var i: usize = 0; var i: usize = 0;
const maybeParsedChunk = parseChunk(tokens, &i, allocator) catch |err| const maybeParsedChunk = parseChunk(tokens, &i, allocator) catch |err|
{ {
std.debug.print("{any}: data: {any}, type: {any}\n", .{tokens[i].region, tokens[i].tokenData, tokens[i].tokenType}); //std.debug.print("{any}: data: {any}, type: {any}\n", .{tokens[i].region, tokens[i].tokenData, tokens[i].tokenType});
return err; return err;
}; };
return maybeParsedChunk; return maybeParsedChunk;

View File

@ -225,7 +225,7 @@ fn tokenizeChar(state: *TokenizerState, ch: u8, lastIndex: *?usize, index: *usiz
} }
else if(std.ascii.isDigit(ch)) else if(std.ascii.isDigit(ch))
{ {
try tokenizeTerminalStr(lastIndex, index.*, tokenType, state, TokenType.Numeral, TokenizerState.Name, tokenStr, ch, region); try tokenizeTerminalIntNum(lastIndex, index.*, tokenType, state, TokenType.Numeral, TokenizerState.Number, tokenNumeral, ch, region);
} }
else else
{ {
@ -1218,6 +1218,15 @@ pub fn tokenize(fileContent: []u8, allocator: std.mem.Allocator) ![]Token
} }
index += 1; index += 1;
} }
if(longBracketLevel != 0)
{
return error.UnbalancedLongBracketLevel;
}
try tokenizeChar(&state, '\n', &lastIndex, &index, &tokenType, &tokenStr, &tokenNumeral, &tokens, &longBracketLevel, &region, allocator);
if(region.start != null and region.start.?.col == 0 and region.start.?.line == 0)
{
region.start = calculatePoint(fileContent, index);
}
return tokens.toOwnedSlice(); return tokens.toOwnedSlice();
} }

View File

@ -4,5 +4,5 @@ b = {["a"] = 23}
for i=0, 10 do b[i] = 2^23 end for i=0, 10 do b[i] = 2^23 end
print("asdf") print("asdf")
function test(a, b) function test(a, b)
return 12 + a / b return 42 + a / b
end end