public function __construct()
 {
     $this->ws = new Ignore(new Many(new WhitespaceParser(1), '(/\\*\\*|\\*/|\\*)'));
     $this->ident = '[a-zA-Z_][a-zA-Z0-9_]*';
     $this->string = new StringLiteral();
     $this->float = new FloatLiteral();
     $this->int = new IntLiteral();
     $this->const = new ClosureWithResult(new Sequence($this->ident, new OptionalChoice(new Sequence('::', $this->ident))), function (Result $result, Input $input) {
         $data = $result->data;
         $line = $input->getLine($result->offset);
         if ($data[1]) {
             return new ConstLookup($data[1][1], $data[0], $line);
         }
         return new ConstLookup($data[0], null, $line);
     });
     $this->type = new Choice($this->string, $this->float, $this->int, $this->const, new RegexParser('true', 'i'), new RegexParser('false', 'i'), new RegexParser('null', 'i'));
     $this->arguments = new Closure(new RepSep(new Sequence($this->ws, new OptionalChoice(new Sequence($this->ident, $this->ws, '=', $this->ws)), $this->type, $this->ws)), function ($data) {
         $arguments = [];
         foreach ($data as $datum) {
             if ($datum[0]) {
                 $arguments[$datum[0][0]] = $datum[1];
             } else {
                 $arguments['value'] = $datum[1];
             }
         }
         return $arguments;
     });
     $this->array = new Closure(new Sequence(new Ignore('{'), new RepSep(new Sequence($this->ws, new OptionalChoice(new Sequence($this->string, $this->ws, '=', $this->ws)), $this->type, $this->ws)), new Ignore('}')), function ($data) {
         $result = [];
         foreach ($data[0] as $datum) {
             if ($datum[0]) {
                 $result[$datum[0][0]] = $datum[1];
             } else {
                 $result[] = $datum[1];
             }
         }
         return $result;
     });
     $this->type->append($this->array);
     $this->doctrine_annotation = new ClosureWithResult(new Sequence(new Ignore('@'), $this->ident, $this->ws, new OptionalChoice(new Sequence(new Ignore('('), PositiveMatch::instance(), $this->arguments, new Ignore(')')))), function (Result $result, Input $input) {
         $data = $result->data;
         $arguments = $data[1][0] ? $data[1][0] : [];
         return new DoctrineAnnotation($data[0], $arguments, $input->getLine($result->offset));
     });
     $this->type->append($this->doctrine_annotation);
     $this->non_doctrine_annotations = new ClosureWithResult(new Sequence('@', '[a-z][a-zA-Z0-9_\\[\\]]*', $this->ws, new RegexParser('[^@]*', 'ms')), function (Result $result, Input $input) {
         $value = str_replace('*/', '', $result->data[2]);
         $value = str_replace('*', '', $value);
         return new NonDoctrineAnnotation($result->data[1], trim($value), $input->getLine($result->offset));
     });
     $this->comment = '[^@].*';
     $this->root = new Closure(new Sequence($this->ws, new Many(new Sequence(new Choice($this->non_doctrine_annotations, $this->doctrine_annotation, $this->comment), $this->ws))), function ($data) {
         return array_map(function ($value) {
             return $value[0];
         }, $data[0]);
     });
 }
Esempio n. 2
0
 public function __construct()
 {
     $this->root = new Closure(new Sequence('"', PositiveMatch::instance(), new Concatenate(new Many('[^\\n\\r\\f"\\\\]+', '\\\\[bnrf"\\\\]')), '"'), function ($data) {
         $str = str_replace('\\"', '"', $data[1]);
         return preg_replace_callback('/\\\\([\\\\a-zA-Z0-9])/', function ($matches) {
             // TODO: There must be a better way to do this...
             return eval("return \"\\{$matches['1']}\";");
         }, $str);
     });
 }
Esempio n. 3
0
 public function __construct($octal = true, $hex = true)
 {
     // Order here is important, if hex fails to match try oct, otherwise its an int.
     $this->root = new Choice();
     if ($hex) {
         $octInt = new Closure(new Concatenate(new Sequence([new Ignore('0'), '[0-7]', PositiveMatch::instance(), '[0-7]*'])), function ($data) {
             return octdec($data);
         });
         $this->root->append($octInt);
     }
     if ($hex) {
         $hexInt = new Closure(new Concatenate(new Sequence(new Ignore('0'), new Ignore('[xX]'), PositiveMatch::instance(), '[A-Fa-f0-9]+')), function ($data) {
             return hexdec($data);
         });
         $this->root->append($hexInt);
     }
     $decInt = new Closure('-?[0-9]+', function ($data) {
         return (int) $data;
     });
     $this->root->append($decInt);
 }
 public function __construct()
 {
     $this->root = new Closure(new Choice(new Sequence('"', PositiveMatch::instance(), new Concatenate(new Many('[^\\n\\r\\f"\\\\]+', '\\\\[nrf"]')), '"'), new Sequence("'", PositiveMatch::instance(), new Concatenate(new Many("[^\n\r\f'\\\\]+", "\\\\[nrf']")), "'")), function ($data) {
         return $data[1];
     });
 }