/*
* read and interpret syntax that looks like
- * //line 15 parse.y
+ * //line parse.y:15
* as a discontenuity in sequential line numbers.
* the next line of input comes from parse.y:15
*/
for(i=0; i<5; i++) {
c = getr();
if(c != "line "[i])
- return c;
+ goto out;
}
- n = 0;
- for(;;) {
- c = getr();
- if(!isdigit(c))
- break;
- n = n*10 + (c-'0');
- }
-
- if(c != ' ' || n == 0)
- return c;
-
cp = lexbuf;
ep = lexbuf+sizeof(lexbuf)-5;
for(;;) {
c = getr();
+ if(c == '\n' || c == EOF)
+ goto out;
if(c == ' ')
continue;
- if(c == '\n')
- break;
- *cp++ = c;
- if(cp >= ep)
+ if(c == ':')
break;
+ if(cp < ep)
+ *cp++ = c;
}
*cp = 0;
-// n--; // weve already seen the newline
- if(n > 0) {
- // try to avoid allocating file name over and over
- for(h=hist; h!=H; h=h->link) {
- if(h->name != nil && strcmp(h->name, lexbuf) == 0) {
- linehist(h->name, n, 0);
- return c;
- }
+
+ n = 0;
+ for(;;) {
+ c = getr();
+ if(!isdigit(c))
+ break;
+ n = n*10 + (c-'0');
+ }
+
+ if(c != '\n' || n <= 0)
+ goto out;
+
+ // try to avoid allocating file name over and over
+ for(h=hist; h!=H; h=h->link) {
+ if(h->name != nil && strcmp(h->name, lexbuf) == 0) {
+ linehist(h->name, n, 0);
+ goto out;
}
- linehist(strdup(lexbuf), n, 0);
}
+ linehist(strdup(lexbuf), n, 0);
+
+out:
return c;
}
// Track last two tokens returned by yylex.
yyprev = yylast;
yylast = lx;
- return lx;
+ return lx;
}
static int
//
if t == MARK {
if !lflag {
- fmt.Fprintf(ftable, "\n//line %v %v\n", lineno, infile)
+ fmt.Fprintf(ftable, "\n//line %v:%v\n", infile, lineno)
}
for {
c := getrune(finput)
func cpyunion() {
if !lflag {
- fmt.Fprintf(ftable, "\n//line %v %v\n", lineno, infile)
+ fmt.Fprintf(ftable, "\n//line %v:%v\n", infile, lineno)
}
fmt.Fprintf(ftable, "type\tyySymType\tstruct")
lineno++
}
if !lflag {
- fmt.Fprintf(ftable, "\n//line %v %v\n", lineno, infile)
+ fmt.Fprintf(ftable, "\n//line %v:%v\n", infile, lineno)
}
for c != EOF {
if c == '%' {
func cpyact(curprod []int, max int) {
if !lflag {
- fmt.Fprintf(fcode, "\n//line %v %v\n", lineno, infile)
+ fmt.Fprintf(fcode, "\n//line %v:%v\n", infile, lineno)
}
lno := lineno
func output() {
var c, u, v int
- fmt.Fprintf(ftable, "\n//line 1 yacctab\n")
+ fmt.Fprintf(ftable, "\n//line yacctab:1\n")
fmt.Fprintf(ftable, "var\tyyExca = []int {\n")
noset := mkset()
}
// copy yaccpar
- fmt.Fprintf(ftable, "\n//line 1 yaccpar\n")
+ fmt.Fprintf(ftable, "\n//line yaccpar:1\n")
parts := strings.Split(yaccpar, "yyrun()", 2)
fmt.Fprintf(ftable, "%v", parts[0])