public static function compile(HyperLanguage $lang)
 {
     $id = $lang->id();
     if (!isset(self::$_compiledLanguageCache[$id])) {
         self::$_compiledLanguageCache[$id] = $lang->makeCompiledLanguage();
     }
     return self::$_compiledLanguageCache[$id];
 }
Example #2
0
 public function __construct()
 {
     $this->setInfo(array(parent::NAME => 'PHP', parent::VERSION => '0.3', parent::AUTHOR => array(parent::NAME => 'Konrad Rudolph', parent::WEBSITE => 'madrat.net', parent::EMAIL => '*****@*****.**')));
     $this->setExtensions(array('php', 'php3', 'php4', 'php5', 'inc'));
     $this->addPostProcessing('html', HyperLanguage::fromName('xml'));
     $this->addStates(array('init' => array('php', 'html'), 'php' => array('comment', 'string', 'char', 'number', 'keyword' => array('', 'type', 'literal', 'operator', 'builtin'), 'identifier', 'variable'), 'variable' => array('identifier'), 'html' => array()));
     $this->addRules(array('php' => new Rule('/<\\?php/', '/\\?>/'), 'html' => new Rule('/(?=.)/', '/(?=<\\?php)/'), 'comment' => Rule::C_COMMENT, 'string' => Rule::C_DOUBLEQUOTESTRING, 'char' => Rule::C_SINGLEQUOTESTRING, 'number' => Rule::C_NUMBER, 'identifier' => Rule::C_IDENTIFIER, 'variable' => new Rule('/\\$/', '//'), 'keyword' => array(array('break', 'case', 'class', 'const', 'continue', 'declare', 'default', 'do', 'else', 'elseif', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'extends', 'for', 'foreach', 'function', 'global', 'if', 'return', 'static', 'switch', 'use', 'var', 'while', 'final', 'interface', 'implements', 'public', 'private', 'protected', 'abstract', 'try', 'catch', 'throw', 'final', 'namespace'), 'type' => array('exception', 'int'), 'literal' => array('false', 'null', 'true', 'this'), 'operator' => array('and', 'as', 'or', 'xor', 'new', 'instanceof', 'clone'), 'builtin' => array('array', 'die', 'echo', 'empty', 'eval', 'exit', 'include', 'include_once', 'isset', 'list', 'print', 'require', 'require_once', 'unset'))));
     $this->addMappings(array('char' => 'string', 'variable' => 'tag', 'html' => 'preprocessor'));
 }
 public function __construct($id, $info, $extensions, $states, $rules, $mappings, $caseInsensitive, $postProcessors)
 {
     $this->_id = $id;
     $this->_info = $info;
     $this->_extensions = $extensions;
     $this->_caseInsensitive = $caseInsensitive;
     $this->_states = $this->compileStates($states);
     $this->_rules = $this->compileRules($rules);
     $this->_mappings = $mappings;
     foreach ($postProcessors as $ppkey => $ppvalue) {
         $this->_postProcessors[$ppkey] = HyperLanguage::compile($ppvalue);
     }
 }
Example #4
0
 public function __construct($lang)
 {
     if (is_string($lang)) {
         $this->_lang = HyperLanguage::compileFromName(strtolower($lang));
     } else {
         if ($lang instanceof HyperlightCompiledLanguage) {
             $this->_lang = $lang;
         } else {
             if ($lang instanceof HyperLanguage) {
                 $this->_lang = HyperLanguage::compile($lang);
             } else {
                 trigger_error('Invalid argument type for $lang to Hyperlight::__construct', E_USER_ERROR);
             }
         }
     }
     foreach ($this->_lang->postProcessors() as $ppkey => $ppvalue) {
         $this->_postProcessors[$ppkey] = new Hyperlight($ppvalue);
     }
     $this->reset();
 }
Example #5
0
function ext_from_lang($language)
{
    $lang = HyperLanguage::compileFromName($language);
    return "{$language}:" . implode(',', $lang->extensions());
}
/**
 * Is the same as:
 * <code>
 * hyperlight(file_get_contents($filename), $lang, $tag, $attributes);
 * </code>
 * @see hyperlight()
 */
function hyperlight_file($filename, $lang = null, $tag = 'pre', array $attributes = array())
{
    if ($lang == '') {
        // Try to guess it from file extension.
        $pos = strrpos($filename, '.');
        if ($pos !== false) {
            $ext = substr($filename, $pos + 1);
            $lang = HyperLanguage::nameFromExt($ext);
        }
    }
    hyperlight(file_get_contents($filename), $lang, $tag, $attributes);
}
Example #7
0
 public function render($code)
 {
     if (false === $this->language()) {
         $this->_lang = HyperLanguage::compileFromName('code');
         $this->reset();
         if (!$this->language()) {
             return htmlspecialchars($code);
         }
     }
     // Normalize line breaks.
     $this->_code = preg_replace('/\\r\\n?/', "\n", $code);
     $fm = hyperlight_calculate_fold_marks($this->_code, $this->language()->id());
     return hyperlight_apply_fold_marks($this->renderCode(), $fm);
 }