Added Int rule. Need to do something about it
parent
960c369020
commit
160ab66243
|
@ -1260,6 +1260,7 @@ static RuleXML *rule_regex_xml_parse (xmlNode *node);
|
||||||
static RuleXML *rule_char_xml_parse (xmlNode *node);
|
static RuleXML *rule_char_xml_parse (xmlNode *node);
|
||||||
static RuleXML *rule_2char_xml_parse (xmlNode *node);
|
static RuleXML *rule_2char_xml_parse (xmlNode *node);
|
||||||
static RuleXML *rule_any_char_xml_parse (xmlNode *node);
|
static RuleXML *rule_any_char_xml_parse (xmlNode *node);
|
||||||
|
static RuleXML *rule_int_xml_parse (xmlNode *node);
|
||||||
static RuleXML *rule_keywords_xml_parse (LangXML *lang_xml,
|
static RuleXML *rule_keywords_xml_parse (LangXML *lang_xml,
|
||||||
xmlNode *node);
|
xmlNode *node);
|
||||||
static RuleXML *rule_include_xml_parse (LangXML *lang_xml,
|
static RuleXML *rule_include_xml_parse (LangXML *lang_xml,
|
||||||
|
@ -1274,6 +1275,7 @@ static void rule_include_xml_free (RuleIncludeXML *xml);
|
||||||
static MooRule *rule_string_xml_create_rule (RuleStringXML *xml);
|
static MooRule *rule_string_xml_create_rule (RuleStringXML *xml);
|
||||||
static MooRule *rule_regex_xml_create_rule (RuleRegexXML *xml);
|
static MooRule *rule_regex_xml_create_rule (RuleRegexXML *xml);
|
||||||
static MooRule *rule_any_char_xml_create_rule (RuleAnyCharXML *xml);
|
static MooRule *rule_any_char_xml_create_rule (RuleAnyCharXML *xml);
|
||||||
|
static MooRule *rule_int_xml_create_rule (RuleXML *xml);
|
||||||
static MooRule *rule_keywords_xml_create_rule (RuleKeywordsXML *xml,
|
static MooRule *rule_keywords_xml_create_rule (RuleKeywordsXML *xml,
|
||||||
LangXML *lang_xml);
|
LangXML *lang_xml);
|
||||||
static MooRule *rule_include_xml_create_rule (RuleIncludeXML *xml,
|
static MooRule *rule_include_xml_create_rule (RuleIncludeXML *xml,
|
||||||
|
@ -1283,6 +1285,7 @@ static MooRule *rule_2char_xml_create_rule (Rule2CharXML *xml);
|
||||||
|
|
||||||
#define rule_char_xml_free g_free
|
#define rule_char_xml_free g_free
|
||||||
#define rule_2char_xml_free g_free
|
#define rule_2char_xml_free g_free
|
||||||
|
#define rule_int_xml_free g_free
|
||||||
|
|
||||||
#define RULE_IS__(node__,name__) (!g_ascii_strcasecmp ((char*)node__->name, name__))
|
#define RULE_IS__(node__,name__) (!g_ascii_strcasecmp ((char*)node__->name, name__))
|
||||||
#define RULE_IS_STRING_NODE(node__) (RULE_IS__(node__, RULE_ASCII_STRING_ELM))
|
#define RULE_IS_STRING_NODE(node__) (RULE_IS__(node__, RULE_ASCII_STRING_ELM))
|
||||||
|
@ -1292,6 +1295,7 @@ static MooRule *rule_2char_xml_create_rule (Rule2CharXML *xml);
|
||||||
#define RULE_IS_ANY_CHAR_NODE(node__) (RULE_IS__(node__, RULE_ASCII_ANY_CHAR_ELM))
|
#define RULE_IS_ANY_CHAR_NODE(node__) (RULE_IS__(node__, RULE_ASCII_ANY_CHAR_ELM))
|
||||||
#define RULE_IS_KEYWORDS_NODE(node__) (RULE_IS__(node__, RULE_KEYWORDS_ELM))
|
#define RULE_IS_KEYWORDS_NODE(node__) (RULE_IS__(node__, RULE_KEYWORDS_ELM))
|
||||||
#define RULE_IS_INCLUDE_NODE(node__) (RULE_IS__(node__, RULE_INCLUDE_RULES_ELM))
|
#define RULE_IS_INCLUDE_NODE(node__) (RULE_IS__(node__, RULE_INCLUDE_RULES_ELM))
|
||||||
|
#define RULE_IS_INT_NODE(node__) (RULE_IS__(node__, RULE_INT_ELM))
|
||||||
|
|
||||||
|
|
||||||
static RuleXML*
|
static RuleXML*
|
||||||
|
@ -1344,6 +1348,11 @@ rule_xml_parse (LangXML *lang_xml,
|
||||||
xml = rule_include_xml_parse (lang_xml, node);
|
xml = rule_include_xml_parse (lang_xml, node);
|
||||||
if (xml) xml->type = MOO_RULE_INCLUDE;
|
if (xml) xml->type = MOO_RULE_INCLUDE;
|
||||||
}
|
}
|
||||||
|
else if (RULE_IS_INT_NODE (node))
|
||||||
|
{
|
||||||
|
xml = rule_int_xml_parse (node);
|
||||||
|
if (xml) xml->type = MOO_RULE_INT;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_warning ("%s: invalid rule type '%s'", G_STRLOC, node->name);
|
g_warning ("%s: invalid rule type '%s'", G_STRLOC, node->name);
|
||||||
|
@ -1523,6 +1532,9 @@ moo_rule_new_from_xml (RuleXML *xml,
|
||||||
case MOO_RULE_INCLUDE:
|
case MOO_RULE_INCLUDE:
|
||||||
rule = rule_include_xml_create_rule ((RuleIncludeXML*) xml, lang);
|
rule = rule_include_xml_create_rule ((RuleIncludeXML*) xml, lang);
|
||||||
break;
|
break;
|
||||||
|
case MOO_RULE_INT:
|
||||||
|
rule = rule_int_xml_create_rule (xml);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rule)
|
if (!rule)
|
||||||
|
@ -1597,6 +1609,9 @@ rule_xml_free (RuleXML *xml)
|
||||||
case MOO_RULE_INCLUDE:
|
case MOO_RULE_INCLUDE:
|
||||||
rule_include_xml_free ((RuleIncludeXML*) xml);
|
rule_include_xml_free ((RuleIncludeXML*) xml);
|
||||||
break;
|
break;
|
||||||
|
case MOO_RULE_INT:
|
||||||
|
rule_int_xml_free ((RuleIncludeXML*) xml);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1736,6 +1751,22 @@ rule_char_xml_create_rule (RuleCharXML *xml)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static RuleXML*
|
||||||
|
rule_int_xml_parse (xmlNode *node)
|
||||||
|
{
|
||||||
|
g_assert (RULE_IS_INT_NODE (node));
|
||||||
|
return g_new0 (RuleXML, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static MooRule*
|
||||||
|
rule_int_xml_create_rule (RuleXML *xml)
|
||||||
|
{
|
||||||
|
return moo_rule_int_new (rule_xml_get_flags (xml),
|
||||||
|
rule_xml_get_style (xml));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static RuleXML*
|
static RuleXML*
|
||||||
rule_2char_xml_parse (xmlNode *node)
|
rule_2char_xml_parse (xmlNode *node)
|
||||||
{
|
{
|
||||||
|
|
|
@ -59,6 +59,9 @@ static gboolean match_any_char (MooRuleAnyChar *rule,
|
||||||
MatchData *data,
|
MatchData *data,
|
||||||
MatchResult *result,
|
MatchResult *result,
|
||||||
MatchFlags flags);
|
MatchFlags flags);
|
||||||
|
static gboolean match_int (MatchData *data,
|
||||||
|
MatchResult *result,
|
||||||
|
MatchFlags flags);
|
||||||
static MooRule *match_include (MooRuleInclude *rule,
|
static MooRule *match_include (MooRuleInclude *rule,
|
||||||
MatchData *data,
|
MatchData *data,
|
||||||
MatchResult *result,
|
MatchResult *result,
|
||||||
|
@ -66,10 +69,7 @@ static MooRule *match_include (MooRuleInclude *rule,
|
||||||
|
|
||||||
static void rule_string_destroy (MooRuleString *rule);
|
static void rule_string_destroy (MooRuleString *rule);
|
||||||
static void rule_regex_destroy (MooRuleRegex *rule);
|
static void rule_regex_destroy (MooRuleRegex *rule);
|
||||||
static void rule_char_destroy (MooRuleChar *rule);
|
|
||||||
static void rule_2char_destroy (MooRule2Char *rule);
|
|
||||||
static void rule_any_char_destroy (MooRuleAnyChar *rule);
|
static void rule_any_char_destroy (MooRuleAnyChar *rule);
|
||||||
static void rule_include_destroy(MooRuleInclude *rule);
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -201,6 +201,9 @@ rules_match_real (MooRuleArray *array,
|
||||||
case MOO_RULE_ASCII_ANY_CHAR:
|
case MOO_RULE_ASCII_ANY_CHAR:
|
||||||
found = match_any_char (&rule->anychar, data, &tmp, flags);
|
found = match_any_char (&rule->anychar, data, &tmp, flags);
|
||||||
break;
|
break;
|
||||||
|
case MOO_RULE_INT:
|
||||||
|
found = match_int (data, &tmp, flags);
|
||||||
|
break;
|
||||||
case MOO_RULE_INCLUDE:
|
case MOO_RULE_INCLUDE:
|
||||||
matched_here = match_include (&rule->incl, data, &tmp, flags);
|
matched_here = match_include (&rule->incl, data, &tmp, flags);
|
||||||
found = (matched_here != NULL);
|
found = (matched_here != NULL);
|
||||||
|
@ -304,6 +307,7 @@ rule_new (MooRuleType type,
|
||||||
case MOO_RULE_ASCII_2CHAR:
|
case MOO_RULE_ASCII_2CHAR:
|
||||||
case MOO_RULE_ASCII_ANY_CHAR:
|
case MOO_RULE_ASCII_ANY_CHAR:
|
||||||
case MOO_RULE_INCLUDE:
|
case MOO_RULE_INCLUDE:
|
||||||
|
case MOO_RULE_INT:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MOO_RULE_KEYWORDS:
|
case MOO_RULE_KEYWORDS:
|
||||||
|
@ -336,18 +340,13 @@ moo_rule_free (MooRule *rule)
|
||||||
case MOO_RULE_REGEX:
|
case MOO_RULE_REGEX:
|
||||||
rule_regex_destroy (&rule->regex);
|
rule_regex_destroy (&rule->regex);
|
||||||
break;
|
break;
|
||||||
case MOO_RULE_ASCII_CHAR:
|
|
||||||
rule_char_destroy (&rule->_char);
|
|
||||||
break;
|
|
||||||
case MOO_RULE_ASCII_2CHAR:
|
|
||||||
rule_2char_destroy (&rule->_2char);
|
|
||||||
break;
|
|
||||||
case MOO_RULE_ASCII_ANY_CHAR:
|
case MOO_RULE_ASCII_ANY_CHAR:
|
||||||
rule_any_char_destroy (&rule->anychar);
|
rule_any_char_destroy (&rule->anychar);
|
||||||
break;
|
break;
|
||||||
|
case MOO_RULE_ASCII_CHAR:
|
||||||
|
case MOO_RULE_ASCII_2CHAR:
|
||||||
case MOO_RULE_INCLUDE:
|
case MOO_RULE_INCLUDE:
|
||||||
rule_include_destroy (&rule->incl);
|
case MOO_RULE_INT:
|
||||||
break;
|
|
||||||
case MOO_RULE_KEYWORDS:
|
case MOO_RULE_KEYWORDS:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -656,18 +655,6 @@ moo_rule_2char_new (char ch1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
rule_char_destroy (G_GNUC_UNUSED MooRuleChar *rule)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
rule_2char_destroy (G_GNUC_UNUSED MooRule2Char *rule)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
match_char (MooRuleChar *rule,
|
match_char (MooRuleChar *rule,
|
||||||
MatchData *data,
|
MatchData *data,
|
||||||
|
@ -901,7 +888,59 @@ match_include (MooRuleInclude *rule,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
/*************************************************************************/
|
||||||
rule_include_destroy (G_GNUC_UNUSED MooRuleInclude *rule)
|
/* Special sequences
|
||||||
|
*/
|
||||||
|
|
||||||
|
MooRule*
|
||||||
|
moo_rule_int_new (MooRuleFlags flags,
|
||||||
|
const char *style)
|
||||||
{
|
{
|
||||||
|
return rule_new (MOO_RULE_INT, flags, style);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define ISDIGIT(c__) (c__ >= '0' && c__ <= '9')
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
match_int (MatchData *data,
|
||||||
|
MatchResult *result,
|
||||||
|
MatchFlags flags)
|
||||||
|
{
|
||||||
|
if (flags & MATCH_START_ONLY)
|
||||||
|
{
|
||||||
|
if (ISDIGIT(data->start[0]))
|
||||||
|
{
|
||||||
|
guint i;
|
||||||
|
for (i = 1; ISDIGIT(data->start[i]); ++i) ;
|
||||||
|
result->match_start = data->start;
|
||||||
|
result->match_end = result->match_start + i;
|
||||||
|
result->match_len = i;
|
||||||
|
result->match_offset = -1;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
for (i = 0; data->start[i] && !ISDIGIT(data->start[i]); ++i) ;
|
||||||
|
|
||||||
|
if (!data->start[i])
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
result->match_start = data->start + i;
|
||||||
|
|
||||||
|
for ( ; ISDIGIT(data->start[i]); ++i) ;
|
||||||
|
|
||||||
|
result->match_end = result->match_start + i;
|
||||||
|
result->match_len = result->match_end - result->match_start;
|
||||||
|
result->match_offset = -1;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,8 @@ MooRule *moo_rule_2char_new (char ch1,
|
||||||
MooRule *moo_rule_any_char_new (const char *string,
|
MooRule *moo_rule_any_char_new (const char *string,
|
||||||
MooRuleFlags flags,
|
MooRuleFlags flags,
|
||||||
const char *style);
|
const char *style);
|
||||||
|
MooRule *moo_rule_int_new (MooRuleFlags flags,
|
||||||
|
const char *style);
|
||||||
MooRule *moo_rule_keywords_new (GSList *words,
|
MooRule *moo_rule_keywords_new (GSList *words,
|
||||||
MooRuleFlags flags,
|
MooRuleFlags flags,
|
||||||
const char *style);
|
const char *style);
|
||||||
|
|
|
@ -108,6 +108,7 @@
|
||||||
#define RULE_ASCII_2CHAR_ELM "TwoChars"
|
#define RULE_ASCII_2CHAR_ELM "TwoChars"
|
||||||
#define RULE_ASCII_ANY_CHAR_ELM "AnyChar"
|
#define RULE_ASCII_ANY_CHAR_ELM "AnyChar"
|
||||||
#define RULE_KEYWORDS_ELM "Keyword"
|
#define RULE_KEYWORDS_ELM "Keyword"
|
||||||
|
#define RULE_INT_ELM "Int"
|
||||||
|
|
||||||
#define RULE_STRING_STRING_PROP "string"
|
#define RULE_STRING_STRING_PROP "string"
|
||||||
#define RULE_REGEX_PATTERN_PROP "pattern"
|
#define RULE_REGEX_PATTERN_PROP "pattern"
|
||||||
|
|
|
@ -104,6 +104,7 @@ typedef enum {
|
||||||
MOO_RULE_ASCII_CHAR,
|
MOO_RULE_ASCII_CHAR,
|
||||||
MOO_RULE_ASCII_2CHAR,
|
MOO_RULE_ASCII_2CHAR,
|
||||||
MOO_RULE_ASCII_ANY_CHAR,
|
MOO_RULE_ASCII_ANY_CHAR,
|
||||||
|
MOO_RULE_INT,
|
||||||
MOO_RULE_KEYWORDS,
|
MOO_RULE_KEYWORDS,
|
||||||
MOO_RULE_INCLUDE
|
MOO_RULE_INCLUDE
|
||||||
} MooRuleType;
|
} MooRuleType;
|
||||||
|
|
Loading…
Reference in New Issue