| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Parser for XML DocBook-based phpDocumentor tutorials
|
|
|
4 |
*
|
|
|
5 |
* phpDocumentor :: automatic documentation generator
|
|
|
6 |
*
|
|
|
7 |
* PHP versions 4 and 5
|
|
|
8 |
*
|
|
|
9 |
* Copyright (c) 2002-2007 Gregory Beaver
|
|
|
10 |
*
|
|
|
11 |
* LICENSE:
|
|
|
12 |
*
|
|
|
13 |
* This library is free software; you can redistribute it
|
|
|
14 |
* and/or modify it under the terms of the GNU Lesser General
|
|
|
15 |
* Public License as published by the Free Software Foundation;
|
|
|
16 |
* either version 2.1 of the License, or (at your option) any
|
|
|
17 |
* later version.
|
|
|
18 |
*
|
|
|
19 |
* This library is distributed in the hope that it will be useful,
|
|
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
22 |
* Lesser General Public License for more details.
|
|
|
23 |
*
|
|
|
24 |
* You should have received a copy of the GNU Lesser General Public
|
|
|
25 |
* License along with this library; if not, write to the Free Software
|
|
|
26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
27 |
*
|
|
|
28 |
* @category ToolsAndUtilities
|
|
|
29 |
* @package phpDocumentor
|
|
|
30 |
* @subpackage Parsers
|
|
|
31 |
* @author Gregory Beaver <cellog@php.net>
|
|
|
32 |
* @copyright 2002-2007 Gregory Beaver
|
|
|
33 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
34 |
* @version CVS: $Id: XMLpackagePageParser.inc 246143 2007-11-14 01:31:24Z ashnazg $
|
|
|
35 |
* @tutorial tutorials.pkg
|
|
|
36 |
* @link http://www.phpdoc.org
|
|
|
37 |
* @link http://pear.php.net/PhpDocumentor
|
|
|
38 |
* @since 1.2
|
|
|
39 |
* @todo CS cleanup - change package to PhpDocumentor
|
|
|
40 |
* @todo CS cleanup - PHPCS needs to ignore CVS Id length
|
|
|
41 |
*/
|
|
|
42 |
/**
|
|
|
43 |
* when <programlisting> is found
|
|
|
44 |
*/
|
|
|
45 |
define('PHPDOCUMENTOR_PDP_EVENT_PROGRAMLISTING', 600);
|
|
|
46 |
/**
|
|
|
47 |
* when <programlisting> is found
|
|
|
48 |
*/
|
|
|
49 |
define('PHPDOCUMENTOR_PDP_STATE_PROGRAMLISTING', 700);
|
|
|
50 |
/**
|
|
|
51 |
* when a DocBook <tag> is found
|
|
|
52 |
*/
|
|
|
53 |
define('PHPDOCUMENTOR_PDP_EVENT_TAG', 601);
|
|
|
54 |
/**
|
|
|
55 |
* when a DocBook <tag> is found
|
|
|
56 |
*/
|
|
|
57 |
define('PHPDOCUMENTOR_PDP_STATE_TAG', 701);
|
|
|
58 |
/**
|
|
|
59 |
* when <![CDATA[ ]]> is found
|
|
|
60 |
*/
|
|
|
61 |
define('PHPDOCUMENTOR_PDP_EVENT_CDATA', 602);
|
|
|
62 |
/**
|
|
|
63 |
* when <![CDATA[ ]]> is found
|
|
|
64 |
*/
|
|
|
65 |
define('PHPDOCUMENTOR_PDP_STATE_CDATA', 702);
|
|
|
66 |
/**
|
|
|
67 |
* when tag attributes name="value" are found
|
|
|
68 |
*/
|
|
|
69 |
define('PHPDOCUMENTOR_PDP_EVENT_ATTRIBUTES', 603);
|
|
|
70 |
/**
|
|
|
71 |
* when tag attributes name="value" are found
|
|
|
72 |
*/
|
|
|
73 |
define('PHPDOCUMENTOR_PDP_STATE_ATTRIBUTES', 703);
|
|
|
74 |
/**
|
|
|
75 |
* when tag attributes name="value" are found
|
|
|
76 |
*/
|
|
|
77 |
define('PHPDOCUMENTOR_PDP_EVENT_ENTITY', 604);
|
|
|
78 |
/**
|
|
|
79 |
* when tag attributes name="value" are found
|
|
|
80 |
*/
|
|
|
81 |
define('PHPDOCUMENTOR_PDP_STATE_ENTITY', 704);
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* Used to parse XML DocBook-based tutorials
|
|
|
85 |
*
|
|
|
86 |
* @category ToolsAndUtilities
|
|
|
87 |
* @package phpDocumentor
|
|
|
88 |
* @subpackage Parsers
|
|
|
89 |
* @author Gregory Beaver <cellog@php.net>
|
|
|
90 |
* @copyright 2002-2007 Gregory Beaver
|
|
|
91 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
92 |
* @version Release: 1.4.3
|
|
|
93 |
* @link http://www.phpdoc.org
|
|
|
94 |
* @link http://pear.php.net/PhpDocumentor
|
|
|
95 |
* @since 1.2
|
|
|
96 |
* @todo CS cleanup - change package to PhpDocumentor
|
|
|
97 |
*/
|
|
|
98 |
class XMLPackagePageParser extends Parser
|
|
|
99 |
{
|
|
|
100 |
/**
|
|
|
101 |
* @var array
|
|
|
102 |
*/
|
|
|
103 |
var $eventHandlers = array(
|
|
|
104 |
PHPDOCUMENTOR_PDP_EVENT_TAG => 'handleTag',
|
|
|
105 |
PHPDOCUMENTOR_PDP_EVENT_ATTRIBUTES => 'handleAttributes',
|
|
|
106 |
PHPDOCUMENTOR_PDP_EVENT_CDATA => 'handleCData',
|
|
|
107 |
PARSER_EVENT_NOEVENTS => 'defaultHandler',
|
|
|
108 |
PARSER_EVENT_COMMENTBLOCK => 'ignoreHandler',
|
|
|
109 |
PARSER_EVENT_OUTPHP => 'ignoreHandler',
|
|
|
110 |
PARSER_EVENT_QUOTE => 'handleQuote',
|
|
|
111 |
PHPDOCUMENTOR_PDP_EVENT_ENTITY => 'handleEntity',
|
|
|
112 |
);
|
|
|
113 |
|
|
|
114 |
/**
|
|
|
115 |
* @var array
|
|
|
116 |
*/
|
|
|
117 |
var $pars = array();
|
|
|
118 |
|
|
|
119 |
var $refsect1id = false;
|
|
|
120 |
var $refsect2id = false;
|
|
|
121 |
var $refsect3id = false;
|
|
|
122 |
/**
|
|
|
123 |
* @var array the tag stack
|
|
|
124 |
*/
|
|
|
125 |
var $context;
|
|
|
126 |
/**#@+ @access private */
|
|
|
127 |
var $_gettoc = false;
|
|
|
128 |
var $_toc = array();
|
|
|
129 |
var $_cursection = 0;
|
|
|
130 |
/**#@-*/
|
|
|
131 |
/**
|
|
|
132 |
* Set up the wordparser
|
|
|
133 |
*
|
|
|
134 |
* {@source}
|
|
|
135 |
*
|
|
|
136 |
* @uses ObjectWordParser
|
|
|
137 |
*/
|
|
|
138 |
function XMLPackagePageParser()
|
|
|
139 |
{
|
|
|
140 |
$this->wp = new ObjectWordParser(true);
|
|
|
141 |
}
|
|
|
142 |
/**
|
|
|
143 |
* Parse a new file
|
|
|
144 |
*
|
|
|
145 |
* @param string $parse_data the parse data
|
|
|
146 |
* @param array $tutorial for format, see {@link Io::getTutorials()}
|
|
|
147 |
*
|
|
|
148 |
* @return bool
|
|
|
149 |
* @staticvar integer used for recursion limiting
|
|
|
150 |
* if a handler for an event is not found
|
|
|
151 |
* @uses parserTutorial using {@link Publisher::PublishEvent()}, a new tutorial
|
|
|
152 |
* is created from the file parsed, and passed to the
|
|
|
153 |
* Intermediate Parser
|
|
|
154 |
*/
|
|
|
155 |
function parse ($parse_data, $tutorial)
|
|
|
156 |
{
|
|
|
157 |
$tempparse = new ppageParser;
|
|
|
158 |
$parse_data = $tempparse->
|
|
|
159 |
parse($parse_data, true, $tutorial['package'],
|
|
|
160 |
$tutorial['subpackage'], basename($tutorial['path']),
|
|
|
161 |
$tutorial['category'], $tutorial['path']);
|
|
|
162 |
unset($tempparse);
|
|
|
163 |
static $endrecur = 0;
|
|
|
164 |
if (!is_array($parse_data) || count($parse_data) == 0) {
|
|
|
165 |
return false;
|
|
|
166 |
}
|
|
|
167 |
$this->setupStates();
|
|
|
168 |
|
|
|
169 |
// initialize variables so E_ALL error_reporting doesn't complain
|
|
|
170 |
$pevent = 0;
|
|
|
171 |
$word = 0;
|
|
|
172 |
$this->p_vars['start'] = true;
|
|
|
173 |
$this->p_vars['event_stack'] = new EventStack;
|
|
|
174 |
|
|
|
175 |
$this->wp->setup($parse_data, false);
|
|
|
176 |
$this->wp->setWhitespace(true);
|
|
|
177 |
$this->context = array();
|
|
|
178 |
if (isset($this->curtag)) {
|
|
|
179 |
unset($this->curtag);
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
do {
|
|
|
183 |
$lpevent = $pevent;
|
|
|
184 |
$pevent = $this->p_vars['event_stack']->getEvent();
|
|
|
185 |
if ($lpevent != $pevent) {
|
|
|
186 |
$this->p_vars['last_pevent'] = $lpevent;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
if ($this->p_vars['last_pevent'] != $pevent) {
|
|
|
190 |
// its a new event so the word parser needs to be reconfigured
|
|
|
191 |
$this->configWordParser($pevent);
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
$this->p_vars['last_word'] = $word;
|
|
|
196 |
$word = $this->wp->getWord();
|
|
|
197 |
|
|
|
198 |
if (PHPDOCUMENTOR_DEBUG == true) {
|
|
|
199 |
echo "----------------\n";
|
|
|
200 |
echo "LAST: |" . $this->p_vars['last_word'] . "|\n";
|
|
|
201 |
echo "INDEX: ".$this->p_vars['curpar']."\n";
|
|
|
202 |
echo "PEVENT: " . $this->getParserEventName($pevent) . "\n";
|
|
|
203 |
echo "LASTPEVENT: " .
|
|
|
204 |
$this->getParserEventName($this->p_vars['last_pevent']) . "\n";
|
|
|
205 |
echo $this->wp->getPos() . " WORD: |$word|\n\n";
|
|
|
206 |
echo '"'.$this->p_vars['quote_data']."\"\n";
|
|
|
207 |
}
|
|
|
208 |
if (isset($this->eventHandlers[$pevent])) {
|
|
|
209 |
$handle = $this->eventHandlers[$pevent];
|
|
|
210 |
if ($word !== false) {
|
|
|
211 |
$this->$handle($word, $pevent);
|
|
|
212 |
}
|
|
|
213 |
} else {
|
|
|
214 |
debug('WARNING: possible error, ' .
|
|
|
215 |
'no XMLPackagePageParser handler for event number '. $pevent);
|
|
|
216 |
if ($endrecur++ == 25) {
|
|
|
217 |
die("FATAL ERROR, recursion limit reached");
|
|
|
218 |
}
|
|
|
219 |
}
|
|
|
220 |
$this->p_vars['start'] = false;
|
|
|
221 |
} while (!($word === false));
|
|
|
222 |
if (count($this->_toc) && isset($this->p_vars['toc'])) {
|
|
|
223 |
$a = $this->curtag->getTOC($this->p_vars['toc']);
|
|
|
224 |
$a->setTOC($this->_toc);
|
|
|
225 |
$a->setPath($tutorial['path']);
|
|
|
226 |
$this->curtag->setTOC($this->p_vars['toc'], $a);
|
|
|
227 |
}
|
|
|
228 |
$this->PublishEvent(PHPDOCUMENTOR_EVENT_TUTORIAL,
|
|
|
229 |
new parserTutorial($this->curtag, $tutorial));
|
|
|
230 |
return $this->curtag;
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
/**#@+
|
|
|
234 |
* @param string|parserInlineTag $word token
|
|
|
235 |
* @param integer $token parser event
|
|
|
236 |
* @return void
|
|
|
237 |
* @access private
|
|
|
238 |
* @todo CS cleanup - PHPCS needs to recognize docblock template tags
|
|
|
239 |
*/
|
|
|
240 |
/**
|
|
|
241 |
* handler for default events
|
|
|
242 |
*/
|
|
|
243 |
function defaultHandler($word, $pevent)
|
|
|
244 |
{
|
|
|
245 |
if (is_string($word) && $this->checkEventPush($word, $pevent)) {
|
|
|
246 |
return;
|
|
|
247 |
}
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
/**
|
|
|
251 |
* handler for ignore events
|
|
|
252 |
*/
|
|
|
253 |
function ignoreHandler($word, $pevent)
|
|
|
254 |
{
|
|
|
255 |
$this->checkEventPop($word, $pevent);
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
/**
|
|
|
259 |
* handler for QUOTE
|
|
|
260 |
*
|
|
|
261 |
* this handler recognizes strings defined with
|
|
|
262 |
* double quotation marks (") and handles them correctly
|
|
|
263 |
* in any place that they legally appear in php code
|
|
|
264 |
*/
|
|
|
265 |
function handleQuote($word, $pevent)
|
|
|
266 |
{
|
|
|
267 |
if ($this->p_flags['reset_quote_data'] === true) {
|
|
|
268 |
$this->p_flags['reset_quote_data'] = false;
|
|
|
269 |
$this->p_vars['quote_data'] = "";
|
|
|
270 |
}
|
|
|
271 |
if (!is_object($word)) {
|
|
|
272 |
$this->checkEventPush($word, $pevent);
|
|
|
273 |
}
|
|
|
274 |
if (is_object($word)) {
|
|
|
275 |
$this->p_vars['quote_data'] = $word;
|
|
|
276 |
} else {
|
|
|
277 |
if ($word != "\"") {
|
|
|
278 |
if (!is_object($this->p_vars['quote_data'])) {
|
|
|
279 |
$this->p_vars['quote_data'] .= $word;
|
|
|
280 |
}
|
|
|
281 |
}
|
|
|
282 |
if ($word == '>') {
|
|
|
283 |
if (is_object($this->p_vars['quote_data'])) {
|
|
|
284 |
$this->p_vars['quote_data'] =
|
|
|
285 |
'{@id '.$this->p_vars['quote_data']->id.'}';
|
|
|
286 |
}
|
|
|
287 |
addErrorDie(PDERROR_UNTERMINATED_ATTRIB, $this->curtag->name,
|
|
|
288 |
$this->p_vars['attrname'], $this->p_vars['quote_data']);
|
|
|
289 |
}
|
|
|
290 |
if ($this->checkEventPop($word, $pevent)) {
|
|
|
291 |
$this->p_flags['reset_quote_data'] = true;
|
|
|
292 |
}
|
|
|
293 |
}
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
/**
|
|
|
297 |
* Handles all XML DocBook tags
|
|
|
298 |
*
|
|
|
299 |
* @todo replace commented-out debug lines with debug() func
|
|
|
300 |
*/
|
|
|
301 |
function handleTag($word, $pevent)
|
|
|
302 |
{
|
|
|
303 |
if (isset($this->curtag) && $this->curtag->hasTitle() &&
|
|
|
304 |
$this->_gettoc && $this->_gettoc->name == $this->curtag->name
|
|
|
305 |
) {
|
|
|
306 |
if (isset($this->_toc[$this->_cursection])) {
|
|
|
307 |
$this->_toc[$this->_cursection]['title'] = $this->curtag->_title;
|
|
|
308 |
$this->_cursection++;
|
|
|
309 |
}
|
|
|
310 |
$this->_gettoc = false;
|
|
|
311 |
}
|
|
|
312 |
if ($this->p_vars['last_word'] == '<') {
|
|
|
313 |
// get tag name
|
|
|
314 |
$this->p_flags['begin_tag'] = true;
|
|
|
315 |
array_push($this->context, $word);
|
|
|
316 |
//DEBUG if (isset($this->curtag)) debug("pushed " . $this->curtag->name);
|
|
|
317 |
if (isset($this->curtag)) {
|
|
|
318 |
array_push($this->pars, $this->curtag);
|
|
|
319 |
}
|
|
|
320 |
$this->curtag = new parserXMLDocBookTag($word);
|
|
|
321 |
} elseif ($this->p_vars['last_word'] == '</' || $word == '/>') {
|
|
|
322 |
$tag = array_pop($this->context);
|
|
|
323 |
if ($word == '/>') {
|
|
|
324 |
// all is OK
|
|
|
325 |
$this->checkEventPop($word, $pevent);
|
|
|
326 |
$word = $tag;
|
|
|
327 |
}
|
|
|
328 |
if ($tag != $word) {
|
|
|
329 |
addErrorDie(PDERROR_UNMATCHED_TUTORIAL_TAG,
|
|
|
330 |
$tag, $word, $this->curtag->getString());
|
|
|
331 |
}
|
|
|
332 |
if (in_array($this->curtag->name,
|
|
|
333 |
array('refentry', 'refsect1', 'refsect2', 'refsect3'))
|
|
|
334 |
) {
|
|
|
335 |
if (!isset($this->curtag->_id)) {
|
|
|
336 |
$title = '';
|
|
|
337 |
if (isset($this->curtag->_title)) {
|
|
|
338 |
$title = $this->curtag->_title->getString();
|
|
|
339 |
}
|
|
|
340 |
addWarning(PDERROR_NO_DOCBOOK_ID, $this->curtag->name, $title);
|
|
|
341 |
}
|
|
|
342 |
}
|
|
|
343 |
$this->p_flags['begin_tag'] = false;
|
|
|
344 |
$curtag = @array_pop($this->pars);
|
|
|
345 |
//DEBUG debug("popped $tag ".$curtag->name.' I am '.$this->curtag->name);
|
|
|
346 |
if ($curtag) {
|
|
|
347 |
if ($this->curtag->name == 'refsect1') $this->refsect1id = false;
|
|
|
348 |
if ($this->curtag->name == 'refsect2') $this->refsect2id = false;
|
|
|
349 |
if ($this->curtag->name == 'refsect3') $this->refsect3id = false;
|
|
|
350 |
$curtag->add($this->curtag);
|
|
|
351 |
//DEBUG debug("added " . $this->curtag->name .
|
|
|
352 |
//DEBUG " to " . $curtag->name . ' ' . $curtag->id);
|
|
|
353 |
$this->curtag = $curtag;
|
|
|
354 |
} else {
|
|
|
355 |
//DEBUG debug("here");
|
|
|
356 |
}
|
|
|
357 |
} elseif (is_string($word)) {
|
|
|
358 |
if (!($e = $this->checkEventPush($word, $pevent))) {
|
|
|
359 |
if ($this->checkEventPop($word, $pevent)) {
|
|
|
360 |
if ($this->p_flags['begin_tag']) {
|
|
|
361 |
$this->p_vars['event_stack']->
|
|
|
362 |
pushEvent(PHPDOCUMENTOR_PDP_EVENT_TAG);
|
|
|
363 |
$this->p_vars['event_stack']->
|
|
|
364 |
pushEvent(PHPDOCUMENTOR_PDP_EVENT_CDATA);
|
|
|
365 |
$this->p_vars['last_tag'] = array_pop($this->context);
|
|
|
366 |
array_push($this->context, $this->p_vars['last_tag']);
|
|
|
367 |
$this->p_flags['in_cdata'] = false;
|
|
|
368 |
}
|
|
|
369 |
return;
|
|
|
370 |
}
|
|
|
371 |
} else {
|
|
|
372 |
$this->p_flags['start_attr'] = true;
|
|
|
373 |
$this->p_flags['end_attr'] = false;
|
|
|
374 |
}
|
|
|
375 |
} else {
|
|
|
376 |
addErrorDie(PDERROR_CANT_HAVE_INLINE_IN_TAGNAME);
|
|
|
377 |
}
|
|
|
378 |
}
|
|
|
379 |
|
|
|
380 |
/**
|
|
|
381 |
* Handle CData sections
|
|
|
382 |
*/
|
|
|
383 |
function handleCData($word, $pevent)
|
|
|
384 |
{
|
|
|
385 |
if ($this->curtag->name == 'refentry' &&
|
|
|
386 |
phpDocumentor_get_class($word) == 'parsertocinlinetag'
|
|
|
387 |
) {
|
|
|
388 |
$this->p_vars['toc'] = $this->curtag->getTOC();
|
|
|
389 |
}
|
|
|
390 |
if (is_string($word) && !$this->p_flags['in_cdata']) {
|
|
|
391 |
if ($this->checkEventPop($word, $pevent)) {
|
|
|
392 |
return;
|
|
|
393 |
}
|
|
|
394 |
if ($this->checkEventPush($word, $pevent)) {
|
|
|
395 |
return;
|
|
|
396 |
}
|
|
|
397 |
}
|
|
|
398 |
if (is_string($word) && $word == '<![CDATA[') {
|
|
|
399 |
$this->curtag->startCData();
|
|
|
400 |
$this->p_flags['in_cdata'] = true;
|
|
|
401 |
} elseif ($this->p_flags['in_cdata'] &&
|
|
|
402 |
is_string($word) && $word == ']]>'
|
|
|
403 |
) {
|
|
|
404 |
$this->curtag->endCData();
|
|
|
405 |
$this->p_flags['in_cdata'] = false;
|
|
|
406 |
} else {
|
|
|
407 |
if ($this->p_flags['in_cdata']) {
|
|
|
408 |
$this->curtag->addCData($word);
|
|
|
409 |
} else {
|
|
|
410 |
$this->curtag->add($word);
|
|
|
411 |
}
|
|
|
412 |
}
|
|
|
413 |
}
|
|
|
414 |
|
|
|
415 |
/**
|
|
|
416 |
* Handle Entities like ”
|
|
|
417 |
*/
|
|
|
418 |
function handleEntity($word, $pevent)
|
|
|
419 |
{
|
|
|
420 |
if (!$word) {
|
|
|
421 |
if (!isset($this->p_vars['entity_name'])) {
|
|
|
422 |
$this->p_vars['entity_name'] = '';
|
|
|
423 |
}
|
|
|
424 |
addErrorDie(PDERROR_UNTERMINATED_ENTITY, $this->p_vars['entity_name']);
|
|
|
425 |
}
|
|
|
426 |
$e = $this->checkEventPop($word, $pevent);
|
|
|
427 |
if ($word && !$e) {
|
|
|
428 |
$this->p_vars['entity_name'] = $word;
|
|
|
429 |
}
|
|
|
430 |
if ($e) {
|
|
|
431 |
$entity = new parserEntity($this->p_vars['entity_name']);
|
|
|
432 |
unset($this->p_vars['entity_name']);
|
|
|
433 |
$this->curtag->add($entity);
|
|
|
434 |
}
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
/**
|
|
|
438 |
* Handle Tag attributes name="value"
|
|
|
439 |
*
|
|
|
440 |
* @todo replace commented-out debug lines with debug() func
|
|
|
441 |
*/
|
|
|
442 |
function handleAttributes($word, $pevent)
|
|
|
443 |
{
|
|
|
444 |
if ($this->checkEventPush($word, $pevent)) {
|
|
|
445 |
return;
|
|
|
446 |
}
|
|
|
447 |
if ($word == '=') {
|
|
|
448 |
$this->p_flags['start_attr'] = false;
|
|
|
449 |
$this->p_vars['end_attr'] = true;
|
|
|
450 |
} else {
|
|
|
451 |
if ($this->p_flags['start_attr']) {
|
|
|
452 |
$this->p_vars['attrname'] = $word;
|
|
|
453 |
} else {
|
|
|
454 |
if (isset($this->p_vars['attrname'])) {
|
|
|
455 |
$value = $this->p_vars['quote_data'];
|
|
|
456 |
if (phpDocumentor_get_class($value) == 'parseridinlinetag') {
|
|
|
457 |
// "inherit" the parent section's id, so
|
|
|
458 |
|
|
|
459 |
// <!-- id is 'test' -->
|
|
|
460 |
// <refsect1 id="{@id test"}>
|
|
|
461 |
// ...
|
|
|
462 |
// <!-- id is 'test.me' -->
|
|
|
463 |
// <refsect2 id="{@id me}">
|
|
|
464 |
// ...
|
|
|
465 |
// <!-- id is 'test.me.out' -->
|
|
|
466 |
// <refsect3 id="{@id out}">
|
|
|
467 |
// ...
|
|
|
468 |
// <!-- id is 'test.me.out.withexample' -->
|
|
|
469 |
// <example id="{@id withexample}">
|
|
|
470 |
|
|
|
471 |
$a = ($this->refsect1id ? $this->refsect1id . '.' : '');
|
|
|
472 |
$a .= ($this->refsect2id ? $this->refsect2id . '.' : '');
|
|
|
473 |
$a .= ($this->refsect3id ? $this->refsect3id . '.' : '');
|
|
|
474 |
if ($this->curtag->name == 'refsect1') {
|
|
|
475 |
$this->refsect1id = $value->id;
|
|
|
476 |
}
|
|
|
477 |
if ($this->curtag->name == 'refsect2') {
|
|
|
478 |
$this->refsect2id = $value->id;
|
|
|
479 |
}
|
|
|
480 |
if ($this->curtag->name == 'refsect3') {
|
|
|
481 |
$this->refsect3id = $value->id;
|
|
|
482 |
}
|
|
|
483 |
//DEBUG debug($value->id . ' is now ' . $a . $value->id);
|
|
|
484 |
$value->id = $a . $value->id;
|
|
|
485 |
if ($value->id != '') {
|
|
|
486 |
if (isset($this->_toc[$this->_cursection])) {
|
|
|
487 |
$this->_cursection++;
|
|
|
488 |
}
|
|
|
489 |
$this->_toc[$this->_cursection]['id'] = $value;
|
|
|
490 |
$this->_toc[$this->_cursection]['tag'] =
|
|
|
491 |
new parserXMLDocBookTag($this->curtag->name);
|
|
|
492 |
//DEBUG debug("set gettoc to " . $this->curtag->name .
|
|
|
493 |
//DEBUG ' ' . $value->id);
|
|
|
494 |
$this->_gettoc = $this->curtag;
|
|
|
495 |
}
|
|
|
496 |
}
|
|
|
497 |
$this->curtag->addAttribute($this->p_vars['attrname'], $value);
|
|
|
498 |
unset($this->p_vars['attrname']);
|
|
|
499 |
if (is_string($word) && $this->checkEventPop($word, $pevent)) {
|
|
|
500 |
$this->p_flags['start_attr'] = true;
|
|
|
501 |
$this->p_flags['end_attr'] = false;
|
|
|
502 |
$this->wp->setPos($this->wp->getPos() - strlen($word));
|
|
|
503 |
} else {
|
|
|
504 |
$this->wp->setPos($this->wp->getPos() - strlen($word));
|
|
|
505 |
}
|
|
|
506 |
return;
|
|
|
507 |
}
|
|
|
508 |
}
|
|
|
509 |
}
|
|
|
510 |
if (is_string($word) && $this->checkEventPop($word, $pevent)) {
|
|
|
511 |
$this->p_flags['start_attr'] = true;
|
|
|
512 |
$this->p_flags['end_attr'] = false;
|
|
|
513 |
$this->wp->setPos($this->wp->getPos() - strlen($word));
|
|
|
514 |
}
|
|
|
515 |
}
|
|
|
516 |
/**#@-*/
|
|
|
517 |
|
|
|
518 |
/**
|
|
|
519 |
* setup the parser tokens, and the pushEvent/popEvent arrays
|
|
|
520 |
*
|
|
|
521 |
* @return void
|
|
|
522 |
* @see $tokens, $pushEvent, $popEvent
|
|
|
523 |
*/
|
|
|
524 |
function setupStates()
|
|
|
525 |
{
|
|
|
526 |
$this->_gettoc = false;
|
|
|
527 |
$this->_toc = array();
|
|
|
528 |
$this->_cursection = 0;
|
|
|
529 |
if (isset($this->p_vars['toc'])) {
|
|
|
530 |
unset($this->p_vars['toc']);
|
|
|
531 |
}
|
|
|
532 |
|
|
|
533 |
$this->tokens[STATE_NOEVENTS]
|
|
|
534 |
= array('</','<!--','<!','<?','<');
|
|
|
535 |
$this->tokens[STATE_COMMENTBLOCK]
|
|
|
536 |
= array('-->');
|
|
|
537 |
$this->tokens[STATE_OUTPHP]
|
|
|
538 |
= array('?>','>');
|
|
|
539 |
$this->tokens[STATE_QUOTE]
|
|
|
540 |
= array("\\\"","\\\\","\"",'>');
|
|
|
541 |
$this->tokens[STATE_ESCAPE]
|
|
|
542 |
= false;// this tells the word parser to just cycle
|
|
|
543 |
$this->tokens[PHPDOCUMENTOR_PDP_STATE_TAG]
|
|
|
544 |
= array('>',' ','/>');
|
|
|
545 |
$this->tokens[PHPDOCUMENTOR_PDP_STATE_CDATA]
|
|
|
546 |
= array('&','<!--','</','<![CDATA[','<',']]>');
|
|
|
547 |
$this->tokens[PHPDOCUMENTOR_PDP_STATE_ATTRIBUTES]
|
|
|
548 |
= array('=','>','/>','"');
|
|
|
549 |
$this->tokens[PHPDOCUMENTOR_PDP_STATE_ENTITY]
|
|
|
550 |
= array(';');
|
|
|
551 |
|
|
|
552 |
// For each event word to event mapings
|
|
|
553 |
$this->pushEvent[PARSER_EVENT_NOEVENTS] =
|
|
|
554 |
array(
|
|
|
555 |
'<!--' => PARSER_EVENT_COMMENTBLOCK,
|
|
|
556 |
'<!' => PARSER_EVENT_OUTPHP,
|
|
|
557 |
"</" => PHPDOCUMENTOR_PDP_EVENT_TAG,
|
|
|
558 |
'<?' => PARSER_EVENT_OUTPHP,
|
|
|
559 |
"<" => PHPDOCUMENTOR_PDP_EVENT_TAG,
|
|
|
560 |
'&' => PHPDOCUMENTOR_PDP_EVENT_ENTITY,
|
|
|
561 |
);
|
|
|
562 |
//##########################
|
|
|
563 |
|
|
|
564 |
$this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_TAG] =
|
|
|
565 |
array(
|
|
|
566 |
' ' => PHPDOCUMENTOR_PDP_EVENT_ATTRIBUTES,
|
|
|
567 |
);
|
|
|
568 |
|
|
|
569 |
$this->popEvent[PHPDOCUMENTOR_PDP_EVENT_TAG] = array(">","/>");
|
|
|
570 |
//##########################
|
|
|
571 |
$this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_ATTRIBUTES] =
|
|
|
572 |
array(
|
|
|
573 |
'"' => PARSER_EVENT_QUOTE,
|
|
|
574 |
);
|
|
|
575 |
|
|
|
576 |
$this->popEvent[PHPDOCUMENTOR_PDP_EVENT_ATTRIBUTES] = array(">","/>");
|
|
|
577 |
//##########################
|
|
|
578 |
|
|
|
579 |
$this->popEvent[PARSER_EVENT_COMMENTBLOCK] = array("-->");
|
|
|
580 |
//##########################
|
|
|
581 |
$this->pushEvent[PARSER_EVENT_QUOTE] =
|
|
|
582 |
array(
|
|
|
583 |
"\\" => PARSER_EVENT_ESCAPE
|
|
|
584 |
);
|
|
|
585 |
$this->popEvent[PARSER_EVENT_QUOTE] = array("\"");
|
|
|
586 |
//##########################
|
|
|
587 |
|
|
|
588 |
$this->popEvent[PARSER_EVENT_OUTPHP] = array("?>",">");
|
|
|
589 |
//##########################
|
|
|
590 |
|
|
|
591 |
$this->popEvent[PHPDOCUMENTOR_PDP_EVENT_ENTITY] = array(";");
|
|
|
592 |
//##########################
|
|
|
593 |
|
|
|
594 |
$this->pushEvent[PHPDOCUMENTOR_PDP_EVENT_CDATA] =
|
|
|
595 |
array(
|
|
|
596 |
"<" => PHPDOCUMENTOR_PDP_EVENT_TAG,
|
|
|
597 |
'<!--' => PARSER_EVENT_COMMENTBLOCK,
|
|
|
598 |
'<?' => PARSER_EVENT_OUTPHP,
|
|
|
599 |
'&' => PHPDOCUMENTOR_PDP_EVENT_ENTITY,
|
|
|
600 |
);
|
|
|
601 |
$this->popEvent[PHPDOCUMENTOR_PDP_EVENT_CDATA] = array("</");
|
|
|
602 |
}
|
|
|
603 |
|
|
|
604 |
/**
|
|
|
605 |
* debugging function
|
|
|
606 |
*
|
|
|
607 |
* {@source}
|
|
|
608 |
*
|
|
|
609 |
* @param mixed $value a value
|
|
|
610 |
*
|
|
|
611 |
* @return mixed the looked up value if found,
|
|
|
612 |
* else the original value
|
|
|
613 |
* @static
|
|
|
614 |
*/
|
|
|
615 |
function getParserEventName ($value)
|
|
|
616 |
{
|
|
|
617 |
$lookup = array(
|
|
|
618 |
PARSER_EVENT_NOEVENTS
|
|
|
619 |
=> "PARSER_EVENT_NOEVENTS",
|
|
|
620 |
PHPDOCUMENTOR_PDP_EVENT_TAG
|
|
|
621 |
=> "PHPDOCUMENTOR_PDP_EVENT_TAG",
|
|
|
622 |
PHPDOCUMENTOR_PDP_EVENT_ATTRIBUTES
|
|
|
623 |
=> "PHPDOCUMENTOR_PDP_EVENT_ATTRIBUTES",
|
|
|
624 |
PHPDOCUMENTOR_PDP_EVENT_CDATA
|
|
|
625 |
=> "PHPDOCUMENTOR_PDP_EVENT_CDATA",
|
|
|
626 |
PHPDOCUMENTOR_PDP_EVENT_LIST
|
|
|
627 |
=> "PHPDOCUMENTOR_PDP_EVENT_LIST",
|
|
|
628 |
PARSER_EVENT_QUOTE
|
|
|
629 |
=> "PARSER_EVENT_QUOTE",
|
|
|
630 |
PHPDOCUMENTOR_PDP_EVENT_ENTITY
|
|
|
631 |
=> "PHPDOCUMENTOR_PDP_EVENT_ENTITY",
|
|
|
632 |
PHPDOCUMENTOR_PDP_EVENT_COMMENT
|
|
|
633 |
=> "PHPDOCUMENTOR_PDP_EVENT_COMMENT",
|
|
|
634 |
PHPDOCUMENTOR_PDP_EVENT_PI
|
|
|
635 |
=> "PHPDOCUMENTOR_PDP_EVENT_PI",
|
|
|
636 |
);
|
|
|
637 |
if (isset($lookup[$value])) {
|
|
|
638 |
return $lookup[$value];
|
|
|
639 |
} else {
|
|
|
640 |
return $value;
|
|
|
641 |
}
|
|
|
642 |
}
|
|
|
643 |
}
|
|
|
644 |
?>
|