Last active
December 16, 2015 19:29
-
-
Save stephpy/5485023 to your computer and use it in GitHub Desktop.
rule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"php": ">=5.3.2", | |
"hoa/compiler": "master" | |
}, | |
"autoload": { | |
"psr-0": { | |
"Rulez": "src/" | |
} | |
}, | |
"minimum-stability": "dev" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%skip space \s | |
// Scalars. | |
%token true true|TRUE | |
%token false false|FALSE | |
%token null null|NULL | |
// Strings. | |
%token string ("|')(.*?)(?<!\\)\1 | |
%token number \d+ | |
%token bracket_ \( | |
%token _bracket \) | |
// Comparator | |
%token isNot (is not|IS NOT) | |
%token is (is|IS) | |
%token and AND | |
%token nand NAND | |
%token or OR | |
%token nor NOR | |
%token xor XOR | |
%token xnor XNOR | |
%token operator [^\s]+ | |
expression: | |
condition() | |
( (::and:: #and | ::nand:: #nand | ::or:: #or | ::nor:: #nor | ::xor:: #xor | ::xnor:: #xnor) expression())? | |
#condition: | |
(::bracket_:: expression() ::_bracket::) | |
| string() operator() value() | |
string: | |
<string> | |
number: | |
<number> | |
operator: | |
<operator> | <is> | <isNot> | |
value: | |
<true> | <false> | <null> | string() | number() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require "vendor/autoload.php"; | |
from('Hoa') | |
->import('Compiler.Llk') | |
->import('File.Read') | |
->import('Compiler.Visitor.Dump') | |
; | |
$compiler = \Hoa\Compiler\Llk::load( | |
new \Hoa\File\Read('Rulez.pp') | |
); | |
$str = '("1" != "toto \"é oajdaa" AND "1" > 20) OR "toto" > 10 XOR "tata" IS NOT NULL AND "tata" cu TRUE'; | |
$ast = $compiler->parse($str); | |
$dump = new Hoa\Compiler\Visitor\Dump(); | |
echo $dump->visit($ast); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment