added regular expression constants library

Esse commit está contido em:
Felipe Nascimento de Moura
2011-02-08 18:09:59 -02:00
commit 684f5a39fb
6 arquivos alterados com 36 adições e 20 exclusões
+5 -5
Ver Arquivo
@@ -63,22 +63,22 @@
$this->name= substr($str, 0, $typeStart);
// identifying details
if(preg_match("/\(.*/", $str, $details))
if(preg_match(PROP_DETAILS, $str, $details))
{
$details= $details[0];
// identifying the default value
if(preg_match("/\".*\"/", $details, $default))
if(preg_match(PROP_DEFAULT, $details, $default))
{
$default= $default[0];
$details= str_replace($default, "", $str, $one);
// checking if the default value isn't a value or a function call
if($default[1]=='=' || strtolower(substr($default, 1, 5)) == 'exec:')
if($default[1]=='=' || strtolower(substr($default, 1, 5)) == EXEC_STRING)
{
$default= preg_replace("/(^(\"=)|(\"exec\:))|(\"$)/i", "", $default);
$default= preg_replace(PROP_DEFEXEC, "", $default);
}
//$default= preg_replace("/(^\")|(\"$)/", "", $default);
$this->default= $default;
}
+13 -12
Ver Arquivo
@@ -2,7 +2,7 @@
/**
* This class sweeps the passed words and validates if
* its content matches with the valid chars
* @package cortex.analyst
*
* @author felipe
*/
class Lexer
@@ -19,6 +19,7 @@ class Lexer
* Thanks to saeedco (no more information found about him!)
* Source: http://br2.php.net/manual/en/function.str-split.php#83331
* Idioms it is supposed to work properly
* English
* Chinese
* Japanese
* Arabic
@@ -87,7 +88,7 @@ class Lexer
{
Mind::$originalContent= $content;
// let's treat the single line comments
$content= preg_replace('/\/\/.+\n/', '', $content);
$content= preg_replace(SINGLE_COMMENT, '', $content);
// now, it's time to start working with the data
$this->content= trim(str_replace("\n", ' ', $content));
@@ -119,7 +120,7 @@ class Lexer
if($letter == ' ')
$letter= $this->tmpSpace;
if($letter == ',')
$letter= $this->tmpComma;
$letter= $this->tmpComa;
if($letter == '.')
$letter= $this->tmpPeriod;
}
@@ -138,12 +139,12 @@ class Lexer
// normal spaces, instead of the space token
// restoring the inition format for attribute details
$fixed= str_replace($this->tmpSpace, " ", $fixed);
$fixed= str_replace($this->tmpComma, ",", $fixed);
$fixed= str_replace($this->tmpComa, ",", $fixed);
$fixed= str_replace($this->tmpPeriod, ".", $fixed);
// let's deal with the \n and multiline comments
$fixed= preg_replace("/\n/", $this->tokens[' '], $fixed);
$fixed= preg_replace('/\/\*.+\*\//', '', $fixed);
$fixed= preg_replace(NEW_LINE, $this->tokens[' '], $fixed);
$fixed= preg_replace(MULTILINE_COMMENT, '', $fixed);
$exploded= explode($this->tokens[' '], $fixed);
@@ -170,12 +171,12 @@ class Lexer
public function __construct()
{
GLOBAL $_MIND;
$this->glue= chr('176');
$this->tmpSpace = "__MINDTMPSPACEGLUEFORSPACESBETWEENPARENTHESES__";
$this->tmpComma = "__MINDTMPCOMAGLUEFORSPACESBETWEENPARENTHESES__";
$this->tmpPeriod = "__MINDTMPPERIODGLUEFORSPACESBETWEENPARENTHESES__";
$this->lang= Mind::$currentProject['idiom'];
$xml= simplexml_load_file(Mind::$langPath.$this->lang.'/lexics.xml');
$this->glue = chr('176');
$this->tmpSpace = chr('177');
$this->tmpComa = chr('178');
$this->tmpPeriod = chr('179');
$this->lang = Mind::$currentProject['idiom'];
$xml = simplexml_load_file(Mind::$langPath.$this->lang.'/lexics.xml');
$this->validChars = (string)$xml->validchars->lower;
$this->validChars.= (string)$xml->validchars->upper;
-2
Ver Arquivo
@@ -39,7 +39,6 @@ class Analyst {
$i= 0;
foreach($structureKeys as $token)
{
//echo $expression[$i]."<hr>";
$word= $expression[$i];
// if it is a substantive
@@ -51,7 +50,6 @@ class Analyst {
//echo "it is an entity!\n";
}else{ // otherwise, it must be a property
$tmpProperty= new MindProperty($word);
//echo " is a property\n";
}
}
+1 -1
Ver Arquivo
@@ -37,7 +37,7 @@ class Tokenizer extends Token{
{
while (!feof($resource))
{
$word= preg_replace('/\s/', '', fgets($resource, 4096));
$word= preg_replace(COMA_SEPARATOR, '', fgets($resource, 4096));
self::$sintaticsList[$word]= true;
}
return self::$sintaticsList;
+1
Ver Arquivo
@@ -7,6 +7,7 @@
* variables, such as language for localization
*/
require(_MINDSRC_.'/mind3rd/API/utils/header.php');
include(_MINDSRC_.'/mind3rd/API/utils/constants.php');
$app= new Symfony\Component\Console\Application('mind');
$app->addCommands(Array(
+16
Ver Arquivo
@@ -0,0 +1,16 @@
<?php
/**
* This file is used to define constants that may be
* used on the system
* It will have the regular expression dictionary, mainly
*/
// REGULAR EXPRESSIONS
define('PROP_DETAILS', "/\(.*/");
define('PROP_DEFAULT', "/\".*\"/");
define('PROP_DEFEXEC', "/(^(\"=)|(\"exec\:))|(\"$)/i");
define('COMA_SEPARATOR', '/\s/');
define('SINGLE_COMMENT', '/\/\/.+\n/');
define('MULTILINE_COMMENT', '/\/\*.+?\*\//');
define('NEW_LINE', "/\n/");
define('EXEC_STRING', 'exec:'); // equal (=) is also acceptable