2017 © Pedro Peláez
 

library gold-parser

Golder parser PHP runtime LALR engine and compiled grammar loader

image

tmilos/gold-parser

Golder parser PHP runtime LALR engine and compiled grammar loader

  • Wednesday, December 21, 2016
  • by tmilos
  • Repository
  • 1 Watchers
  • 2 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Gold Parser

Gold parser PHP runtime LALR engine and compiled grammar loader. For more information check Gold Parser website. Library is written based on the Calitha C# GOLD Parser Engine., (*1)

Author Build Status Coverage Status License, (*2)

Installation

You can use Composer to install, (*3)

$ composer require tmilos/gold-parser

Usage

Use Loader class to load compiled grammar file, and it's createNewParser() to get the LALR parser for that grammar., (*4)

<?php
$parser = Loader::fromFile('grammar.cgt')->createNewParser();
$nonTerminal = $parser->parse($inputString);
$parser->isAccepted(); // true

Events

The Parser instance has a default event listener, which you could replace. During parsing it dispatches various events. In the Events class are enumerated all events that are dispatched., (*5)

Event name constant Event name Event class Description
Events::PARSE_ERROR gp.parse_error ParseErrorEvent Parsing error
Events::TOKEN_ERROR gp.token_error TokenErrorEvent Unexpected token encountered error
Events::TOKEN_READ gp.token_read TokenReadEvent Next token has been read
Events::SHIFT gp.shift ShiftEvent Parser shifted
Events::REDUCE gp.reduce ReduceEvent Parser reduced
Events::ACCEPT gp.accept AcceptEvent Parser got into accept state
Events::GOTO_EVENT gp.goto GotoEvent Parser state changed with goto

Errors

By default the parser adds error listeners that will throw exceptions when error events are dispatched. You can add your own listeners for the error events and disable those default listeners with Parser::setThrowExceptionsOnErrors(false), (*6)

Default error handlers will throw ParseException on PARSE_ERROR event, and TokenException on TOKEN_ERROR event., (*7)

Performance

On my modest laptop with PHP 7.0 it takes around 0.2 seconds to load grammar and create parser, and around 0.04 seconds to parse ~700 chars json. Feel free to contribute and improve performance. Think the loading is critical., (*8)

The Versions

21/12 2016

dev-master

9999999-dev

Golder parser PHP runtime LALR engine and compiled grammar loader

  Sources   Download

MIT

The Requires

 

The Development Requires

gold parser lalr parser compiled grammar

21/12 2016

1.0.2

1.0.2.0

Golder parser PHP runtime LALR engine and compiled grammar loader

  Sources   Download

MIT

The Requires

 

The Development Requires

gold parser lalr parser compiled grammar

21/12 2016

1.0.1

1.0.1.0

Golder parser PHP runtime LALR engine and compiled grammar loader

  Sources   Download

MIT

The Requires

 

The Development Requires

gold parser lalr parser compiled grammar

20/12 2016

1.0.0

1.0.0.0

Golder parser PHP runtime LALR engine and compiled grammar loader

  Sources   Download

MIT

The Requires

 

The Development Requires

gold parser lalr parser compiled grammar