lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi List,
This is an announcement that I've put a project called DSL on github
[1].  Here's the description from the README:

DSL is a language generator. Given a set of token patterns and grammar
rules describing a language, DSL will generate a parser. DSL is based
on LPEG (Lua Parsing Expression Grammars), so tokens and rules are
described in LPEG syntax. DSL extends LPEG by adding functionality
useful for writing custom languages such as diagnostic tools, error
handling, and some new primitives that can be used for writing
patterns.

DSL features
* parsing event callbacks (token try, token match, rule try, rule
match, rule end, comment try, comment match)
* error annotations on grammar rule patterns for throwing syntactical errors
* auto-generation of expression operators such as *, /, +, etc.
* automatic whitespace handling
* one-pass parsing of input string
* new Token primitive 'T' as an extension of the LPEG 'P' pattern for
writing grammar rules



DSL is the successor to my codepeg project.  It's so entirely
different in design that it made more sense to kill that project and
start a new one than to continue it.  It's much simpler than codepeg
and can produce DSLs with a minimum of input.  I've tried my best not
to make any assumptions about language design like what kinds of
characters will go in language tokens.  That said, whitespace is
ignored for now although it would be easy to fix that for whitespace
sensitive DSLs like templating languages.

Also, I've made some special features for languages that use infix
notation whereby operators and their precedence can be simply
specified.  For a simple example, here's a JSON parser defined in DSL.
 I make no claim to completeness, but simply provide it as an example
[2]


local dsl = DSL{
	tokens = [=[
		NUMBER = float+integer
		STRING = string
		TRUE = P"true"
		FALSE = P"false"
		NULL = P"null"
	]=],
	rules = [==[
		value = object + array + values
		entry = STRING * T":" * Assert(value, "entry.value")
		object = T"{" * (entry * (T"," * entry)^0)^-1  * Assert(T"}",
"object.RIGHT_BRACE")
		array = T"[" * (value * (T"," * value)^0)^-1 * Assert(T"]",
"array.RIGHT_BRACKET")
	]==],
	annotations = {
		-- value tokens
		NUMBER = { value=true },
		STRING = { value=true },
		TRUE = { value=true },
		FALSE = { value=true },
		NULL = { value=true },
		-- rule annotations
		value = { collapsable=true },
		values = { collapsable=true },
	},
}


For a more complete C-like language dealing with expressions and
function definitions, see the Expr example [3].

wes

[1] https://github.com/weshoke/DSL
[2] https://github.com/weshoke/DSL/blob/master/test/test.json.lua
[3] https://github.com/weshoke/DSL/blob/master/test/test.expr.lua