added STRING token type to parser/lexer, removed unused DQUOTE/SQUOTE tokens

git-svn-id: svn://anubis/fart/trunk@382 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2010-10-13 20:36:56 +00:00
parent b7e2aa1bae
commit 48e2900e1f
2 changed files with 34 additions and 4 deletions

View File

@ -4,14 +4,20 @@
%{ %{
#include <string>
#include "nodes.h" #include "nodes.h"
#include "parser.h" #include "parser.h"
#include "parser.tab.hh" #include "parser.tab.hh"
#define YY_USER_ACTION yylloc->first_column += yyleng; #define YY_USER_ACTION yylloc->first_column += yyleng;
static std::string build_string;
%} %}
%x str
%% %%
\+ return PLUS; \+ return PLUS;
@ -36,8 +42,6 @@
\? return QUESTION; \? return QUESTION;
\$ return DOLLAR; \$ return DOLLAR;
\. return DOT; \. return DOT;
\" return DQUOTE;
\' return SQUOTE;
, return COMMA; , return COMMA;
\{ return LCURLY; \{ return LCURLY;
@ -119,6 +123,33 @@ local return LOCAL;
} }
[ \t\v] /* ignore whitespace */ [ \t\v] /* ignore whitespace */
/* strings */
\" build_string = ""; BEGIN(str);
<str>{
\" {
/* end of the string literal */
BEGIN(INITIAL);
*yylval = new IdentifierNode(build_string);
return STRING;
}
\\x[0-9A-Fa-f]{2} {
/* hexadecimal escape code */
unsigned int val;
(void) sscanf(yytext + 2, "%x", &val);
build_string += (char) val;
}
\\n build_string += '\n';
\\t build_string += '\t';
\\r build_string += '\r';
\\b build_string += '\b';
\\f build_string += '\f';
\\(.|\n) build_string += yytext[1];
[^\\\"]+ build_string += yytext;
}
. return yytext[0]; . return yytext[0];
%% %%

View File

@ -55,8 +55,6 @@ refptr<Scope> parser_scope;
%token QUESTION; %token QUESTION;
%token DOLLAR; %token DOLLAR;
%token DOT; %token DOT;
%token DQUOTE;
%token SQUOTE;
%token COMMA; %token COMMA;
%token LCURLY; %token LCURLY;
@ -67,6 +65,7 @@ refptr<Scope> parser_scope;
%token RPAREN; %token RPAREN;
%token REAL_NUMBER; %token REAL_NUMBER;
%token STRING;
%token AMBIENT; %token AMBIENT;
%token AMBIENT_OCCLUSION; %token AMBIENT_OCCLUSION;