Yo! Writing here to see what you guys think about me making a peg parser in lua/roblox.
--[[
Example code: Takes name, and string and builds grammer profile
Potential PEG implementation
Possible pack-rat implementation also to run in linear time;
Similar to how boatbomber's lexer runs
]]
local parse = ...
parse:connect(lexer)
--Lexer connection; Wouldn't find tokens otherwise
parse.define("Sum", "@num@WS?('+'/'-')@num") --Anything inside '' will be used literally
parse.define("StringLiteral", "<@string> !Sum",{ --This object will tell the parser what to define the syntax token to include
- - Referencing other definitions use !; Escaping wouldn’t reference
value = "@1" --Some implementation of capture groups
})
--@lexer-token
--Second way
local parser = parse.init()--or parse.new()
parser.define("StringLiteral", "<@string>", {
value = "@1"
})
--Thinking something like this
local tree = parse:build(tokenStream) --or parser:build()
--^^Abstract Syntax Tree; Maybe just a parse tree and seperate function like
tree:abstract("unncessary tokens", "Example: !StringLiteral")
--To create an abstract tree from it, Tree would then throw away any string literal tokens from the tree
I’m writing here to ask if I should take the time to make this (99% will) or maybe someone would find this useful. I’ve also written a lexer which is currently in the stages of optimization and such but yeah, let me know.
Would you find this useful?
- Yes
- No
0 voters