forked from Anastasiya-Potseluico/evol-git
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lexical_pattern.php
123 lines (106 loc) · 3.16 KB
/
lexical_pattern.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
// This file is part of CorrectWriting question type - https://code.google.com/p/oasychev-moodle-plugins/
//
// CorrectWriting question type is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// CorrectWriting is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with CorrectWriting. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines patterns class for lexer.
*
* @package qtype
* @subpackage correctwriting
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
/**
* Class for lexer patterns.
*
* Class for storing patterns.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class qtype_correctwriting_lexer_pattern {
/**
* Pattern name.
* @var string
*/
private $name;
/**
* Pattern regexp.
* @var string
*/
private $regexp;
/**
* Active condition. If lexer current condition == $activecondition then this
* pattern can be used. Initial value: "DEFAULT".
* @var string
*/
private $activecondition;
/**
* Next condition. Condition in which lexer will get after using this
* pattern.
* @var string
*/
private $nextcondition;
/**
* Pattern actions.
* @var string
*/
private $actions;
/**
* Basic pattern constructor.
*
* @param string $name - pattern name
* @param string $regexp - pattern regexp
* @param string $activecondition - active condition
* @param string $nextcondition - next condition
*/
public function __construct($name,
$regexp,
$actions,
$activecondition = 'DEFAULT',
$nextcondition = null) {
if (strlen($name) == 0 or strlen($regexp) == 0) {
throw new Exception('Pattern constructor: empty name or regexp');
} else {
$this->name = $name;
$this->regexp = $regexp;
}
$this->activecondition = $activecondition;
$this->nextcondition = $nextcondition;
$this->actions = $actions;
// TODO: check and add /^( )/ to regexp
}
/**
* Parse pattern action string.
*/
public function parse_actions() {
// TODO: parse action string
}
/**
* This function gets actionstring and "execute" it.
*/
public function execute_actions() {
// TODO: eval action string
}
public function name() {
return $this->name;
}
}
class qtype_correctwriting_lexer_action {
private $type;
private $errorstr;
public function __construct($type, $errorstr = null) {
$this->$type = $type;
$this->errorstr = $errorstr;
}
}
?>