ion7-grammar / from.regex

module

from.regex

local regex_m = require "ion7.grammar.from.regex"
local gbnf = regex_m.to_gbnf("\\d{4}-\\d{2}-\\d{2}", "date")
-- date ::= [0-9]{4} "-" [0-9]{2} "-" [0-9]{2}

Functions

merge_literals

Merge runs of adjacent `literal` nodes into a single literal so that `abc` compiles to `"abc"` rather than `"a" "b" "c"`. Empty literals (which surface only when an anchor is consumed) are dropped.

merge_literals(items)

seq_from_items

Build a seq / single-item / empty AST from a captured items list.

seq_from_items(items)

apply_quant

Wrap with the requested quantifier (or pass through when nil).

apply_quant(node, quant)

build_escape

Single-char escape outside of a char class.

build_escape(c)

to_ast

Convert a regex string to an AST node.

to_ast(pattern)
patternstringERE/PCRE subset regex pattern.
→ nodeAST node representing the pattern.

to_gbnf

Convert a regex pattern directly to a single-rule GBNF string.

to_gbnf(pattern, name)
patternstringERE/PCRE subset regex pattern.
namestring?Root rule name (default: "root").
→ stringGBNF string.