~ubuntu-branches/ubuntu/vivid/phabricator/vivid-proposed

« back to all changes in this revision

Viewing changes to libphutil/support/parser/generate-type-parser.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-10-23 20:49:26 UTC
  • mfrom: (0.2.1) (0.1.1)
  • Revision ID: package-import@ubuntu.com-20141023204926-vq80u1op4df44azb
Tags: 0~git20141023-1
Initial release (closes: #703046)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env php
 
2
<?php
 
3
 
 
4
require_once dirname(__FILE__).'/../../scripts/__init_script__.php';
 
5
 
 
6
$terminals = array(
 
7
  '|',
 
8
  '<',
 
9
  '>',
 
10
  '(',
 
11
  ')',
 
12
  ',',
 
13
  'k',
 
14
  'map',
 
15
  'list',
 
16
  '?',
 
17
  'opt',
 
18
  'cm',
 
19
);
 
20
 
 
21
$rules = array(
 
22
  'start' => 'maybe_optional',
 
23
  'maybe_optional' => array(
 
24
    'yes' => 'opt maybe_comment',
 
25
    'no' => 'maybe_comment',
 
26
  ),
 
27
  'maybe_comment' => array(
 
28
    'yes' => 'type comment',
 
29
    'no' => 'type',
 
30
  ),
 
31
  'comment' => '( comment_text )',
 
32
  'comment_text' => array(
 
33
    'comment_text cm',
 
34
    'cm',
 
35
  ),
 
36
  'type' => array(
 
37
    'yes' => 'some_type ?',
 
38
    'no' => 'some_type',
 
39
  ),
 
40
  'some_type' => array(
 
41
    'or_type',
 
42
    'not_or_type',
 
43
  ),
 
44
  'or_type' => array(
 
45
    'or_type | not_or_type',
 
46
    'not_or_type | not_or_type',
 
47
  ),
 
48
  'not_or_type' => array(
 
49
    'basic_type',
 
50
    'map_type',
 
51
    'list_type',
 
52
  ),
 
53
  'basic_type' => array(
 
54
    'k',
 
55
  ),
 
56
  'map_type' => array(
 
57
    'map < type , type >',
 
58
  ),
 
59
  'list_type' => array(
 
60
    'list < type >',
 
61
  ),
 
62
);
 
63
 
 
64
$parser = id(new PhutilParserGenerator())
 
65
  ->setTerminals($terminals)
 
66
  ->setRules($rules)
 
67
  ->processGrammar();
 
68
 
 
69
echo $parser->generateParserFunction('phutil_type_spec_parser')."\n";