2017 © Pedro Peláez
 

library parser

helper to write parser with php

image

face/parser

helper to write parser with php

  • Friday, December 4, 2015
  • by sneakyBobito
  • Repository
  • 1 Watchers
  • 0 Stars
  • 45 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Face Parser

Latest Stable Version Build Status Test Coverage, (*1)

Tool to help to create a parser with php. Originally built to parse FQL queries but might be used for anything else., (*2)

Usage

    use Face\Parser\RegexpLexer as Lexer;
    use Face\Parser\TokenNavigation;

    $lexer = new Lexer();

    $lexer->setTokens([

        "function"                  => "T_FUNCTION",
        "class"                     => "T_CLASS",
        "[a-zA-Z_][a-zA-Z0-9_]*"    => "T_IDENTIFIER",
        "\\{"                       => "T_L_BRACKET",
        "\\}"                       => "T_R_BRACKET",
        "\\("                       => "T_L_PARENTHESIS",
        "\\)"                       => "T_R_PARENTHESIS",
        ";"                         => "T_SEMICOLON",
        "\\s+"                      => "T_WHITESPACE"

    ]);

    $string = 'class foo{
        function bar(){}
    }';

    $tokenArray = $lexer->tokenize($string);

    $tokens = new TokenNavigation($tokenArray);

    // Check if the first token is a "class" keyword or throws an exception
    $tokens->expectToBe("T_CLASS");

    $tokens->next();
    $tokens->expectToBe("T_IDENTIFIER");

    $className = $tokens->current()->getTokenValue();

    // while next token is a function keyword
    while($tokens->hasNext() && $tokens->look(1)->is("T_FUNCTION")){
        // Parse the function body
        someFunctionThatParsesTheFunctionAndJumpsToTheNextToken($tokens);
    }

The Versions

04/12 2015

dev-master

9999999-dev https://github.com/face-orm/face-parser

helper to write parser with php

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

parser lexer compiler