summaryrefslogtreecommitdiff
path: root/common/lib/mmtcgen/parser.g
blob: 93db48dd8dc9b8d3c38561b0e2caaa860404ffe2 (plain)
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
import sys
from mmtype import MMType
%%

parser MMTypesParser:
    ignore:         "(#.*?)?\n"
    token START:    "^"
    token EOF:      "$"
    token NAME:     "[a-zA-Z0-9_]+"
    token VALUE:    "0x[0-9A-F]{4}"
    token TYPES:    "REQ|CNF|IND|RSP"
    token SPACE:    "[ \t]+"

    rule parse:    {{ mmtypes = [] }}
        (line      {{ mmtypes.append (line) }}
            )*
        EOF        {{ return mmtypes }}

    rule line:  NAME SPACE VALUE types
        {{return MMType (NAME, VALUE, types)}}

    rule types: SPACE TYPES {{ v = [TYPES] }}
                ( SPACE TYPES {{ v.append (TYPES) }}
                    )*
                {{ return v }}