Download the PHP package nielssp/parco without Composer

On this page you can find all versions of the php package nielssp/parco. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package parco

Parco – PHP parser combinators

Build Status Coverage Status Latest Stable Version

Parco is an experimental parser combinator library for PHP inspired by Scala Parser Combinators. See also Wikipedia for general information on parser combinators.

The API documentation is available on parco.nielssp.dk/api.

Install

Requirements:

Install using composer:

Usage

See the examples directory for some examples:

Writing a parser

To write a parser using Parco simply use one of the combinator traits in a class. There are currently three traits:

To implement a parser you may define multiple subparsers and combine them using combinators.

Each subparser is implemented as a parameterless method returning a Parser object. It usually makes sense to have a method for each production rule in your language grammar, so for a grammar such as:

our parser class may have the following structure:

You may also want to add a method for invoking the parser:

The parseAll method is provided by the RegexParsers trait. It converts the input string to a sequence of characters and makes sure that there is no leftover input after the given parser has been applied. Now we can use the parser by constructing and then invoking it:

If the parser fails, a ParseException is thrown. The "Error handling" section below explains how to handle parse errors.

Terminals

The follwing parsers can be used to parse one or more input sequence elements:

Additionally RegexParsers provides a method for parsing input sequence elements using regular expressions, e.g.:

The above parsers serve as the basic building blocks for constructing more advanced parsers. The following section shows how to combine them.

From grammar to code

Some basic combinators provided by Parsers:

If you want to parse a followed by b, but only want to keep the result of a, the method seqL can be used:

Similarily, seqR can be used to keep the result of b instead.

More combinators are described on the API documentation page.

Manipulating parser results

The abstract Parser class provides some methods for manipulating the result of a parser. The most important one is the map-method, which converts the result of a parser using a function, e.g.:

The above parser uses a regular expression to parse one or more digits, then converts the result to and integer.

Two other useful methods are:

Recursion

The Parsers trait provides a magic getter that converts parameterless parsers into lazy parsers. This can be used to implement recursive grammars such as the follwing:

To use this feature simply refererence your parser functions without parentheses (e.g. $this->expr instead of $this->expr()):

Left recursion

Some left-recursive grammars (e.g. left-associative operators) such as

can be implemented using the chainl-combinator:

The second parameter to chainl is a parser that parses the separator (i.e. the '-' terminal) and returns a function that combines parse result from left to right.

Thus the result of parsing 8 - 4 - 1 - 3 with the above parser is ((8 - 4) - 1) - 3 = 0.

A similar combinator, chainr, can be used for right-associative operators.

Error handling

The result of a parser includes information about the line number and column number. This can be used to produce helpful error messages.

An example of a parser error handler:

Which produces output such as:

Parco also has an exception class, ParseException, that can be used to wrap parse errors. It is thrown automatically when calling get() on an unsuccessful parser result.

License

Copyright (C) 2015 Niels Sonnich Poulsen (http://nielssp.dk)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


All versions of parco with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nielssp/parco contains the following files

Loading the files please wait ....