Skip to content
This repository was archived by the owner on Oct 16, 2022. It is now read-only.

Commit 055c8ff

Browse files
committed
fixing line numbers and filenames in error messages. issue #24
1 parent 935c78a commit 055c8ff

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

parser/parser.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package parser
33
import (
44
"bytes"
55
"fmt"
6+
"path"
67

78
"github.com/stephens2424/php/ast"
89
"github.com/stephens2424/php/lexer"
@@ -84,7 +85,7 @@ func (p ParseError) String() string {
8485

8586
// Parse consumes the input string to produce an AST that represents it.
8687
func (p *Parser) Parse(filepath, input string) (file *ast.File, err error) {
87-
file = &ast.File{Namespace: p.FileSet.GlobalNamespace}
88+
file = &ast.File{Namespace: p.FileSet.GlobalNamespace, Name: path.Base(filepath)}
8889
p.file = file
8990
p.scope = p.FileSet.Scope
9091
p.namespace = p.FileSet.GlobalNamespace
@@ -222,7 +223,7 @@ func errorf(p *Parser, str string, args ...interface{}) ParseError {
222223
e := ParseError{error: fmt.Errorf(str, args...)}
223224
if p != nil {
224225
e.File = p.file
225-
e.Line = 0
226+
e.Line = p.current.Begin.Line
226227
}
227228
return e
228229
}

0 commit comments

Comments
 (0)