got parsing working using PCRE; updated testinput.i
This commit is contained in:
parent
42ada6ee17
commit
1ae6878fb1
@ -43,6 +43,8 @@ bool parse_input(char * buff, int size)
|
||||
sections["tokens"] = tokens;
|
||||
sections["rules"] = rules;
|
||||
Section section = none;
|
||||
string line;
|
||||
bool append_line = false;
|
||||
|
||||
for (int i = 0; i < sizeof(exprs)/sizeof(exprs[0]); i++)
|
||||
{
|
||||
@ -64,16 +66,36 @@ bool parse_input(char * buff, int size)
|
||||
{
|
||||
line_length--;
|
||||
}
|
||||
string line(input, line_length);
|
||||
if (pcre_exec(empty, NULL, line.c_str(), line.size(), 0, 0,
|
||||
ovector, ovec_size) == 0)
|
||||
continue;
|
||||
if (pcre_exec(comment, NULL, line.c_str(), line.size(), 0, 0,
|
||||
ovector, ovec_size) == 0)
|
||||
continue;
|
||||
if (pcre_exec(section_name, NULL, line.c_str(), line.size(), 0, 0,
|
||||
ovector, ovec_size) == 0)
|
||||
if (append_line)
|
||||
{
|
||||
line += string(input, line_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
line = string(input, line_length);
|
||||
}
|
||||
if (line.size() > 0 && line[line.size()-1] == '\\')
|
||||
{
|
||||
line[line.size()-1] = ' ';
|
||||
append_line = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
append_line = false;
|
||||
}
|
||||
if ( append_line
|
||||
|| (pcre_exec(empty, NULL, line.c_str(), line.size(),
|
||||
0, 0, ovector, ovec_size) >= 0)
|
||||
|| (pcre_exec(comment, NULL, line.c_str(), line.size(),
|
||||
0, 0, ovector, ovec_size) >= 0)
|
||||
)
|
||||
{
|
||||
/* nothing */;
|
||||
}
|
||||
else if (pcre_exec(section_name, NULL, line.c_str(), line.size(),
|
||||
0, 0, ovector, ovec_size) >= 0)
|
||||
{
|
||||
sn = string(input, ovector[2], ovector[3] - ovector[2]);
|
||||
if (sections.find(sn) != sections.end())
|
||||
{
|
||||
section = sections[sn];
|
||||
@ -83,16 +105,17 @@ bool parse_input(char * buff, int size)
|
||||
cerr << "Unknown section name '" << sn << "'!" << endl;
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (section)
|
||||
{
|
||||
case none:
|
||||
cerr << "Unrecognized input on line " << lineno << endl;
|
||||
return false;
|
||||
case tokens:
|
||||
if (pcre_exec(token, NULL, line.c_str(), line.size(), 0, 0,
|
||||
ovector, ovec_size) == 0)
|
||||
if (pcre_exec(token, NULL, line.c_str(), line.size(),
|
||||
0, 0, ovector, ovec_size) >= 0)
|
||||
{
|
||||
string name(line, ovector[2], ovector[3] - ovector[2]);
|
||||
string definition(line,
|
||||
@ -112,8 +135,8 @@ bool parse_input(char * buff, int size)
|
||||
}
|
||||
break;
|
||||
case rules:
|
||||
if (pcre_exec(rule, NULL, line.c_str(), line.size(), 0, 0,
|
||||
ovector, ovec_size) == 0)
|
||||
if (pcre_exec(rule, NULL, line.c_str(), line.size(),
|
||||
0, 0, ovector, ovec_size) >= 0)
|
||||
{
|
||||
string name(line, ovector[2], ovector[3] - ovector[2]);
|
||||
string definition(line,
|
||||
@ -127,7 +150,10 @@ bool parse_input(char * buff, int size)
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
input = newline + 1;
|
||||
lineno++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
|
||||
[tokens]
|
||||
|
||||
ASSIGN := ":="
|
||||
DASSIGN := ":=="
|
||||
IDENTIFIER := "[a-zA-Z_][a-zA-Z_0-9]*"
|
||||
ASSIGN :=
|
||||
DASSIGN :==
|
||||
IDENTIFIER [a-zA-Z_][a-zA-Z_0-9]*
|
||||
|
||||
[rules]
|
||||
|
||||
Assignment := IDENTIFIER ASSIGN Expression
|
||||
|
||||
Expression := IDENTIFIER
|
||||
Expression := IDENTIFIER \
|
||||
| Assignment
|
||||
|
Loading…
x
Reference in New Issue
Block a user