edin/lexicon-syntax

BNF-style grammar parser, validator, and code generator for Lexicon-powered syntax tools.

Maintainers

Package info

github.com/edin/LexiconSyntax

pkg:composer/edin/lexicon-syntax

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.5 2026-06-10 12:36 UTC

This package is auto-updated.

Last update: 2026-06-10 12:47:14 UTC


README

Lexicon Syntax is a companion grammar parser and validator for the edin/lexicon package. It parses compact token and rule declarations into an AST, validates common grammar mistakes, and can pretty-print the grammar back into a normalized BNF-like format.

See docs/README.md for the language, CLI, generation, validation, and roadmap notes.

token Digit ::= '0' .. '9';
token Letter ::= 'a' .. 'z' | 'A' .. 'Z' | '_';
token Identifier ::= Letter (Letter | Digit)*;
token Number ::= Digit+;

rule Expression ::= Term ((Plus | Minus) Term)*;
rule Term ::= Factor ((Star | Slash) Factor)*;
rule Factor ::= Number | GroupedExpression;
rule GroupedExpression ::= OpenParen Expression CloseParen;
use LexiconSyntax\GrammarParser;
use LexiconSyntax\GrammarPrinter;
use LexiconSyntax\Validation\GrammarValidator;

$document = GrammarParser::parse($source);

echo GrammarPrinter::format($document);

$result = GrammarValidator::validate($document);
foreach ($result->diagnostics as $diagnostic) {
    echo $diagnostic->message, PHP_EOL;
}

CLI

Install the command globally with Composer:

composer global require edin/lexicon-syntax
lsyn help

Make sure Composer's global vendor/bin directory is on PATH. On Windows this is commonly:

%APPDATA%\Composer\vendor\bin

Create a C-like demo project in an empty directory:

lsyn init c-like
lsyn validate
lsyn generate
lsyn parse

Those commands read lexicon-syntax.json from the current project folder.

Useful inspection commands:

lsyn print
lsyn ast
lsyn parse

lsyn print pretty-prints the grammar, lsyn ast prints the grammar AST nodes, and lsyn parse generates the demo parser and prints the parsed C-like sample AST.

During development from source, run the binary directly:

composer install
php bin/lsyn help