Permalink
Browse files

fixed init for manual load

  • Loading branch information...
1 parent c5c7c69 commit aa3f071b35e3be37c1bdf87ad0f62d8242ff1565 @alxlit committed Apr 10, 2012
Showing with 29 additions and 17 deletions.
  1. +8 −2 src/CoffeeScript/Lexer.php
  2. +21 −15 src/CoffeeScript/Rewriter.php
View
@@ -134,11 +134,17 @@ class Lexer
static $INVERSES = array();
+ static $initialized = FALSE;
+
/**
* Initialize some static variables (called at the end of this file).
*/
static function init()
{
+ if (self::$initialized) return;
+
+ self::$initialized = TRUE;
+
self::$COFFEE_KEYWORDS = array_merge(self::$COFFEE_KEYWORDS, array_keys(self::$COFFEE_ALIASES));
self::$COFFEE_RESERVED = array_merge(self::$JS_RESERVED, self::$JS_KEYWORDS, self::$COFFEE_KEYWORDS, self::$STRICT_PROSCRIBED);
self::$JS_FORBIDDEN = array_merge(self::$JS_KEYWORDS, self::$JS_RESERVED, self::$STRICT_PROSCRIBED);
@@ -294,6 +300,8 @@ static function t_canonical($token)
function __construct($code, $options)
{
+ self::init();
+
if (preg_match(self::$WHITESPACE, $code))
{
$code = "\n{$code}";
@@ -1343,6 +1351,4 @@ function whitespace_token()
}
}
-Lexer::init();
-
?>
@@ -42,8 +42,29 @@ class Rewriter
static $LINEBREAKS = array('TERMINATOR', 'INDENT', 'OUTDENT');
+ static $initialized = FALSE;
+
+ static function init()
+ {
+ if (self::$initialized) return;
+
+ self::$initialized = TRUE;
+
+ foreach (self::$BALANCED_PAIRS as $pair)
+ {
+ list($left, $rite) = $pair;
+
+ self::$EXPRESSION_START[] = self::$INVERSES[$rite] = $left;
+ self::$EXPRESSION_END[] = self::$INVERSES[$left] = $rite;
+ }
+
+ self::$EXPRESSION_CLOSE = array_merge(self::$EXPRESSION_CLOSE, self::$EXPRESSION_END);
+ }
+
function __construct($tokens)
{
+ self::init();
+
$this->tokens = $tokens;
}
@@ -444,19 +465,6 @@ function indentation($token)
return array( array(t('INDENT'), 2, $token[2]), array(t('OUTDENT'), 2, $token[2]) );
}
- static function init()
- {
- foreach (self::$BALANCED_PAIRS as $pair)
- {
- list($left, $rite) = $pair;
-
- self::$EXPRESSION_START[] = self::$INVERSES[$rite] = $left;
- self::$EXPRESSION_END[] = self::$INVERSES[$left] = $rite;
- }
-
- self::$EXPRESSION_CLOSE = array_merge(self::$EXPRESSION_CLOSE, self::$EXPRESSION_END);
- }
-
function remove_leading_newlines()
{
$key = 0;
@@ -626,6 +634,4 @@ function tag_postfix_conditionals()
}
}
-Rewriter::init();
-
?>

0 comments on commit aa3f071

Please sign in to comment.