generated from WillAbides/goproject-tmpl
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathobject_handler_machine.rl
76 lines (64 loc) · 1.66 KB
/
object_handler_machine.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
70
71
72
73
74
75
76
package rjson
func handleObjectValues(data []byte, handler ObjectValueHandler, stack []int) (int, []int ,error) {
var top, cs, p, pp int
var err error
pe := len(data)
eof := len(data)
var currentFieldStart, currentFieldEnd int
%%{
machine handleObjectValues;
include skipper "skip_machine.rl";
prepush {
if top + 1 >= len(stack) {
stack = append(stack, make([]int, 1 + top - len(stack))...)
}
}
action try_handler {
pp, err = handler.HandleObjectValue(data[currentFieldStart+1:currentFieldEnd-1], data[p:])
if err != nil {
return p + pp, stack, err
}
if pp < 0 {
err = errPOutOfRange
fbreak;
}
if pp != 0 {
if p + pp - 1 >= pe {
err = errPOutOfRange
fbreak;
}
fexec p + pp - 1;
}
}
action try_handler_simple {
_, err = handler.HandleObjectValue(data[currentFieldStart+1:currentFieldEnd-1], data[p:])
if err != nil {
return p, stack, err
}
}
skip_array := skip_array_def;
skip_object := skip_object_def;
handled_value =
json_bool >(try_handler_simple)
| json_null >(try_handler_simple)
| json_number >(try_handler_simple)
| json_string >(try_handler)
| '[' >(try_handler) @{fcall skip_array;}
| '{' >(try_handler) @{fcall skip_object;}
;
json_object_field = (json_string >{currentFieldStart = p} %{currentFieldEnd = p} );
main :=
( json_space* (
json_null |
('{'
(
json_space* json_object_field json_space* ':' json_space* handled_value
(json_space* ',' json_space* json_object_field json_space* ':' json_space* handled_value )*
)?
json_space* '}'))) @err{
return p, stack, errInvalidObject
};
write data; write init; write exec;
}%%
return p, stack, err
}