aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'edify/lexer.ll')
-rw-r--r--edify/lexer.ll24
1 files changed, 11 insertions, 13 deletions
diff --git a/edify/lexer.ll b/edify/lexer.ll
index fb2933be..b764d169 100644
--- a/edify/lexer.ll
+++ b/edify/lexer.ll
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <string.h> 18#include <string.h>
19#include <string>
19 20
20#include "expr.h" 21#include "expr.h"
21#include "yydefs.h" 22#include "yydefs.h"
@@ -25,9 +26,7 @@ int gLine = 1;
25int gColumn = 1; 26int gColumn = 1;
26int gPos = 0; 27int gPos = 0;
27 28
28// TODO: enforce MAX_STRING_LEN during lexing 29std::string string_buffer;
29char string_buffer[MAX_STRING_LEN];
30char* string_pos;
31 30
32#define ADVANCE do {yylloc.start=gPos; yylloc.end=gPos+yyleng; \ 31#define ADVANCE do {yylloc.start=gPos; yylloc.end=gPos+yyleng; \
33 gColumn+=yyleng; gPos+=yyleng;} while(0) 32 gColumn+=yyleng; gPos+=yyleng;} while(0)
@@ -43,7 +42,7 @@ char* string_pos;
43 42
44\" { 43\" {
45 BEGIN(STR); 44 BEGIN(STR);
46 string_pos = string_buffer; 45 string_buffer.clear();
47 yylloc.start = gPos; 46 yylloc.start = gPos;
48 ++gColumn; 47 ++gColumn;
49 ++gPos; 48 ++gPos;
@@ -54,36 +53,35 @@ char* string_pos;
54 ++gColumn; 53 ++gColumn;
55 ++gPos; 54 ++gPos;
56 BEGIN(INITIAL); 55 BEGIN(INITIAL);
57 *string_pos = '\0'; 56 yylval.str = strdup(string_buffer.c_str());
58 yylval.str = strdup(string_buffer);
59 yylloc.end = gPos; 57 yylloc.end = gPos;
60 return STRING; 58 return STRING;
61 } 59 }
62 60
63 \\n { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\n'; } 61 \\n { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\n'); }
64 \\t { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\t'; } 62 \\t { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\t'); }
65 \\\" { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\"'; } 63 \\\" { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\"'); }
66 \\\\ { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\\'; } 64 \\\\ { gColumn += yyleng; gPos += yyleng; string_buffer.push_back('\\'); }
67 65
68 \\x[0-9a-fA-F]{2} { 66 \\x[0-9a-fA-F]{2} {
69 gColumn += yyleng; 67 gColumn += yyleng;
70 gPos += yyleng; 68 gPos += yyleng;
71 int val; 69 int val;
72 sscanf(yytext+2, "%x", &val); 70 sscanf(yytext+2, "%x", &val);
73 *string_pos++ = val; 71 string_buffer.push_back(static_cast<char>(val));
74 } 72 }
75 73
76 \n { 74 \n {
77 ++gLine; 75 ++gLine;
78 ++gPos; 76 ++gPos;
79 gColumn = 1; 77 gColumn = 1;
80 *string_pos++ = yytext[0]; 78 string_buffer.push_back(yytext[0]);
81 } 79 }
82 80
83 . { 81 . {
84 ++gColumn; 82 ++gColumn;
85 ++gPos; 83 ++gPos;
86 *string_pos++ = yytext[0]; 84 string_buffer.push_back(yytext[0]);
87 } 85 }
88} 86}
89 87