5
5
* http://sourceforge.net/projects/lamplib
6
6
* This project is administered by Markus Baker, Harry Fuecks and Matt
7
7
* Mitchell, and the project code is in the public domain.
8
- *
8
+ *
9
9
* Thanks, guys!
10
10
*
11
11
* @package moodlecore
23
23
define ("LEXER_EXIT " , 4 );
24
24
/** LEXER_SPECIAL = 5 */
25
25
define ("LEXER_SPECIAL " , 5 );
26
-
26
+
27
27
/**
28
28
* Compounded regular expression. Any of
29
29
* the contained patterns could match and
@@ -37,7 +37,7 @@ class ParallelRegex {
37
37
var $ _labels ;
38
38
var $ _regex ;
39
39
var $ _case ;
40
-
40
+
41
41
/**
42
42
* Constructor. Starts with no patterns.
43
43
* @param bool $case True for case sensitive, false
@@ -75,7 +75,7 @@ function addPattern($pattern, $label = true) {
75
75
$ this ->_labels [$ count ] = $ label ;
76
76
$ this ->_regex = null ;
77
77
}
78
-
78
+
79
79
/**
80
80
* Attempts to match all patterns at once against
81
81
* a string.
@@ -101,7 +101,7 @@ function match($subject, &$match) {
101
101
}
102
102
return true ;
103
103
}
104
-
104
+
105
105
/**
106
106
* Compounds the patterns into a single
107
107
* regular expression separated with the
@@ -121,7 +121,7 @@ function _getCompoundedRegex() {
121
121
}
122
122
return $ this ->_regex ;
123
123
}
124
-
124
+
125
125
/**
126
126
* Accessor for perl regex mode flags to use.
127
127
* @return string Flags as string.
@@ -131,7 +131,7 @@ function _getPerlMatchingFlags() {
131
131
return ($ this ->_case ? "msS " : "msSi " );
132
132
}
133
133
}
134
-
134
+
135
135
/**
136
136
* States for a stack machine.
137
137
*
@@ -141,7 +141,7 @@ function _getPerlMatchingFlags() {
141
141
*/
142
142
class StateStack {
143
143
var $ _stack ;
144
-
144
+
145
145
/**
146
146
* Constructor. Starts in named state.
147
147
* @param string $start Starting state name.
@@ -169,7 +169,7 @@ public function StateStack($start) {
169
169
function getCurrent () {
170
170
return $ this ->_stack [count ($ this ->_stack ) - 1 ];
171
171
}
172
-
172
+
173
173
/**
174
174
* Adds a state to the stack and sets it
175
175
* to be the current state.
@@ -179,7 +179,7 @@ function getCurrent() {
179
179
function enter ($ state ) {
180
180
array_push ($ this ->_stack , $ state );
181
181
}
182
-
182
+
183
183
/**
184
184
* Leaves the current state and reverts
185
185
* to the previous one.
@@ -195,7 +195,7 @@ function leave() {
195
195
return true ;
196
196
}
197
197
}
198
-
198
+
199
199
/**
200
200
* Accepts text and breaks it into tokens.
201
201
* Some optimisation to make the sure the
@@ -213,7 +213,7 @@ class Lexer {
213
213
var $ _mode ;
214
214
var $ _mode_handlers ;
215
215
var $ _case ;
216
-
216
+
217
217
/**
218
218
* Sets up the lexer in case insensitive matching
219
219
* by default.
@@ -240,7 +240,7 @@ public function Lexer(&$parser, $start = "accept", $case = false) {
240
240
debugging ('Use of class name as constructor is deprecated ' , DEBUG_DEVELOPER );
241
241
self ::__construct ($ parser , $ start , $ case );
242
242
}
243
-
243
+
244
244
/**
245
245
* Adds a token search pattern for a particular
246
246
* parsing mode. The pattern does not change the
@@ -258,7 +258,7 @@ function addPattern($pattern, $mode = "accept") {
258
258
}
259
259
$ this ->_regexes [$ mode ]->addPattern ($ pattern );
260
260
}
261
-
261
+
262
262
/**
263
263
* Adds a pattern that will enter a new parsing
264
264
* mode. Useful for entering parenthesis, strings,
@@ -278,7 +278,7 @@ function addEntryPattern($pattern, $mode, $new_mode) {
278
278
}
279
279
$ this ->_regexes [$ mode ]->addPattern ($ pattern , $ new_mode );
280
280
}
281
-
281
+
282
282
/**
283
283
* Adds a pattern that will exit the current mode
284
284
* and re-enter the previous one.
@@ -293,7 +293,7 @@ function addExitPattern($pattern, $mode) {
293
293
}
294
294
$ this ->_regexes [$ mode ]->addPattern ($ pattern , "__exit " );
295
295
}
296
-
296
+
297
297
/**
298
298
* Adds a pattern that has a special mode.
299
299
* Acts as an entry and exit pattern in one go.
@@ -311,7 +311,7 @@ function addSpecialPattern($pattern, $mode, $special) {
311
311
}
312
312
$ this ->_regexes [$ mode ]->addPattern ($ pattern , "_ $ special " );
313
313
}
314
-
314
+
315
315
/**
316
316
* Adds a mapping from a mode to another handler.
317
317
* @param string $mode Mode to be remapped.
@@ -321,7 +321,7 @@ function addSpecialPattern($pattern, $mode, $special) {
321
321
function mapHandler ($ mode , $ handler ) {
322
322
$ this ->_mode_handlers [$ mode ] = $ handler ;
323
323
}
324
-
324
+
325
325
/**
326
326
* Splits the page text into tokens. Will fail
327
327
* if the handlers report an error or if no
@@ -352,7 +352,7 @@ function parse($raw) {
352
352
}
353
353
return $ this ->_invokeParser ($ raw , LEXER_UNMATCHED );
354
354
}
355
-
355
+
356
356
/**
357
357
* Sends the matched token and any leading unmatched
358
358
* text to the parser changing the lexer to a new
@@ -390,7 +390,7 @@ function _dispatchTokens($unmatched, $matched, $mode = false) {
390
390
}
391
391
return $ this ->_invokeParser ($ matched , LEXER_MATCHED );
392
392
}
393
-
393
+
394
394
/**
395
395
* Calls the parser method named after the current
396
396
* mode. Empty content will be ignored.
@@ -409,7 +409,7 @@ function _invokeParser($content, $is_match) {
409
409
}
410
410
return $ this ->_parser ->$ handler ($ content , $ is_match );
411
411
}
412
-
412
+
413
413
/**
414
414
* Tries to match a chunk of text and if successful
415
415
* removes the recognised chunk and any leading
0 commit comments