-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathabif-v0.31.ebnf
More file actions
65 lines (57 loc) · 1.79 KB
/
abif-v0.31.ebnf
File metadata and controls
65 lines (57 loc) · 1.79 KB
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
%import common.WS
%import common.NEWLINE
%import common.ESCAPED_STRING
%import common.INT -> INTEGER
%import common.SIGNED_FLOAT -> FLOAT
%ignore WS
ASTERISK : "*"
EQUAL : "="
OPENSQ : "["
CLOSEDSQ : "]"
CLOSEDCURLY : "}"
COLON : ":"
COMMA : ","
HASHMARK : "#"
OPENCURLY : "{"
SLASH : "/"
GT : ">"
TRUE : "true"
FALSE : "false"
NULL : "null"
// QKEY is a quoted key.
QKEY : ESCAPED_STRING
// BKEY is a bare candidate key.
BKEY : /[a-zA-Z][a-zA-Z0-9_-]*/
// QVALUE is a quoted value.
QVALUE : ESCAPED_STRING
// Content inside square brackets
SQ_CONTENT : /[^\]]+/
?start: abiffile
?abiffile : ( comment | metadata_line | cand_line | voteline )*
// comment definition
comment : HASHMARK comment_string NEWLINE
comment_string : /[^\r\n]+/
// metadata_line - metadata lines usually at the top of a file
// NOTE: metadata lines look more-or-less like JSON or JSON5 but there
// are important differences that are left as an exercise for the
// reader:
metadata_line : OPENCURLY [metadata_pair] CLOSEDCURLY comment?
metadata_pair : metadata_key COLON metadata_value
metadata_key : QKEY | BKEY
metadata_value: QVALUE | INTEGER | FLOAT | TRUE | FALSE | NULL
// cand_line - candidate definition lines
cand_line : EQUAL? cand_tok COLON cand_tok comment?
cand_tok: ( cand_square_quoted | cand_doublequote_quoted | cand_bare )
cand_square_quoted : OPENSQ SQ_CONTENT CLOSEDSQ
cand_doublequote_quoted : QKEY
cand_bare : BKEY
// voteline - voter preference lines
voteline : ballot_count count_sep prefs? comment?
ballot_count : INTEGER
prefs : pref_item (pref_sep pref_item)*
pref_sep : ( EQUAL | GT | COMMA )
// pref_item - candidate token and optional candidate rating
pref_item : ( cand_id | cand_tok_rating )
cand_tok_rating : cand_id SLASH INTEGER
cand_id : ( cand_bare | cand_doublequote_quoted | cand_square_quoted )
count_sep : COLON