-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArg.php
More file actions
88 lines (70 loc) · 2.29 KB
/
Copy pathArg.php
File metadata and controls
88 lines (70 loc) · 2.29 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
abstract class Arg {
protected static $pattern;
function __construct($arg){
$this->arg = $arg;
}
public function checkSyntax(){
global $xml;
if (!preg_match(static::$pattern, $this->arg)){
// echo $this->arg;
// echo static::$pattern."\n"; // REMOVE
// echo "> TU SA TO POKAZILO"; // REMOVE
exit(23);
}
return $this;
}
abstract public function printXML($n);
}
class Variable extends Arg {
protected static $pattern = "/^(G|L|T)F@[A-Za-z_\-$&%*!?][A-Za-z_\-$&%*!?0-9]*$/";
public function printXML($n){
global $xml;
$xml->startElement('arg'.$n);
$xml->writeAttribute('type', "var");
$xml->text($this->arg);
$xml->endElement();
}
}
class Symbol extends Arg {
protected static $pattern = "/^((G|L|T)F@[A-Za-z_\-$&%*!?][A-Za-z_\-$&%*!?0-9]*|int@[\-+]?([0-9]+|0x[A-Fa-f0-9]+)|bool@(true|false)|nil@nil|string@([^\\\\\s#]|\\\\\d{3})*)$/";
private static function _parseArg($str){
$parts = explode("@", $str);
switch ($parts[0]){
case 'int': case "bool": case "string": case "nil":
return $parts;
case "GF": case "LF": case "TF":
return ["var", $str];
}
}
public function printXML($n){
global $xml;
$xml->startElement('arg'.$n);
$parts = $this->_parseArg($this->arg);
$xml->writeAttribute('type', $parts[0]);
$xml->text($parts[1]);
$xml->endElement();
}
}
class Label extends Arg {
protected static $pattern = "/^[A-Za-z_\-$&%*!?][A-Za-z_\-$&%*!?0-9]*$/";
public function printXML($n){
global $xml;
$xml->startElement('arg'.$n);
$xml->writeAttribute('type', 'label');
$xml->text($this->arg);
$xml->endElement();
}
}
class Type extends Arg {
protected static $pattern = "/^(int|string|bool)$/";
public function printXML($n){
global $xml;
$xml->startElement('arg'.$n);
$xml->writeAttribute('type', 'type');
// preg_replace(["/</", "/>/", "/&/"], ["<", ">", "&"], $this->line); // TODO
$xml->text($this->arg);
$xml->endElement();
}
}
?>