summaryrefslogtreecommitdiff
path: root/glsl_lexer.lpp
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2010-04-26 14:19:49 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-04-26 14:19:49 -0700
commitc11f1a4fb07f09a6b804c5d0e4bb12cd5137fafa (patch)
treeaa3bb1de98ecca5fab0fbb5e84d5e46df20f15eb /glsl_lexer.lpp
parent25ebc0459f9e15ebff051fe39e131eca88ea55a0 (diff)
Initial implementation of #line
Does not handle comments in #line or line continuation characters, but it should be good enough for now.
Diffstat (limited to 'glsl_lexer.lpp')
-rw-r--r--glsl_lexer.lpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/glsl_lexer.lpp b/glsl_lexer.lpp
index a25dbf9e2f..06214a8ecc 100644
--- a/glsl_lexer.lpp
+++ b/glsl_lexer.lpp
@@ -21,6 +21,7 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
+#include <ctype.h>
#include "ast.h"
#include "glsl_parser_extras.h"
#include "glsl_parser.h"
@@ -43,6 +44,13 @@
%x PP COMMENT
+DEC_INT [1-9][0-9]*
+HEX_INT 0[xX][0-9a-fA-F]+
+OCT_INT 0[0-7]*
+INT ({DEC_INT}|{HEX_INT}|{OCT_INT})
+SPC [ \t]*
+SPCP [ \t]+
+HASH ^{SPC}#{SPC}
%%
"/*" { yy_push_state(COMMENT, yyscanner); }
@@ -59,7 +67,35 @@
^[ \t]*#[ \t]*$ ;
^[ \t]*#[ \t]*version { BEGIN PP; return VERSION; }
^[ \t]*#[ \t]*extension { BEGIN PP; return EXTENSION; }
-^[ \t]*#[ \t]*line { BEGIN PP; return LINE; }
+{HASH}line{SPCP}{INT}{SPCP}{INT}{SPC}$ {
+ /* Eat characters until the first digit is
+ * encountered
+ */
+ char *ptr = yytext;
+ while (!isdigit(*ptr))
+ ptr++;
+
+ /* Subtract one from the line number because
+ * yylineno is zero-based instead of
+ * one-based.
+ */
+ yylineno = strtol(ptr, &ptr, 0) - 1;
+ yylloc->source = strtol(ptr, NULL, 0);
+ }
+{HASH}line{SPCP}{INT}{SPC}$ {
+ /* Eat characters until the first digit is
+ * encountered
+ */
+ char *ptr = yytext;
+ while (!isdigit(*ptr))
+ ptr++;
+
+ /* Subtract one from the line number because
+ * yylineno is zero-based instead of
+ * one-based.
+ */
+ yylineno = strtol(ptr, &ptr, 0) - 1;
+ }
^[ \t]*#[ \t]*pragma { BEGIN PP; return PRAGMA; }
<PP>\/\/[^\n]* { }
<PP>[ \t\r]* { }