-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp5.php
55 lines (46 loc) · 1.62 KB
/
p5.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
use SyntaxAnalyzer\Analyzer;
require_once __DIR__ . '/testhelpers.php';
//create(field aaaa,field bbb,)
$words = [
['type' => 'key', 'value' => 'CREATE'],
['type' => 'symbol', 'value' => '('],
['type' => 'key', 'value' => 'FIELD'],
['type' => 'string', 'value' => 'aaaa'],
['type' => 'symbol', 'value' => ','],
['type' => 'key', 'value' => 'FIELD'],
['type' => 'string', 'value' => 'ccc'],
['type' => 'symbol', 'value' => ','],
['type' => 'key', 'value' => 'FIELD'],
['type' => 'string', 'value' => 'bbb'],
// ['type' => 'symbol', 'value' => ','],
['type' => 'symbol', 'value' => ')'],
];
$rules = [
'create' => [
'matches' => [
['r' => '/CREATE/', 'type' => 'key', 'n' => [1, 1], 'name' => 'key_create'],
['r' => '/\(/', 'type' => 'symbol', 'n' => [1, 1], 'name' => 'symbol'],
['r' => 'create_content', 'type' => 'call', 'n' => [1, PHP_INT_MAX], 'name' => 'fields'],
['r' => '/\)/', 'type' => 'symbol', 'n' => [1, 1], 'name' => 'symbol'],
],
'n' => [1, PHP_INT_MAX],
'name'=>'create',
],
'create_content' => [
'matches' => [
['r' => '/FIELD/', 'type' => 'key', 'n' => [1, 1], 'name' => 'field'],
['r' => '/.*/', 'type' => 'string', 'n' => [1, 1], 'name' => 'field'],
['r' => '/\,/', 'type' => 'symbol', 'n' => [0, 1], 'name' => 'symbol'],
],
'n' => [1, PHP_INT_MAX],
'name'=>'create_content',
]
];
$g = new Analyzer($rules);
$g->setWords($words);
$i = 0;
$r = $g->matchOne($rules['create'], $rs, $i);
print_r($rs);
//$g->showLog();
//