Moved the Agents into their own repo. Kept the agent.pl just for reference
This commit is contained in:
parent
22381be29a
commit
8680a02b13
18132 changed files with 0 additions and 2569420 deletions
|
|
@ -1,296 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @cond CORE
|
||||
* @brief A collection of useful common filters.
|
||||
*
|
||||
* Filters are either stream filters or individual filters.
|
||||
* Stream filters operate on the entire token stream, and return the new
|
||||
* token stream. Individual filters operate on individual tokens (bound by type),
|
||||
* and return the new token. Any publicly available member here is one of those,
|
||||
* therefore the return and param documents are omitted.
|
||||
*
|
||||
*/
|
||||
// Poor man's namespace.
|
||||
class LuminousFilters {
|
||||
|
||||
/**
|
||||
* @brief Gets the expected number of arguments to a doc-comment command/tag
|
||||
* @param $command the name of the command
|
||||
* @returns The expected number of arguments for a command, this is either
|
||||
* 0 or 1 at the moment
|
||||
* @internal
|
||||
*/
|
||||
private static function doxygen_arg_length($command) {
|
||||
switch(strtolower($command)) {
|
||||
case "addtogroup":
|
||||
case "category":
|
||||
case "class":
|
||||
case "cond":
|
||||
case "def":
|
||||
case "defgroup":
|
||||
case "dir":
|
||||
case "elseif":
|
||||
case "enum":
|
||||
case "exception":
|
||||
case "example":
|
||||
case "extends":
|
||||
case "if":
|
||||
case "ifnot":
|
||||
case "file":
|
||||
case "headerfile":
|
||||
case "implements":
|
||||
case "ingroup":
|
||||
case "interface":
|
||||
case "memberof":
|
||||
case "namespace":
|
||||
case "package":
|
||||
case "page":
|
||||
case "par":
|
||||
case "param":
|
||||
case "relates":
|
||||
case "relatesalso":
|
||||
case "retval":
|
||||
case 'see':
|
||||
case 'since':
|
||||
case "tparam":
|
||||
case "throw":
|
||||
case "throws":
|
||||
case "weakgroup":
|
||||
case "xrefitem":
|
||||
return 1;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief callback to doxygenize
|
||||
* Highlights Doxygen-esque doc-comment syntax.
|
||||
* This is a callback to doxygenize().
|
||||
* @return the highlighted string
|
||||
* @internal
|
||||
*/
|
||||
private static function doxygenize_cb($matches) {
|
||||
$lead = $matches[1];
|
||||
$tag_char = $matches[2];
|
||||
$tag = $matches[3];
|
||||
|
||||
$line = "";
|
||||
if (isset($matches[4]))
|
||||
$line = $matches[4];
|
||||
|
||||
$len = -1;
|
||||
// JSDoc-like
|
||||
$l_ = ltrim($line);
|
||||
if (isset($l_[0]) && $l_[0] === '{') {
|
||||
$line = preg_replace('/({[^}]*})/', "<DOCPROPERTY>$1</DOCPROPERTY>", $line);
|
||||
return "$lead<DOCTAG>$tag_char$tag</DOCTAG>$line";
|
||||
}
|
||||
else
|
||||
$len = self::doxygen_arg_length($tag);
|
||||
|
||||
if($len === 0)
|
||||
return "$lead<DOCTAG>$tag_char$tag</DOCTAG>$line";
|
||||
else {
|
||||
$l = explode(' ', $line);
|
||||
$start = "$lead<DOCTAG>$tag_char$tag</DOCTAG><DOCPROPERTY>";
|
||||
|
||||
$j = 0;
|
||||
$c = count($l);
|
||||
for($i=0; $j<$len && $i<$c; $i++)
|
||||
{
|
||||
$s = $l[$i];
|
||||
$start .= $s . ' ';
|
||||
unset($l[$i]);
|
||||
if (trim($s) !== '')
|
||||
$j++;
|
||||
}
|
||||
$start = preg_replace('/ $/', '', $start);
|
||||
$start .= "</DOCPROPERTY>";
|
||||
$l = array_values($l);
|
||||
if (!empty($l)) $start .= ' ';
|
||||
$start .= implode(' ', $l);
|
||||
return $start;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Highlights doc-comment tags inside a comment block.
|
||||
*
|
||||
* @see generic_doc_comment
|
||||
* @internal
|
||||
*/
|
||||
static function doxygenize($token) {
|
||||
$token = LuminousUtils::escape_token($token);
|
||||
$token[1] = preg_replace_callback("/(^(?>[\/\*#\s\{]*))([\@\\\])([\\w]*)(\}|[ \t]+.*?)?$/m",
|
||||
array('LuminousFilters', 'doxygenize_cb'), $token[1]);
|
||||
return $token;
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief Generic filter to highlight JavaDoc, PHPDoc, Doxygen, JSdoc, and similar doc comment syntax.
|
||||
*
|
||||
* A cursory check will be performed to try to validate that the token
|
||||
* really is a doc-comment, it does this by checking for common formats.
|
||||
*
|
||||
* If the check is successful, the token will be switched to type
|
||||
* 'DOCCOMMENT' and its doc-tags will be highlighted
|
||||
*
|
||||
* This is a wrapper around doxygenize(). If the checks are not necessary,
|
||||
* or incorrect for your situation, you may instead choose to use
|
||||
* doxygenize() directly.
|
||||
*/
|
||||
static function generic_doc_comment($token) {
|
||||
// checks if a comment is in the form:
|
||||
// xyyz where x may = y but y != z.
|
||||
// This matches, say, /** comment but does not match /********/
|
||||
// same with /// comment but not ///////////////
|
||||
$s = $token[1];
|
||||
if (isset($s[3])
|
||||
&& ($s[2] === $s[1] || $s[2] === '!')
|
||||
&& !ctype_space($s[0])
|
||||
&& !ctype_space($s[1])
|
||||
&& $s[3] !== $s[2]
|
||||
)
|
||||
{
|
||||
$token[0] = 'DOCCOMMENT';
|
||||
$token = self::doxygenize($token);
|
||||
}
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Highlights comment notes
|
||||
* Highlights keywords in comments, i.e. "NOTE", "XXX", "FIXME", "TODO",
|
||||
* "HACK", "BUG"
|
||||
*/
|
||||
static function comment_note($token) {
|
||||
$token = LuminousUtils::escape_token($token);
|
||||
$token[1] = preg_replace('/\\b(?:NOTE|XXX|FIXME|TODO|HACK|BUG):?/',
|
||||
'<COMMENT_NOTE>$0</COMMENT_NOTE>', $token[1]);
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Highlights generic escape sequences in strings
|
||||
* Highlights escape sequences in strings. There is no checking on which
|
||||
* sequences are legal, this is simply a generic function which checks for
|
||||
* \\u... unicode, \\d... octal, \\x... hex and finally just any character
|
||||
* following a backslash.
|
||||
*/
|
||||
static function string($token) {
|
||||
if (strpos($token[1], '\\') === false) return $token;
|
||||
|
||||
$token = LuminousUtils::escape_token($token);
|
||||
$token[1] = preg_replace('/
|
||||
\\\\
|
||||
(?:
|
||||
(?:u[a-f0-9]{4,8}) # unicode
|
||||
|\d{1,3} # octal
|
||||
|x[a-fA-F0-9]{2} # hex
|
||||
|. # whatever
|
||||
)
|
||||
/xi', '<ESC>$0</ESC>', $token[1]);
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tries to highlight PCRE style regular expression syntax
|
||||
*/
|
||||
static function pcre($token, $delimited=true) {
|
||||
$token = self::string($token);
|
||||
$token = LuminousUtils::escape_token($token);
|
||||
$str = &$token[1];
|
||||
$flags = array();
|
||||
if ($delimited) {
|
||||
$str = preg_replace('/^[^[:alnum:]<>\s]/', '<DELIMITER>$0</DELIMITER>', $str);
|
||||
if (preg_match("/[[:alpha:]]+$/", $str, $matches)){
|
||||
$m = $matches[0];
|
||||
$flags = str_split($m);
|
||||
$str = preg_replace("/((?<!\A)[^[:alnum:]\s<>])([[:alpha:]]+)$/",
|
||||
"<DELIMITER>$1</DELIMITER><KEYWORD>$2</KEYWORD>", $str);
|
||||
} else
|
||||
$str = preg_replace('/[^[:alnum:]<>]$/', '<DELIMITER>$0</DELIMITER>', $str);
|
||||
|
||||
}
|
||||
|
||||
$str = preg_replace("/((?<!\\\)[\*\+\.|])|((?<![\(\\\])\?)/",
|
||||
"<REGEX_OPERATOR>$0</REGEX_OPERATOR>", $str);
|
||||
$str = preg_replace("/(?<=\()\?(?:(?:[a-zA-Z:!|=])|(?:(?:<)[=!]))/",
|
||||
"<REGEX_SUBPATTERN>$0</REGEX_SUBPATTERN>", $str);
|
||||
$str = preg_replace("/(?<!\\\)[\(\)]/",
|
||||
"<REGEX_SUBPATTERN_MARKER>$0</REGEX_SUBPATTERN_MARKER>", $str);
|
||||
$str = preg_replace("/(?<!\\\)[\[\]]/",
|
||||
"<REGEX_CLASS_MARKER>$0</REGEX_CLASS_MARKER>", $str);
|
||||
$str = preg_replace("/(?<!\\\)
|
||||
\{
|
||||
(
|
||||
((?>\d+)(,(?>\d+)?)?)
|
||||
|
|
||||
(,(?>\d+))
|
||||
)
|
||||
\}/x", "<REGEX_REPEAT_MARKER>$0</REGEX_REPEAT_MARKER>", $str);
|
||||
|
||||
// extended regex: # signifies a comment
|
||||
if (in_array('x', $flags))
|
||||
$str = preg_replace('/(?<!\\\)#.*$/m', '<COMMENT>$0</COMMENT>',
|
||||
$str);
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Translates any token type of an uppercase/numeric IDENT to 'CONSTANT'
|
||||
*/
|
||||
static function upper_to_constant($token) {
|
||||
// check for this because it may have been mapped to a function or something
|
||||
if ($token[0] === 'IDENT' && preg_match('/^[A-Z_][A-Z_0-9]{3,}$/', $token[1]))
|
||||
$token[0] = 'CONSTANT';
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Translates anything of type 'IDENT' to the null type
|
||||
*/
|
||||
static function clean_ident($token) {
|
||||
if ($token[0] === 'IDENT') $token[0] = null;
|
||||
return $token;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Attempts to apply OO syntax highlighting
|
||||
*
|
||||
* Tries to apply generic OO syntax highlighting. Any identifer immediately
|
||||
* preceding a '.', '::' or '->' token is mapped to an 'OO'.
|
||||
* Any identifer token immediatel following any of those tokens is mapped to
|
||||
* an 'OBJ'.
|
||||
* This is a stream filter.
|
||||
*/
|
||||
static function oo_stream_filter($tokens) {
|
||||
$c = count($tokens);
|
||||
for($i=0; $i<$c; $i++) {
|
||||
if ($tokens[$i][0] !== 'IDENT') continue;
|
||||
if ($i > 0) {
|
||||
$s = $tokens[$i-1][1];
|
||||
if ($s === '.' || $s === '->' || $s === '::') {
|
||||
$tokens[$i][0] = 'OO';
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ($i < $c-1) {
|
||||
$s = $tokens[$i+1][1];
|
||||
if ($s === '.' || $s === '->' || $s === '::') {
|
||||
$tokens[$i][0] = 'OBJ';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @endcond
|
||||
// end CORE
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,84 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @cond CORE
|
||||
* @brief A basic preg_match wrapper which caches its results
|
||||
*
|
||||
* @note This class is used by Scanner and should not need to be used by
|
||||
* anything else.
|
||||
*
|
||||
* A class encapsulating the process of searching for a substring efficiently
|
||||
* it handles caching of results.
|
||||
*
|
||||
* @warning One instance should be used only incrementally along a string.
|
||||
* i.e. do not call it with index = 5 then index = 1.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
*/
|
||||
class LuminousStringSearch
|
||||
{
|
||||
/// A copy of the string to operate on.
|
||||
private $string;
|
||||
|
||||
/**
|
||||
* The cache is stored as a map of pattern => result,
|
||||
* the result is an array of:
|
||||
* (0=>index, 1=>match_groups), OR, it is false if there are no more results
|
||||
* left in the string.
|
||||
*/
|
||||
private $cache = array();
|
||||
|
||||
public function __construct($str) {
|
||||
$this->string = $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Performs a search for the given pattern past the given index.
|
||||
* @param $search the pattern to search for
|
||||
* @param $index the minimum string index (offset) of a result
|
||||
* @param $matches a reference to the return location of the match groups
|
||||
* @return the index or false if no match is found.
|
||||
*/
|
||||
public function
|
||||
match($search, $index, &$matches) {
|
||||
$r = false; // return value
|
||||
|
||||
if (isset($this->cache[$search])) {
|
||||
$a = $this->cache[$search];
|
||||
if ($a === false) return false; // no more results
|
||||
|
||||
$r = $a[0];
|
||||
$matches = $a[1];
|
||||
assert($matches !== null);
|
||||
|
||||
if ($r >= $index) // cache is good!
|
||||
return $r;
|
||||
}
|
||||
// cache not set, or out of date, we have to perform the match
|
||||
if (!($ret = preg_match($search, $this->string, $matches_,
|
||||
PREG_OFFSET_CAPTURE, $index))) {
|
||||
if ($ret === false && LUMINOUS_DEBUG) {
|
||||
throw new Exception('preg_match returned false for pattern: "'
|
||||
. $search . '", with code: ' . LuminousUtils::pcre_error_decode(
|
||||
preg_last_error()) . " with string length " . strlen($this->string)
|
||||
. " and offset " . $index
|
||||
);
|
||||
}
|
||||
$this->cache[$search] = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
$r = $matches_[0][1];
|
||||
// strip the offsets from the match_groups
|
||||
foreach($matches_ as $i=>&$v)
|
||||
$v = $v[0];
|
||||
|
||||
$this->cache[$search] = array($r, $matches_);
|
||||
|
||||
$matches = $matches_;
|
||||
return $r;
|
||||
}
|
||||
}
|
||||
|
||||
/// @endcond
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @cond CORE
|
||||
* @brief A set of pre-defined patterns to match various common tokens
|
||||
*/
|
||||
abstract class LuminousTokenPresets {
|
||||
|
||||
/// multi-line double quoted string using backslash escapes
|
||||
static $DOUBLE_STR = '/" (?> [^"\\\\]+ | \\\\.)* (?:"|$)/xs';
|
||||
|
||||
/// single line double quoted string using backslash escapes
|
||||
static $DOUBLE_STR_SL = "/\"(?> [^\\\\\"\n]+ | \\\\.)*(?:\$|\")/xms";
|
||||
|
||||
/// multi-line single quote string using backslash escapes
|
||||
static $SINGLE_STR = "/' (?> [^'\\\\]+ | \\\\.)* (?:'|\$)/xs";
|
||||
|
||||
/// single line single quoted string using backslash escapes
|
||||
static $SINGLE_STR_SL = "/'(?> [^\\\\'\n]+ | \\\\.)*(?:\$|')/xms";
|
||||
|
||||
/// Single quoted c-style character
|
||||
static $CHAR = "(?: \\\\(?: x[A-F0-9]{1,2}| . ) | . ) (?: '|\$)/ixm";
|
||||
|
||||
/// hexadecimal literal
|
||||
static $NUM_HEX = '/0[Xx][a-fA-F0-9]+/';
|
||||
|
||||
/// Real number, i.e. an integer or a float, optionally with an exponent
|
||||
static $NUM_REAL = '/
|
||||
(?: \d+ (?: \.\d+ )? | \.?\d+) # int, fraction or significand
|
||||
(?:e[+-]?\d+)? # exponent
|
||||
/ix';
|
||||
|
||||
/// Single line c++ style comment
|
||||
static $C_COMMENT_SL = '% // .* %x';
|
||||
|
||||
/// Multiline C style comment
|
||||
static $C_COMMENT_ML = '% / \* (?> [^\\*]+ | \\*(?!/) )* (?: \\*/ | $) %sx';
|
||||
|
||||
/// Perl/Python/Ruby style hash-comment (single line)
|
||||
static $PERL_COMMENT = '/#.*/';
|
||||
|
||||
/// SQL style single quoted string using '' to escape
|
||||
static $SQL_SINGLE_STR = "/ ' (?> [^']+ | '' )* (?: '|\$)/x";
|
||||
|
||||
/// SQL style single quoted string using '' or \' to escape
|
||||
static $SQL_SINGLE_STR_BSLASH = "/ ' (?> [^'\\\\]+ | '' | \\\\. )* (?: '|\$)/x";
|
||||
|
||||
}
|
||||
/// @endcond
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @cond CORE
|
||||
* @brief A set of utility functions for scanners
|
||||
*/
|
||||
class LuminousUtils {
|
||||
|
||||
/**
|
||||
* @brief Tries to balance a delimiter
|
||||
*
|
||||
* Tries to 'balance' a single character delimiter, i.e:
|
||||
* '(' is mapped to ')'
|
||||
* '{' is mapped to '}',
|
||||
* '[' is mapped to ']',
|
||||
* '<' is mapped to '>'
|
||||
* Any other character is mapped to itself.
|
||||
*
|
||||
* @param $delimiter the left/opening delimiter to try to balance
|
||||
* @return The corresponding close delimiter character, or the input
|
||||
* character.
|
||||
*/
|
||||
static function balance_delimiter($delimiter) {
|
||||
switch($delimiter) {
|
||||
case '(' : return ')';
|
||||
case '{' : return '}';
|
||||
case '[' : return ']';
|
||||
case '<' : return '>';
|
||||
default: return $delimiter;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Escapes a string suitable for use in XML
|
||||
*
|
||||
* Escapes a string according to the Luminous internal escaping format
|
||||
* (this is currently htmlspecialchars with ENT_NOQUOTES.)
|
||||
* @param $string the string to escape
|
||||
* @return the escaped string
|
||||
*/
|
||||
static function escape_string($string) {
|
||||
return htmlspecialchars($string, ENT_NOQUOTES);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Escapes a token so its string is suitable for use in XML
|
||||
*
|
||||
* Escapes a token. If the token is already escaped, nothing changes.
|
||||
* If the token is not escaped, the escaped flag is set (index 2) and the
|
||||
* token text (index 1) is escaped according to the internal escaping format
|
||||
* @param $token the token to escape
|
||||
* @return the escaped token
|
||||
*/
|
||||
static function escape_token($token) {
|
||||
$esc = &$token[2];
|
||||
if (!$esc) {
|
||||
$str = &$token[1];
|
||||
$str = htmlspecialchars($str, ENT_NOQUOTES);
|
||||
$esc = true;
|
||||
}
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wraps a block of text in an XML tag
|
||||
*
|
||||
* Tags a block of text. The block is assumed to have been escaped correctly
|
||||
* with LuminousUtils::escape_string.
|
||||
* @param $type the type to tag the string as, this is the token name
|
||||
* @param $block the block of text
|
||||
* @param $split_multiline if this is set to true, the tags are closed at
|
||||
* the end of each line and re-opened again on the next line. This is
|
||||
* useful for output formats like HTML, where spanning multiple lines
|
||||
* could break the markup
|
||||
* @return The tagged block of text. This resembles an XML fragment.
|
||||
*/
|
||||
static function tag_block($type, $block, $split_multiline=true) {
|
||||
if ($type === null) return $block;
|
||||
$open = '<' . $type . '>';
|
||||
$close = '</' . $type . '>';
|
||||
if ($split_multiline)
|
||||
return $open . str_replace("\n", $close . "\n" . $open, $block) .
|
||||
$close;
|
||||
else
|
||||
return $open . $block . $close;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decodes PCRE error codes to human readable strings
|
||||
*
|
||||
* Decodes a PCRE error code, which was returned by preg_last_error(), to
|
||||
* something readable
|
||||
* @param $errcode the error code
|
||||
* @return the error description, as string. This is currently the same
|
||||
* as the constant name, so the constant PREG_NO_ERROR is mapped to the
|
||||
* string 'PREG_NO_ERROR'
|
||||
*/
|
||||
static function pcre_error_decode($errcode) {
|
||||
switch ($errcode) {
|
||||
case PREG_NO_ERROR:
|
||||
return 'PREG_NO_ERROR';
|
||||
case PREG_INTERNAL_ERROR:
|
||||
return 'PREG_INTERNAL_ERROR';
|
||||
case PREG_BACKTRACK_LIMIT_ERROR:
|
||||
return 'PREG_BACKTRACK_LIMIT_ERROR';
|
||||
case PREG_RECURSION_LIMIT_ERROR:
|
||||
return 'PREG_RECURSION_LIMIT_ERROR';
|
||||
case PREG_BAD_UTF8_ERROR:
|
||||
return 'PREG_BAD_UTF8_ERROR';
|
||||
case PREG_BAD_UTF8_OFFSET_ERROR:
|
||||
return 'PREG_BAD_UTF8_OFFSET_ERROR';
|
||||
default:
|
||||
return "Unknown error code `$errcode'";
|
||||
}
|
||||
}
|
||||
}
|
||||
/// @endcond
|
||||
// ends CORE
|
||||
Loading…
Add table
Add a link
Reference in a new issue