Sitellite Application Framework
Class Tree         Index         All Elements

Class: Tokenizer

Source Location: Program_Root/Parser/Tokenizer.php

Class Overview


Tokenizer provides an saf.Parser-like wrapper around the PHP tokenizer extension that can be extended for token analysis and parser writing.


Author(s)

Version

  • 0.6, 2003-01-20, $Id: Tokenizer.php,v 1.2 2005/07/06 15:30:56 lux Exp $

Copyright

  • Copyright (C) 2001-2003, Simian Systems Inc.

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 94]
Tokenizer provides an saf.Parser-like wrapper around the PHP tokenizer extension that can be extended for token analysis and parser writing.

One of its uses in Sitellite is parsing PHP code for I18n text by the saf.I18n.Builder package.

Note: Requires the PHP tokenizer extension, which is built into PHP by default as of 4.3.0.


1 <?php
2
3 class ClassFinder extends Tokenizer {
4 var $classes = array ();
5 var $next = false;
6
7 function ClassFinder () {
8 $this->addCallback ('_class', T_CLASS);
9 $this->addCallback ('_string', T_STRING);
10 }
11
12 function find ($code) {
13 if ($this->parse ($code)) {
14 return $this->classes;
15 } else {
16 return false;
17 }
18 }
19
20 function _class ($token, $data) {
21 $this->next = true;
22 }
23
24 function _string ($token, $data) {
25 if ($this->next) {
26 $this->classes[] = $token;
27 $this->next = false;
28 }
29 }
30 }
31
32 $finder = new ClassFinder ();
33 $res = $finder->find ('<?php
34 class Foo {
35 var $foo = "Hello";
36 }
37 class Bar {
38 var $bar = "World";
39 }
40 ');
41
42 if (is_array ($res)) {
43 foreach ($res as $class) {
44 echo $class . "<br />\n";
45 }
46 }
47
48 ?>




Tags:

access:  public
version:  0.6, 2003-01-20, $Id: Tokenizer.php,v 1.2 2005/07/06 15:30:56 lux Exp $
license:  http://www.sitellite.org/index/license
copyright:  Copyright (C) 2001-2003, Simian Systems Inc.
author:  John Luxford <mailto:lux@simian.ca>


[ Top ]


Class Variables

$code =

[line 104]

Stores the code that is passed to the previous call to parse().



Tags:

access:  public

Type:   mixed


[ Top ]

$error =

[line 120]

Contains the message if an error occurs.



Tags:

access:  public

Type:   mixed


[ Top ]

$tokens =

[line 112]

Stores the tokens from the previous call to parse()



Tags:

access:  public

Type:   mixed


[ Top ]



Class Methods


method addCallback [line 193]

void addCallback( string $function, integer $token)

Adds a callback $function for the specified $token.

The $token is the number of the token, which may be expressed by passing the appropriate T_* tokenizer constant.




Tags:

access:  public


Parameters:

string   $function  
integer   $token  

[ Top ]

method normalize [line 133]

array normalize( array $tokens)

Fixes some quirks and exceptions to the structure of the output of the PHP token_get_all() function.



Tags:

access:  public


Parameters:

array   $tokens  

[ Top ]

method parse [line 158]

boolean parse( string $code)

Parses the specified $code and calls the callback method assigned to each token type.



Tags:

access:  public


Parameters:

string   $code  

[ Top ]

method _default [line 213]

boolean _default( string $token, string $data)

This is the default token handler. It handles all tokens that haven't been assigned custom callback functions.



Tags:

access:  public


Parameters:

string   $token  
string   $data  

[ Top ]


Copyright © 2007, SIMIAN systems Inc.
All rights reserved. Privacy policy
Documentation generated on Tue, 13 Feb 2007 17:19:59 -0600 by Sitellite AppDoc and phpDocumentor 1.2.2