[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
examples: bistromathic: fix location tracking
From: |
Akim Demaille |
Subject: |
examples: bistromathic: fix location tracking |
Date: |
Sun, 2 Feb 2020 11:29:52 +0100 |
commit 493359b75815df852195b1517f868743ba7998f7
Author: Akim Demaille <address@hidden>
Date: Sun Feb 2 08:59:54 2020 +0100
examples: bistromathic: fix location tracking
* examples/c/bistromathic/scan.l (LOCATION_STEP): New.
Use to properly ignore blanks.
* examples/c/bistromathic/bistromathic.test: Check that case.
diff --git a/examples/c/bistromathic/bistromathic.test
b/examples/c/bistromathic/bistromathic.test
index 4d19c98b..89ebcb40 100755
--- a/examples/c/bistromathic/bistromathic.test
+++ b/examples/c/bistromathic/bistromathic.test
@@ -46,3 +46,8 @@ cat >input <<EOF
*
EOF
run 0 "err: 1.1: syntax error expected end of file or - or ( or end of line or
double precision number or function or variable before *"
+
+cat >input <<EOF
+1 + 2 * * 3
+EOF
+run 0 "err: 1.9: syntax error expected - or ( or double precision number or
function or variable before *"
diff --git a/examples/c/bistromathic/scan.l b/examples/c/bistromathic/scan.l
index c5f57c1e..e04cbc19 100644
--- a/examples/c/bistromathic/scan.l
+++ b/examples/c/bistromathic/scan.l
@@ -13,13 +13,19 @@
// Each time a rule is matched, advance the end cursor/position.
#define YY_USER_ACTION \
yylloc->last_column += yyleng;
+
+ // Move the first position onto the last.
+#define LOCATION_STEP() \
+ do { \
+ yylloc->first_line = yylloc->last_line; \
+ yylloc->first_column = yylloc->last_column; \
+ } while (0)
%}
%%
%{
// Each time yylex is called, move the head position to the end one.
- yylloc->first_line = yylloc->last_line;
- yylloc->first_column = yylloc->last_column;
+ LOCATION_STEP ();
%}
/* Rules. */
@@ -52,7 +58,7 @@
"\n" yylloc->last_line++; yylloc->last_column = 1; return TOK_EOL;
/* Ignore white spaces. */
-[ \t]+ continue;
+[ \t]+ LOCATION_STEP (); continue;
<<EOF>> return TOK_EOF;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- examples: bistromathic: fix location tracking,
Akim Demaille <=