summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustyna Ilczuk <justyna.ilczuk@gmail.com>2012-12-16 10:36:19 +0100
committerJustyna Ilczuk <justyna.ilczuk@gmail.com>2012-12-16 10:36:19 +0100
commitcc0a923959fadb76895a2f4f4fcc6445cb1eb536 (patch)
tree6b8e1ca1702a1ab373a1e3cbcfa0377b5f99b535
parent9e1b5fa9110c633f0765cb0cc518b24b97525519 (diff)
downloadsencha-lang-cc0a923959fadb76895a2f4f4fcc6445cb1eb536.tar.gz
sencha-lang-cc0a923959fadb76895a2f4f4fcc6445cb1eb536.tar.bz2
sencha-lang-cc0a923959fadb76895a2f4f4fcc6445cb1eb536.tar.xz
sencha-lang-cc0a923959fadb76895a2f4f4fcc6445cb1eb536.zip
Simple unescaping strins.
-rw-r--r--Sencha-lang/Lexer.cpp48
-rw-r--r--Sencha-lang/Lexer.h1
2 files changed, 48 insertions, 1 deletions
diff --git a/Sencha-lang/Lexer.cpp b/Sencha-lang/Lexer.cpp
index d77a61d..960e232 100644
--- a/Sencha-lang/Lexer.cpp
+++ b/Sencha-lang/Lexer.cpp
@@ -16,6 +16,50 @@ Lexer::~Lexer()
{
//dtor
}
+
+std::string Lexer::unescape_string(string text)
+{
+ std::string result = text;
+ unsigned int offset = 0;
+ for(unsigned int i = 0; i < text.size(); i++)
+ {
+ char replacement = 0;
+ if(text[i] == '\\')
+ {
+ switch (text[i+1])
+ {
+ case 'n':
+ replacement = '\n';
+ break;
+ case 'r':
+ replacement = '\r';
+ break;
+ case 't':
+ replacement = '\t';
+ break;
+ case '[':
+ replacement = 27;
+ break;
+
+ }
+
+ }
+ if(replacement != 0)
+ {
+ char replacement_chars[2];
+ replacement_chars[0] = replacement;
+ replacement_chars[1] = 0;
+
+ std::cout << result << " escaping..." << replacement_chars << std::endl;
+ result.replace(i + offset, 2, replacement_chars);
+ offset--;
+ std::cout << result << " escaped..." << std::endl;
+ }
+
+
+ }
+ return result;
+}
void Lexer::add_keyword(string word)
{
@@ -125,8 +169,10 @@ pair<string, Token> Lexer::parse_token(string line)
else break;
}
+ auto type = guess_type(token_value);
+ if(type == t_literal) token_value = unescape_string(token_value);
- Token token = Token(guess_type(token_value), token_value);
+ Token token = Token(type, token_value);
string truncated_line = line.substr(i);
return pair<string, Token>(truncated_line, token);
diff --git a/Sencha-lang/Lexer.h b/Sencha-lang/Lexer.h
index 5fe5c7c..cd3db82 100644
--- a/Sencha-lang/Lexer.h
+++ b/Sencha-lang/Lexer.h
@@ -18,6 +18,7 @@ class Lexer
void add_keyword(string word);
void add_punctuation_char(char c);
void add_operator(string oper);
+ string unescape_string(string text);
vector<Token> parse_line(string line);
pair<string, Token> parse_token(string line);