[Crosstoolchain-logs] [device-tree-compiler] 26/357: Rudimentary support for reporting the line number of syntax errors.
Hector Oron
zumbi at moszumanska.debian.org
Thu Dec 8 17:05:44 UTC 2016
This is an automated email from the git hooks/post-receive script.
zumbi pushed a commit to branch upstream/1.3.x
in repository device-tree-compiler.
commit 86dbcbd1e421700feeae2fc83db9e464f7964262
Author: David Gibson <dgibson at sneetch.(none)>
Date: Wed Oct 19 16:00:31 2005 +1000
Rudimentary support for reporting the line number of syntax errors.
---
dtc-lexer.l | 19 ++++++++++++++++++-
dtc-parser.y | 7 ++++---
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/dtc-lexer.l b/dtc-lexer.l
index 438d7d2..c082228 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -18,7 +18,7 @@
* USA
*/
-%option noyywrap nounput
+%option noyywrap nounput yylineno
%x CELLDATA
%x BYTESTRING
@@ -43,24 +43,30 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
#define DPRINT(fmt, ...) do { } while (0)
#endif
+
+
%}
%%
\"[^"]*\" {
+ yylloc.first_line = yylineno;
DPRINT("String: %s\n", yytext);
yylval.data = data_copy_escape_string(yytext+1,
yyleng-2);
+ yylloc.first_line = yylineno;
return DT_STRING;
}
"/memreserve/" {
+ yylloc.first_line = yylineno;
DPRINT("Keyword: /memreserve/\n");
BEGIN(MEMRESERVE);
return DT_MEMRESERVE;
}
<MEMRESERVE>[0-9a-fA-F]+ {
+ yylloc.first_line = yylineno;
if (yyleng > 2*sizeof(yylval.addr)) {
fprintf(stderr, "Address value %s too large\n",
yytext);
@@ -72,12 +78,14 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
}
<MEMRESERVE>";" {
+ yylloc.first_line = yylineno;
DPRINT("/MEMRESERVE\n");
BEGIN(INITIAL);
return ';';
}
<CELLDATA>[0-9a-fA-F]+ {
+ yylloc.first_line = yylineno;
if (yyleng > 2*sizeof(yylval.cval)) {
fprintf(stderr,
"Cell value %s too long\n", yytext);
@@ -88,36 +96,42 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
}
<CELLDATA>">" {
+ yylloc.first_line = yylineno;
DPRINT("/CELLDATA\n");
BEGIN(INITIAL);
return '>';
}
<CELLDATA>\&{REFCHAR}* {
+ yylloc.first_line = yylineno;
DPRINT("Ref: %s\n", yytext+1);
yylval.str = strdup(yytext+1);
return DT_REF;
}
<BYTESTRING>[0-9a-fA-F]{2} {
+ yylloc.first_line = yylineno;
yylval.byte = strtol(yytext, NULL, 16);
DPRINT("Byte: %02x\n", (int)yylval.byte);
return DT_BYTE;
}
<BYTESTRING>"]" {
+ yylloc.first_line = yylineno;
DPRINT("/BYTESTRING\n");
BEGIN(INITIAL);
return ']';
}
{PROPCHAR}+ {
+ yylloc.first_line = yylineno;
DPRINT("PropName: %s\n", yytext);
yylval.str = strdup(yytext);
return DT_PROPNAME;
}
{PROPCHAR}+(@{UNITCHAR}+)? {
+ yylloc.first_line = yylineno;
DPRINT("NodeName: %s\n", yytext);
yylval.str = strdup(yytext);
return DT_NODENAME;
@@ -125,6 +139,7 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
[a-zA-Z_][a-zA-Z0-9_]*: {
+ yylloc.first_line = yylineno;
DPRINT("Label: %s\n", yytext);
yylval.str = strdup(yytext);
yylval.str[yyleng-1] = '\0';
@@ -134,6 +149,7 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
<*>{WS}+ /* eat whitespace */
<*>"/*"([^*]|\*+[^*/])*\*+"/" {
+ yylloc.first_line = yylineno;
DPRINT("Comment: %s\n", yytext);
/* eat comments */
}
@@ -141,6 +157,7 @@ REFCHAR ({PROPCHAR}|{UNITCHAR}|[/@])
<*>"//".*\n /* eat line comments */
<*>. {
+ yylloc.first_line = yylineno;
switch (yytext[0]) {
case '<':
DPRINT("CELLDATA\n");
diff --git a/dtc-parser.y b/dtc-parser.y
index 66e243d..1bfbfa3 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -18,6 +18,9 @@
* USA
*/
+%glr-parser
+%locations
+
%{
#include "dtc.h"
@@ -69,8 +72,6 @@ extern struct boot_info *the_boot_info;
%type <str> label
%type <str> nodename
-%glr-parser
-
%%
sourcefile: memreserves devicetree {
@@ -160,5 +161,5 @@ label: DT_LABEL { $$ = $1; }
void yyerror (char const *s)
{
- fprintf (stderr, "%s\n", s);
+ fprintf (stderr, "%s at line %d\n", s, yylloc.first_line);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/crosstoolchain/device-tree-compiler.git
More information about the Crosstoolchain-logs
mailing list