lang: parser: Try to add the end values in parser
Not sure if this is right, but it's a start.
This commit is contained in:
@@ -12,4 +12,4 @@ class c1($a, $b []str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
-- OUTPUT --
|
-- OUTPUT --
|
||||||
# err: errUnify: type error: list != str: /main.mcl @ 4:1-4:25
|
# err: errUnify: type error: list != str: /main.mcl @ 4:1-4:26
|
||||||
|
|||||||
@@ -15,4 +15,4 @@ test ["x",] {
|
|||||||
float32 => $b,
|
float32 => $b,
|
||||||
}
|
}
|
||||||
-- OUTPUT --
|
-- OUTPUT --
|
||||||
# err: errUnify: type error: int != float: /main.mcl @ 10:6-10:22
|
# err: errUnify: type error: int != float: /main.mcl @ 10:6-10:25
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ test "t1" {
|
|||||||
stringptr => 42, # int, not str
|
stringptr => 42, # int, not str
|
||||||
}
|
}
|
||||||
-- OUTPUT --
|
-- OUTPUT --
|
||||||
# err: errUnify: type error: str != int: /main.mcl @ 2:2-2:17
|
# err: errUnify: type error: str != int: /main.mcl @ 2:2-2:18
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ test "test" {}
|
|||||||
Test["${name}"] -> Test["test"] # must fail
|
Test["${name}"] -> Test["test"] # must fail
|
||||||
|
|
||||||
-- OUTPUT --
|
-- OUTPUT --
|
||||||
# err: errUnify: type error: str != list: /main.mcl @ 6:1-6:15
|
# err: errUnify: type error: str != list: /main.mcl @ 6:1-6:16
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ test "test" {}
|
|||||||
Test["test"] -> Test["${name}"] # must fail
|
Test["test"] -> Test["${name}"] # must fail
|
||||||
|
|
||||||
-- OUTPUT --
|
-- OUTPUT --
|
||||||
# err: errUnify: type error: str != list: /main.mcl @ 6:17-6:31
|
# err: errUnify: type error: str != list: /main.mcl @ 6:17-6:32
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ $name = ["a", "bb", "ccc",]
|
|||||||
test "${name}" {} # must fail
|
test "${name}" {} # must fail
|
||||||
|
|
||||||
-- OUTPUT --
|
-- OUTPUT --
|
||||||
# err: errUnify: type error: str != list: /main.mcl @ 4:1-4:17
|
# err: errUnify: type error: str != list: /main.mcl @ 4:1-4:18
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ func init() {
|
|||||||
row int
|
row int
|
||||||
col int
|
col int
|
||||||
|
|
||||||
|
endRow int
|
||||||
|
endCol int
|
||||||
|
|
||||||
//err error // TODO: if we ever match ERROR in the parser
|
//err error // TODO: if we ever match ERROR in the parser
|
||||||
|
|
||||||
bool bool
|
bool bool
|
||||||
@@ -1568,11 +1571,10 @@ func pos(y yyLexer, dollar yySymType) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// cast is used to pull out the parser run-specific struct we store our AST in.
|
// posLast runs pos on the last token of the current stmt/expr.
|
||||||
// this is usually called in the parser.
|
func posLast(y yyLexer, dollars []yySymType) {
|
||||||
func cast(y yyLexer) *lexParseAST {
|
// pick the last token in the set matched by the parser
|
||||||
x := y.(*Lexer).parseResult
|
pos(y, dollars[len(dollars)-1]) // our pos
|
||||||
return x.(*lexParseAST)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// locate should be called after creating AST nodes from lexer tokens to store
|
// locate should be called after creating AST nodes from lexer tokens to store
|
||||||
@@ -1585,14 +1587,16 @@ func locate(y yyLexer, first yySymType, last yySymType, node interface{}) {
|
|||||||
if pn, ok := node.(interfaces.PositionableNode); !ok {
|
if pn, ok := node.(interfaces.PositionableNode); !ok {
|
||||||
return
|
return
|
||||||
} else if !pn.IsSet() {
|
} else if !pn.IsSet() {
|
||||||
pn.Locate(first.row, first.col, last.row, last.col)
|
//fmt.Printf("LOCATE(%v): %v, %v, %v, %v\n", node, first.row, first.col, last.endRow, last.endCol)
|
||||||
|
pn.Locate(first.row, first.col, last.endRow, last.endCol)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// posLast runs pos on the last token of the current stmt/expr.
|
// cast is used to pull out the parser run-specific struct we store our AST in.
|
||||||
func posLast(y yyLexer, dollars []yySymType) {
|
// this is usually called in the parser.
|
||||||
// pick the last token in the set matched by the parser
|
func cast(y yyLexer) *lexParseAST {
|
||||||
pos(y, dollars[len(dollars)-1]) // our pos
|
x := y.(*Lexer).parseResult
|
||||||
|
return x.(*lexParseAST)
|
||||||
}
|
}
|
||||||
|
|
||||||
// cast is used to pull out the parser run-specific struct we store our AST in.
|
// cast is used to pull out the parser run-specific struct we store our AST in.
|
||||||
@@ -1605,8 +1609,17 @@ func (yylex *Lexer) cast() *lexParseAST {
|
|||||||
func (yylex *Lexer) pos(lval *yySymType) {
|
func (yylex *Lexer) pos(lval *yySymType) {
|
||||||
lval.row = yylex.Line()
|
lval.row = yylex.Line()
|
||||||
lval.col = yylex.Column()
|
lval.col = yylex.Column()
|
||||||
// TODO: we could use: `s := yylex.Text()` to calculate a delta length!
|
|
||||||
//log.Printf("lexer: %d x %d", lval.row, lval.col)
|
// use: `yylex.Text()` to calculate a delta length!
|
||||||
|
text := yylex.Text()
|
||||||
|
lines := strings.Split(text, "\n")
|
||||||
|
|
||||||
|
lval.endRow = lval.row + len(lines) - 1 // add delta lines
|
||||||
|
if len(lines) > 1 {
|
||||||
|
lval.endCol = len(lines[len(lines)-1]) // add pos of last line
|
||||||
|
} else {
|
||||||
|
lval.endCol = lval.col + len(text) // moved over this many chars
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error is the error handler which gets called on a parsing error.
|
// Error is the error handler which gets called on a parsing error.
|
||||||
|
|||||||
Reference in New Issue
Block a user