From 68a4bf6240a1ddf7b75f8b61d1f000be5d0102b1 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 1 Apr 2010 22:33:30 -0400 Subject: [PATCH] added unistring::operator+=(), working on parser more --- parse-input.cc | 68 +++++++++++++++++++++++++++++++++++++++++++++++++- unicode.cc | 6 +++++ unicode.h | 1 + 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/parse-input.cc b/parse-input.cc index 1a449aa..3062cd0 100644 --- a/parse-input.cc +++ b/parse-input.cc @@ -14,7 +14,8 @@ using namespace std; void parse_input(refptr< vector > ucs) { - enum State { INITIAL, SECTION_NAME, RULES }; + enum State { INITIAL, SECTION_NAME, RULES, RULE_NAME, RULE_COLON, + RULE_EQUALS, RULE_RHS }; State state = INITIAL; int lineno = 1; int colno = 1; @@ -69,6 +70,71 @@ void parse_input(refptr< vector > ucs) break; } break; + case RULES: + if (isspace(c)) + { + } + else if ( ('a' <= c && c <= 'z') + || ('A' <= c && c <= 'Z') + || (c == '_') ) + { + build_str = ""; + build_str += c; + state = RULE_NAME; + } + else + { + SET_ERROR("Unexpected character"); + } + break; + case RULE_NAME: + if ( ('a' <= c && c <= 'z') + || ('A' <= c && c <= 'Z') + || ('0' <= c && c <= '9') + || (c == '_') ) + { + build_str += c; + } + else if (isspace(c)) + { + state = RULE_COLON; + } + else + { + SET_ERROR("Expected ':='"); + } + break; + case RULE_COLON: + if (isspace(c)) + { + } + else if (c == ':') + { + state = RULE_EQUALS; + } + else + { + SET_ERROR("Expected ':='"); + } + break; + case RULE_EQUALS: + if (c == '=') + { + state = RULE_RHS; + } + else + { + SET_ERROR("Expected '='"); + } + break; + case RULE_RHS: + break; + } + + if (error) + { + cerr << errstr << endl; + break; } } } diff --git a/unicode.cc b/unicode.cc index bff58b5..480cdd5 100644 --- a/unicode.cc +++ b/unicode.cc @@ -13,6 +13,12 @@ unistring & unistring::operator=(const char * ascii_str) return *this; } +unistring & unistring::operator+=(const unichar_t c) +{ + chars.push_back(c); + return *this; +} + bool unistring::operator==(const char * ascii_str) { int len = chars.size(); diff --git a/unicode.h b/unicode.h index e161819..57acdf2 100644 --- a/unicode.h +++ b/unicode.h @@ -10,6 +10,7 @@ class unistring { public: unistring & operator=(const char * ascii_str); + unistring & operator+=(const unichar_t c); bool operator==(const char * ascii_str); protected: