定制 edin/lexicon-syntax 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

edin/lexicon-syntax

最新稳定版本:v0.1.5

Composer 安装命令:

composer require edin/lexicon-syntax

包简介

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

README 文档

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

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固