gutted parse_input() to fix compilation
This commit is contained in:
parent
1dccdd1013
commit
a78b3af9f8
17
imbecile.cc
17
imbecile.cc
@ -4,8 +4,6 @@
|
||||
#include <getopt.h>
|
||||
#include <iconv.h>
|
||||
#include "refptr/refptr.h"
|
||||
#include "serialize.h"
|
||||
#include "unicode.h"
|
||||
#include "parse-input.h"
|
||||
using namespace std;
|
||||
|
||||
@ -38,14 +36,15 @@ int main(int argc, char * argv[])
|
||||
cerr << "Error opening input file: '" << argv[optind] << "'";
|
||||
return 2;
|
||||
}
|
||||
refptr< vector<unichar_t> > ucs = deserialize(encoding, ifs);
|
||||
if (ucs.isNull())
|
||||
{
|
||||
cerr << "Error deserializing input file." << endl;
|
||||
return 1;
|
||||
}
|
||||
ifs.seekg(0, ios_base::end);
|
||||
int size = ifs.tellg();
|
||||
ifs.seekg(0, ios_base::beg);
|
||||
char * buff = new char[size];
|
||||
ifs.read(buff, size);
|
||||
|
||||
parse_input(ucs);
|
||||
parse_input(buff, size);
|
||||
|
||||
ifs.close();
|
||||
delete[] buff;
|
||||
return 0;
|
||||
}
|
||||
|
173
parse-input.cc
173
parse-input.cc
@ -1,5 +1,4 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h> /* isspace() */
|
||||
#include "parse-input.h"
|
||||
@ -11,176 +10,6 @@ using namespace std;
|
||||
sprintf(errstr, err " at line %d, column %d", ##args, lineno, colno); \
|
||||
} while(0)
|
||||
|
||||
void parse_input(refptr< vector<unichar_t> > ucs)
|
||||
{
|
||||
enum State { INITIAL, SECTION_NAME, RULES, RULE_NAME,
|
||||
RULE_EQUALS, RULE_RHS, TOKENS, TOKEN_NAME, TOKEN_EQUALS, TOKEN_RHS };
|
||||
State state = INITIAL;
|
||||
int lineno = 1;
|
||||
int colno = 1;
|
||||
bool error = false;
|
||||
char errstr[200];
|
||||
unistring build_str;
|
||||
struct { unistring name; unistring rhs; } rule;
|
||||
struct { unistring name; unistring rhs; } token;
|
||||
|
||||
for (int i = 0, sz = ucs->size(); i < sz; i++)
|
||||
{
|
||||
unichar_t c = (*ucs)[i];
|
||||
switch (state)
|
||||
{
|
||||
case INITIAL:
|
||||
if (c == '[')
|
||||
{
|
||||
state = SECTION_NAME;
|
||||
build_str = "";
|
||||
}
|
||||
else if (isspace(c))
|
||||
void parse_input(char * buff, int size)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_ERROR("Unexpected character 0x%x (%c) in input file",
|
||||
c, c);
|
||||
}
|
||||
break;
|
||||
case SECTION_NAME:
|
||||
switch (c)
|
||||
{
|
||||
case ']':
|
||||
if (build_str == "rules")
|
||||
{
|
||||
state = RULES;
|
||||
}
|
||||
else if (build_str == "tokens")
|
||||
{
|
||||
state = TOKENS;
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_ERROR("Unknown section name");
|
||||
}
|
||||
break;
|
||||
case '\n':
|
||||
SET_ERROR("Unterminated section header");
|
||||
break;
|
||||
default:
|
||||
build_str += c;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case RULES:
|
||||
if (c == '[')
|
||||
{
|
||||
state = SECTION_NAME;
|
||||
build_str = "";
|
||||
}
|
||||
else if (isspace(c))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
build_str = "";
|
||||
build_str += c;
|
||||
state = RULE_NAME;
|
||||
}
|
||||
break;
|
||||
case RULE_NAME:
|
||||
if (c == ':')
|
||||
{
|
||||
rule.name = build_str;
|
||||
build_str = "";
|
||||
state = RULE_EQUALS;
|
||||
}
|
||||
else
|
||||
{
|
||||
build_str += c;
|
||||
}
|
||||
break;
|
||||
case RULE_EQUALS:
|
||||
if (c == '=')
|
||||
{
|
||||
state = RULE_RHS;
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_ERROR("Expected '='");
|
||||
}
|
||||
break;
|
||||
case RULE_RHS:
|
||||
if (c == '\n')
|
||||
{
|
||||
rule.rhs = build_str;
|
||||
state = RULES;
|
||||
}
|
||||
else
|
||||
{
|
||||
build_str += c;
|
||||
}
|
||||
break;
|
||||
case TOKENS:
|
||||
if (c == '[')
|
||||
{
|
||||
state = SECTION_NAME;
|
||||
build_str = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
build_str = "";
|
||||
build_str += c;
|
||||
state = TOKEN_NAME;
|
||||
}
|
||||
break;
|
||||
case TOKEN_NAME:
|
||||
if (c == ':')
|
||||
{
|
||||
state = TOKEN_EQUALS;
|
||||
}
|
||||
else
|
||||
{
|
||||
build_str += c;
|
||||
}
|
||||
break;
|
||||
case TOKEN_EQUALS:
|
||||
if (c == '=')
|
||||
{
|
||||
token.name = build_str;
|
||||
build_str = "";
|
||||
state = TOKEN_RHS;
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_ERROR("Expected '='");
|
||||
}
|
||||
break;
|
||||
case TOKEN_RHS:
|
||||
if (c == '\n')
|
||||
{
|
||||
token.rhs = build_str;
|
||||
state = RULES;
|
||||
}
|
||||
else
|
||||
{
|
||||
build_str += c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* update line and column position information */
|
||||
if (c == '\n')
|
||||
{
|
||||
lineno++;
|
||||
colno = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
colno++;
|
||||
}
|
||||
|
||||
if (error)
|
||||
{
|
||||
cerr << errstr << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include "refptr/refptr.h"
|
||||
#include "unicode.h"
|
||||
|
||||
void parse_input(refptr< std::vector<unichar_t> > ucs);
|
||||
void parse_input(char * buff, int size);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user