-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathphpdoc.rl
69 lines (54 loc) · 1.33 KB
/
phpdoc.rl
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
%%machine lexer;
import (
"github.com/quasilyte/parsing-in-go/phpdoc"
"fmt"
)
type PhpdocLex struct {
pos int
src string
result phpdoc.Type
}
func NewLexer() *PhpdocLex {
return &PhpdocLex{}
}
func (l *PhpdocLex) Init(s string) {
l.pos = 0
l.src = s
}
func (l *PhpdocLex) Lex(lval *PhpdocSymType) int {
tok := 0
data := l.src
cs, p, pe := 0, l.pos, len(data)
eof := pe
var ts, te int
var act int
%%{
whitespace = [\t ];
ident_first = [a-zA-Z_] | (0x0080..0x00FF);
ident_rest = ident_first | [0-9] | [\\];
ident = ident_first (ident_rest)*;
main := |*
whitespace => {};
'int' => { tok = T_INT; fbreak; };
'float' => { tok = T_FLOAT; fbreak; };
'null' => { tok = T_NULL; fbreak; };
'string' => { tok = T_STRING; fbreak; };
'false' => { tok = T_FALSE; fbreak; };
'bool' => { tok = T_BOOL; fbreak; };
ident => { tok = T_NAME; fbreak; };
any => { tok = int(data[ts]); fbreak; };
*|;
}%%
%%write init;
%%write exec;
l.pos = p
if tok == T_NAME {
lval.text = data[ts:te]
}
return tok
}
func (l *PhpdocLex) Error(s string) {
fmt.Printf("syntax error: %s\n", s)
}
%%write data;