Packrut.nut - parsing library for Squirrel

Introducing packrat.nut, the first general-purpose parsing library for Squirrel!

Regular expressions not enough? Define grammars in a readable and intuitive way, in your Squirrel code, either in a string or with a DSL.

This has been a passion-project for me, where I could:

  • tackle a difficult but common problem (parsing)
  • evaluate a range of interesting algorithms
  • implement an interesting algorithm, in a language where it hasn’t been before
  • use advanced features of the language (e.g. metamethods) in a novel way
  • contribute some new functionality to the Squirrel ecosystem

Memory usage is likely to be a limiting factor for real-world applications, however the example code shows that the library can be used to parse a JSON string of reasonable length and complexity (when run on the agent). I’ve not had reason to use it in another project myself yet, but I think it would have been useful in previous projects for parsing a subset of XML to deal with certain external APIs which would only respond with (reasonably small) XML documents.

2 Likes