aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_lexer.l
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-17 13:56:22 +1000
committerDavid Walter Seikel2012-01-17 13:56:22 +1000
commit68271c1b714ea927370b86e22489a32fffaedf10 (patch)
tree37fef44ab9684bb497faef72f68ae5024b36068a /LuaSL/src/LuaSL_lexer.l
parentRemove unused debug variable. (diff)
downloadSledjHamr-68271c1b714ea927370b86e22489a32fffaedf10.zip
SledjHamr-68271c1b714ea927370b86e22489a32fffaedf10.tar.gz
SledjHamr-68271c1b714ea927370b86e22489a32fffaedf10.tar.bz2
SledjHamr-68271c1b714ea927370b86e22489a32fffaedf10.tar.xz
Store the lexer provided length.
Diffstat (limited to 'LuaSL/src/LuaSL_lexer.l')
-rw-r--r--LuaSL/src/LuaSL_lexer.l133
1 files changed, 67 insertions, 66 deletions
diff --git a/LuaSL/src/LuaSL_lexer.l b/LuaSL/src/LuaSL_lexer.l
index bb452f3..5945599 100644
--- a/LuaSL/src/LuaSL_lexer.l
+++ b/LuaSL/src/LuaSL_lexer.l
@@ -3,7 +3,7 @@
3#define excludeLexer 3#define excludeLexer
4#include "LuaSL.h" 4#include "LuaSL.h"
5 5
6int common(YYSTYPE *lval, char *text, LuaSL_compiler *compiler, boolean checkIgnorable, int type); 6int common(YYSTYPE *lval, char *text, int len, LuaSL_compiler *compiler, boolean checkIgnorable, int type);
7 7
8%} 8%}
9 9
@@ -31,95 +31,96 @@ STRING \"(\\.|[^\\"\n])*\"
31 /* The order here is important, in mysterious ways. The more specific the lower in case of ambiguities like "floats contain integers". I think, not tested that well yet. */ 31 /* The order here is important, in mysterious ways. The more specific the lower in case of ambiguities like "floats contain integers". I think, not tested that well yet. */
32 32
33 /* Ignorables. */ 33 /* Ignorables. */
34[[:space:]]+ %{ common(yylval, yytext, yyextra, FALSE, LSL_SPACE); %} 34[[:space:]]+ %{ common(yylval, yytext, yyleng, yyextra, FALSE, LSL_SPACE); %}
35 /* Yes I know this will have problems with huge comments, just being simple to get it to work for now. */ 35 /* Yes I know this will have problems with huge comments, just being simple to get it to work for now. */
36"/*"([^"*/"]*)"*/" %{ common(yylval, yytext, yyextra, FALSE, LSL_COMMENT); %} 36"/*"([^"*/"]*)"*/" %{ common(yylval, yytext, yyleng, yyextra, FALSE, LSL_COMMENT); %}
37"//"[^\n]* %{ common(yylval, yytext, yyextra, FALSE, LSL_COMMENT_LINE); %} 37"//"[^\n]* %{ common(yylval, yytext, yyleng, yyextra, FALSE, LSL_COMMENT_LINE); %}
38 38
39 /* Operations. */ 39 /* Operations. */
40"&&" { return common(yylval, yytext, yyextra, TRUE, LSL_BOOL_AND); } 40"&&" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_BOOL_AND); }
41"||" { return common(yylval, yytext, yyextra, TRUE, LSL_BOOL_OR); } 41"||" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_BOOL_OR); }
42"|" { return common(yylval, yytext, yyextra, TRUE, LSL_BIT_OR); } 42"|" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_BIT_OR); }
43"^" { return common(yylval, yytext, yyextra, TRUE, LSL_BIT_XOR); } 43"^" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_BIT_XOR); }
44"&" { return common(yylval, yytext, yyextra, TRUE, LSL_BIT_AND); } 44"&" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_BIT_AND); }
45"!=" { return common(yylval, yytext, yyextra, TRUE, LSL_NOT_EQUAL); } 45"!=" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_NOT_EQUAL); }
46"==" { return common(yylval, yytext, yyextra, TRUE, LSL_EQUAL); } 46"==" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_EQUAL); }
47">=" { return common(yylval, yytext, yyextra, TRUE, LSL_GREATER_EQUAL); } 47">=" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_GREATER_EQUAL); }
48"<=" { return common(yylval, yytext, yyextra, TRUE, LSL_LESS_EQUAL); } 48"<=" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_LESS_EQUAL); }
49">" { return common(yylval, yytext, yyextra, TRUE, LSL_GREATER_THAN); } 49">" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_GREATER_THAN); }
50"<" { return common(yylval, yytext, yyextra, TRUE, LSL_LESS_THAN); } 50"<" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_LESS_THAN); }
51">>" { return common(yylval, yytext, yyextra, TRUE, LSL_RIGHT_SHIFT); } 51">>" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_RIGHT_SHIFT); }
52"<<" { return common(yylval, yytext, yyextra, TRUE, LSL_LEFT_SHIFT); } 52"<<" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_LEFT_SHIFT); }
53"+" { return common(yylval, yytext, yyextra, TRUE, LSL_ADD); } 53"+" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_ADD); }
54"-" { return common(yylval, yytext, yyextra, TRUE, LSL_SUBTRACT); } 54"-" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_SUBTRACT); }
55"*" { return common(yylval, yytext, yyextra, TRUE, LSL_MULTIPLY); } 55"*" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_MULTIPLY); }
56"%" { return common(yylval, yytext, yyextra, TRUE, LSL_MODULO); } 56"%" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_MODULO); }
57"/" { return common(yylval, yytext, yyextra, TRUE, LSL_DIVIDE); } 57"/" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_DIVIDE); }
58"!" { return common(yylval, yytext, yyextra, TRUE, LSL_BOOL_NOT); } 58"!" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_BOOL_NOT); }
59"~" { return common(yylval, yytext, yyextra, TRUE, LSL_BIT_NOT); } 59"~" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_BIT_NOT); }
60"[" { return common(yylval, yytext, yyextra, TRUE, LSL_BRACKET_OPEN); } 60"[" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_BRACKET_OPEN); }
61"]" { return common(yylval, yytext, yyextra, TRUE, LSL_BRACKET_CLOSE); } 61"]" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_BRACKET_CLOSE); }
62"(" { return common(yylval, yytext, yyextra, TRUE, LSL_PARENTHESIS_OPEN); } 62"(" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_PARENTHESIS_OPEN); }
63")" { return common(yylval, yytext, yyextra, TRUE, LSL_PARENTHESIS_CLOSE); } 63")" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_PARENTHESIS_CLOSE); }
64"+=" { return common(yylval, yytext, yyextra, TRUE, LSL_ASSIGNMENT_ADD); } 64"+=" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_ASSIGNMENT_ADD); }
65"-=" { return common(yylval, yytext, yyextra, TRUE, LSL_ASSIGNMENT_SUBTRACT); } 65"-=" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_ASSIGNMENT_SUBTRACT); }
66"*=" { return common(yylval, yytext, yyextra, TRUE, LSL_ASSIGNMENT_MULTIPLY); } 66"*=" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_ASSIGNMENT_MULTIPLY); }
67"%=" { return common(yylval, yytext, yyextra, TRUE, LSL_ASSIGNMENT_MODULO); } 67"%=" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_ASSIGNMENT_MODULO); }
68"/=" { return common(yylval, yytext, yyextra, TRUE, LSL_ASSIGNMENT_DIVIDE); } 68"/=" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_ASSIGNMENT_DIVIDE); }
69"=" { return common(yylval, yytext, yyextra, TRUE, LSL_ASSIGNMENT_PLAIN); } 69"=" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_ASSIGNMENT_PLAIN); }
70"." { return common(yylval, yytext, yyextra, TRUE, LSL_DOT); } 70"." { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_DOT); }
71"--" { return common(yylval, yytext, yyextra, TRUE, LSL_DECREMENT_PRE); } 71"--" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_DECREMENT_PRE); }
72"++" { return common(yylval, yytext, yyextra, TRUE, LSL_INCREMENT_PRE); } 72"++" { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_INCREMENT_PRE); }
73"," { return common(yylval, yytext, yyextra, TRUE, LSL_COMMA); } 73"," { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_COMMA); }
74 74
75 /* Other symbols. */ 75 /* Other symbols. */
76"@" %{ return common(yylval, yytext, yyextra, TRUE, LSL_LABEL); %} 76"@" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_LABEL); %}
77"{" %{ beginBlock(yyextra, yylval); return common(yylval, yytext, yyextra, TRUE, LSL_BLOCK_OPEN); %} 77"{" %{ beginBlock(yyextra, yylval); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_BLOCK_OPEN); %}
78"}" %{ endBlock(yyextra, yylval); return common(yylval, yytext, yyextra, TRUE, LSL_BLOCK_CLOSE); %} 78"}" %{ endBlock(yyextra, yylval); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_BLOCK_CLOSE); %}
79";" %{ return common(yylval, yytext, yyextra, TRUE, LSL_STATEMENT); %} 79";" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_STATEMENT); %}
80 80
81 /* Type keywords. */ 81 /* Type keywords. */
82"float" %{ return common(yylval, yytext, yyextra, TRUE, LSL_TYPE_FLOAT); %} 82"float" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_TYPE_FLOAT); %}
83"integer" %{ return common(yylval, yytext, yyextra, TRUE, LSL_TYPE_INTEGER); %} 83"integer" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_TYPE_INTEGER); %}
84"key" %{ return common(yylval, yytext, yyextra, TRUE, LSL_TYPE_KEY); %} 84"key" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_TYPE_KEY); %}
85"list" %{ return common(yylval, yytext, yyextra, TRUE, LSL_TYPE_LIST); %} 85"list" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_TYPE_LIST); %}
86"quaternion" %{ return common(yylval, yytext, yyextra, TRUE, LSL_TYPE_ROTATION); %} 86"quaternion" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_TYPE_ROTATION); %}
87"rotation" %{ return common(yylval, yytext, yyextra, TRUE, LSL_TYPE_ROTATION); %} 87"rotation" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_TYPE_ROTATION); %}
88"string" %{ return common(yylval, yytext, yyextra, TRUE, LSL_TYPE_STRING); %} 88"string" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_TYPE_STRING); %}
89"vector" %{ return common(yylval, yytext, yyextra, TRUE, LSL_TYPE_VECTOR); %} 89"vector" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_TYPE_VECTOR); %}
90 90
91 /* Statement keywords. */ 91 /* Statement keywords. */
92"do" %{ return common(yylval, yytext, yyextra, TRUE, LSL_DO); %} 92"do" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_DO); %}
93"for" %{ return common(yylval, yytext, yyextra, TRUE, LSL_FOR); %} 93"for" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_FOR); %}
94"else" %{ return common(yylval, yytext, yyextra, TRUE, LSL_ELSE); %} 94"else" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_ELSE); %}
95"if" %{ return common(yylval, yytext, yyextra, TRUE, LSL_IF); %} 95"if" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_IF); %}
96"jump" %{ return common(yylval, yytext, yyextra, TRUE, LSL_JUMP); %} 96"jump" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_JUMP); %}
97"return" %{ return common(yylval, yytext, yyextra, TRUE, LSL_RETURN); %} 97"return" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_RETURN); %}
98"state" %{ return common(yylval, yytext, yyextra, TRUE, LSL_STATE_CHANGE); %} 98"state" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_STATE_CHANGE); %}
99"while" %{ return common(yylval, yytext, yyextra, TRUE, LSL_WHILE); %} 99"while" %{ return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_WHILE); %}
100 100
101{IDENTIFIER} %{ yylval->value.stringValue = strdup(yytext); return common(yylval, yytext, yyextra, TRUE, LSL_IDENTIFIER); %} 101{IDENTIFIER} %{ yylval->value.stringValue = strdup(yytext); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_IDENTIFIER); %}
102 102
103 /* Types. */ 103 /* Types. */
104{INTEGER} %{ yylval->value.integerValue = atoi(yytext); return common(yylval, yytext, yyextra, TRUE, LSL_INTEGER); %} 104{INTEGER} %{ yylval->value.integerValue = atoi(yytext); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_INTEGER); %}
105{FLOAT} %{ yylval->value.floatValue = atof(yytext); return common(yylval, yytext, yyextra, TRUE, LSL_FLOAT); %} 105{FLOAT} %{ yylval->value.floatValue = atof(yytext); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_FLOAT); %}
106{KEY} %{ yylval->value.stringValue = strdup(yytext); return common(yylval, yytext, yyextra, TRUE, LSL_KEY); %} 106{KEY} %{ yylval->value.stringValue = strdup(yytext); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_KEY); %}
107{STRING} %{ yylval->value.stringValue = strdup(yytext); return common(yylval, yytext, yyextra, TRUE, LSL_STRING); %} 107{STRING} %{ yylval->value.stringValue = strdup(yytext); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_STRING); %}
108 108
109<<EOF>> { return common(yylval, yytext, yyextra, TRUE, LSL_SCRIPT); } 109<<EOF>> { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_SCRIPT); }
110 110
111 /* Everything else */ 111 /* Everything else */
112. %{ printf(" unexpected character.\n"); yylval->value.unknownValue = strdup(yytext); common(yylval, yytext, yyextra, TRUE, LSL_UNKNOWN); %} 112. %{ printf(" unexpected character.\n"); yylval->value.unknownValue = strdup(yytext); common(yylval, yytext, yyleng, yyextra, TRUE, LSL_UNKNOWN); %}
113 113
114%% 114%%
115 115
116int common(YYSTYPE *lval, char *text, LuaSL_compiler *compiler, boolean checkIgnorable, int type) 116int common(YYSTYPE *lval, char *text, int len, LuaSL_compiler *compiler, boolean checkIgnorable, int type)
117{ 117{
118 char *p; 118 char *p;
119 119
120 lval->token = tokens[type - lowestToken]; 120 lval->token = tokens[type - lowestToken];
121 lval->line = compiler->line; 121 lval->line = compiler->line;
122 lval->column = compiler->column; 122 lval->column = compiler->column;
123 lval->len = len;
123 124
124 for (p = text; *p; p++) 125 for (p = text; *p; p++)
125 { 126 {