-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpragmaDirective.go
More file actions
38 lines (35 loc) · 864 Bytes
/
Copy pathpragmaDirective.go
File metadata and controls
38 lines (35 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package solparser
import (
"github.com/uji/solparser/ast"
"github.com/uji/solparser/token"
)
func (p *Parser) ParsePragmaDirective() (*ast.PragmaDirective, error) {
prgm, err := p.lexer.Scan()
if err != nil {
return nil, err
}
if prgm.Type != token.Pragma {
return nil, token.NewPosError(prgm.Position, "not found pragma.")
}
tkns := make([]*token.Token, 0, 1)
for {
tkn, err := p.lexer.Scan()
if err != nil {
return nil, err
}
if tkn.Type == token.EOS {
return nil, token.NewPosError(tkn.Position, "not found Semicolon.")
}
if tkn.Type == token.Semicolon {
if len(tkns) == 0 {
return nil, token.NewPosError(tkn.Position, "not found pragma tokens.")
}
return &ast.PragmaDirective{
Pragma: prgm.Position,
PragmaTokens: tkns,
Semicolon: tkn.Position,
}, nil
}
tkns = append(tkns, &tkn)
}
}