Lux - a powerful parser generator for Luau

lux

What is Lux?

Lux is an open source parser generator for Luau. It takes LBNF grammar and return a parser.

How to use it?

Lux is an easy to use string parsing tool. You can get it on Roblox Creator Marketplace or test it in Lux Lab. After installation you can require and use it:

local Lux = require(script.Lux)
local parser = Lux.generateParser([[ -- Generate grammar & parser
name = "%u%l+"; -- One uppercase letter and lowercase letters
greetings = "Hello," name; -- "Hello," and name
!text = { greetings }; -- Root rule: any greetings.
]])
local tree = parser:parse("Hello, Bob")
Lux.show(tree)

The source code is available on GitHub.

19 Likes

Well, this is a level I never thought about when writing my own interpreter, now I feel dumb for manually parsing the significant tokens.

Yeah, well done, this is an amazing resource!

1 Like

Thank you! I hope Lux will help you in creating your interpreter!

lab

Lux Lab is now available! You can test your grammar and experiment with Lux in this experience.

Could you better explain what this does…? It doesn’t seem easy to use either:

This is LBNF. Visit this page to get more information: Grammar - Lux

I’m stuck. I can’t solve recursion problem and I can’t update this module to fix the bugs. Sorry, I don’t know what to do. You shouldn’t use it until I find a solution. If someone know how to improve this module, please DM me.

Hello! I’m so happy! I found the solution and soon wil release Lux update with bug fixes. Also I have to warn that I will not update the Lux for 2 weeks as I’m away from my computer.

1 Like

Lux is updated!

New features:

  • Repeation count specification: { … }<min…max> ({ … } = { … }<0…inf>)

Removed:

  • Indents. It’s confusing to have a lot of * and > in your grammar. So now parser will skip indents automatically.

Bug fixes:

  • Or chain recursion.
2 Likes

This doesn’t work because each rule definition needs to end in a semi-colon (;).

This would work:

local Lux = require(script.Lux)
local parser = Lux.generateParser([[ -- Generate grammar & parser
name = "%u%l+"; -- One uppercase letter and lowercase letters
greetings = "Hello," name; -- "Hello," and name
!text = { greetings }; -- Root rule: any greetings.
]])
local tree = parser:parse("Hello, Bob")
Lux.show(tree)

I think it should also be noted that some string patterns can cause an infinite recursion to occur within the module (I found this out while messing around with it)

1 Like

Can you provide some examples, please? I stopped updating Lux, but maybe one day I’ll fix this issue.

I can’t quite reproduce the problem at the moment since I was just writing random string patterns and don’t remember the problematic ones in particular.

However, I did discover another infinite recursion while trying to recreate the string pattern one:

letter = "%a";
digit = "%d";

iden = { letter } [ iden | digit | '_' ];

!text = { iden };

Looking at this, I guess it would make sense this would infinitely recurse

Hello! Does anyone want a remake of Lux? I upgraded my skills in development, so I think I could do better, but I don’t know if anyone needs this.

1 Like

I sincerely think it’s a good idea, specially seeing what people are doing with the roblox engine right now.

One thing I would ask for is proper error handling, when you’re creating a language it is essential to tell where the error has come from, but the library just says that it expected EOF instead of the actual error.

Thank you for your suggestion! I decided to take a break from Roblox developing. I don’t know when I will be back. Sorry and have a great day!

1 Like

No problem, I really hope you rework this project, its quite unique for roblox.

Hi, I was actually just planning on making something quite similar and am going to make a parser that uses LALR(1). Don’t know how long it will take but i thought it would be a fun side project to experiment with. I’m also going to add a configurable syntax highlighter which allows you to mess with token highlighting using the richtext feature in textlabels.

1 Like

That would be great! Does it gonna use EBNF? I miss Exceptions.
(Edit: Forgot LALR is a different thing)