Download the PHP package phug/reader without Composer

On this page you can find all versions of the php package phug/reader. 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 reader

Phug Reader

What is Phug Reader?

The Reader-class is a small utility that can parse and scan strings for specific entities.

It's mostly based on Regular Expressions, but also brings in tools to scan strings and expressions of any kind (e.g. string escaping, bracket counting etc.)

The string passed to the reader is swallowed byte by byte through consume-mechanisms. When the string is empty, the parsing is done (usually).

This class is specifically made for lexical analysis and expression-validation.

Installation

Install via Composer

Usage

Basics

The process of reading with the Phug\Reader involves peeking and consuming. You peek, check, if it's what you wanted and if it is, you consume.

read-methods on the Reader will peek and consume automatically until they found what you searched for. match-methods work like peek, but work with regular expressions.

Lets create a small example code to parse:

Now we create a reader for that code

If you want a fixed encoding, use the second $encoding parameter.

Now we can do our reading process. First we want to read our identifier. We can do that easily with readIdentifier() which returns null if no identifier has been encountered and the identifier found otherwise. It will stop on anything that is not an identifier-character (The space after the identifier, in this case)

To get to our =-character directly, we can just skip all spaces we encounter. This also allows for any spacing you want (e.g. you can indent the above with tabs if you like)

If we need the spaces, we can always catch the returned result. If no spaces are encountered, it just returns null.

Now we want to parse the assignment-operator (=) (or rather, validate that it's there)

Skip spaces again

and read the string. If no quote-character (" or ') is encountered, it will return null. Otherwise, it will return the (already parsed) string, without quotes. Notice that you have to check null explicitly, since we could also have an empty string ("") which evaluates to true in PHP

The quote-style encountered will be escaped by default, so you can scan "some \" string" correctly. If you want to add other escaping, use the first parameter of readString.

Now you have all parts parsed to make up your actual action

and it was validated on that way.

This was just a small example, Phug Reader is made for loop-parsing.

Build a small tokenizer

Keep expressions intact

Sometimes you want to keep expressions intact, e.g. when you allow inclusion of third-party-code that needs to be parsed separately.

The Reader brings a bracket-counting-utility that can do just that exactly. Let's take Jade as an example:

To parse this, let's do the following:

You now got a parser for (really, really basic) Jade-elements! It can handle as many attributes as you like with all possible values you could think of without ever breaking the listing, regardless of contained commas and brackets.

Digging deeper, the Phug Reader is actually able to lex source code and text of any kind.


All versions of reader with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.0
symfony/polyfill-mbstring Version *
psr/http-message Version ^1.0
phug/util Version ^0.3.5 || ^1.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 phug/reader contains the following files

Loading the files please wait ....