root/lang/ruby/mp1/mp1_parser_common.rl @ 36100

Revision 14331, 2.0 kB (checked in by frsyuki, 5 years ago)

lang/ruby/mp1: added MP1, a general-purpose binary serialization format

Line 
1//
2// MP1
3//
4// Copyright (C) 2008 FURUHASHI Sadayuki
5//
6//    Licensed under the Apache License, Version 2.0 (the "License");
7//    you may not use this file except in compliance with the License.
8//    You may obtain a copy of the License at
9//
10//        http://www.apache.org/licenses/LICENSE-2.0
11//
12//    Unless required by applicable law or agreed to in writing, software
13//    distributed under the License is distributed on an "AS IS" BASIS,
14//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15//    See the License for the specific language governing permissions and
16//    limitations under the License.
17//
18
19%%{
20        machine mp1_parser_common;
21
22# primitive markers
23        nil_marker                      = 0x00;
24        false_marker            = 0x01;
25        true_marker                     = 0x02;
26
27# data type markers
28        byte_marker                     = 0x04;
29        int_marker                      = 0x05;
30        float_marker            = 0x06;
31
32# extend data type markers
33        bignum_marker           = 0x10;
34        byte_array_marker       = 0x11;
35
36# container type markers
37        array_marker            = 0x18;
38        dictionary_marker       = 0x19;
39
40        nil_type                        = nil_marker @nil_type;
41        false_type                      = false_marker @false_type;
42        true_type                       = true_marker @true_type;
43
44        byte_type                       = byte_marker any @byte_type;
45        int_type                        = int_marker any{4} @int_type;
46        float_type                      = float_marker any{8} @float_type;
47
48        byte_array_type         = byte_array_marker any{4} @byte_array_type;
49        bignum_type                     = bignum_marker any{2} @bignum_type;
50
51        array_type                      = array_marker any{4} @array_type;
52        dictionary_type         = dictionary_marker any{4} @dictionary_type;
53
54        primitive_types = nil_type | false_type | true_type;
55
56        data_types = byte_type | int_type | float_type;
57
58        extend_types = bignum_type | byte_array_type;
59
60        container_types = array_type | dictionary_type ;
61
62        value_type =
63                primitive_types |
64                data_types |
65                extend_types |
66                container_types
67                ;
68
69main := (value_type);
70
71array_item := (value_type %array_item)*;
72
73dictionary_item := ((value_type %dictionary_key_item) (value_type %dictionary_value_item))*;
74
75byte_array_item := (any @byte_array_item)*;
76
77bignum_item := (any @bignum_item)*;
78
79}%%
80
Note: See TracBrowser for help on using the browser.