summaryrefslogtreecommitdiffstats
path: root/Sencha-lang/Lexer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Sencha-lang/Lexer.cpp')
-rw-r--r--Sencha-lang/Lexer.cpp63
1 files changed, 22 insertions, 41 deletions
diff --git a/Sencha-lang/Lexer.cpp b/Sencha-lang/Lexer.cpp
index 681e927..02caa44 100644
--- a/Sencha-lang/Lexer.cpp
+++ b/Sencha-lang/Lexer.cpp
@@ -107,21 +107,15 @@ pair<string, Token> Lexer::parse_token(string line)
for(i=0; i< line.size(); i++)
{
- if(token_value == "" && isspace(line[i])) continue;
+ if(token_value == "" && isspace(line[i])) continue;
- if(isdigit(line[i]))
+ if(isdigit(line[i]) || line[i] == '-')
{
token_value += line[i++];
for(; i < line.size(); i++)
{
- if(isdigit(line[i]) || line[i] == '.')
- {
- token_value += line[i];
- }
- else
- {
- break;
- }
+ if(isdigit(line[i]) || line[i] == '.') token_value += line[i];
+ else break;
}
}
@@ -137,14 +131,8 @@ pair<string, Token> Lexer::parse_token(string line)
break;
}
}
- }
-
- if(isalnum(line[i]) || line[i]== '_')
- {
- token_value += line[i];
-
- }
-
+ }
+ if(isalnum(line[i]) || line[i]== '_') token_value += line[i];
else if(ispunct(line[i]))
{
if(token_value=="")
@@ -161,17 +149,13 @@ pair<string, Token> Lexer::parse_token(string line)
}
}
break;
- }
-
-
+ }
else break;
}
auto type = guess_type(token_value);
- if(type == t_literal) token_value = unescape_string(token_value);
-
+ if(type == t_literal) token_value = unescape_string(token_value);
Token token = Token(type, token_value);
string truncated_line = line.substr(i);
-
return pair<string, Token>(truncated_line, token);
}
@@ -209,14 +193,24 @@ type_of_token Lexer::guess_type(string value)
typedef enum { t_invalid_token=0, t_symbol, t_integer, t_literal,
t_punctuation, t_keyword } type_of_token;
- */
+ */
+
+ if(value == "") return t_invalid_token;
+ if(value.size() == 1 )
+ {
+ if(is_punctuation(value[0])) return t_punctuation;
+ else
+ {
+ if(is_operator(value)) return t_operator;
+ }
+ }
+ if(value.size() == 2 && is_operator(value)) return t_operator;
- if(value == "") return t_invalid_token;
- if(isdigit(value[0]))
+ if(isdigit(value[0]) || value[0] == '-')
{
bool is_number = true;
bool dot_used = false;
- for(unsigned int i=0; i<value.size(); i++)
+ for(unsigned int i=1; i<value.size(); i++)
{
if(value[i] == '.')
{
@@ -242,25 +236,12 @@ type_of_token Lexer::guess_type(string value)
{
if(is_keyword(value)) return t_keyword;
else return t_symbol;
-
}
-
if(value[0]=='\"')
{
if(value[value.size()-1] == '\"') return t_literal;
else return t_invalid_token;
}
-
- if(value.size() == 1 )
- {
- if(is_punctuation(value[0])) return t_punctuation;
- else
- {
- if(is_operator(value)) return t_operator;
- }
- }
- if(value.size() == 2 && is_operator(value)) return t_operator;
-
//If any...
return t_invalid_token;
}