forked from kaishuu0123/erd-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
erd.peg
69 lines (56 loc) · 2.11 KB
/
erd.peg
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
type Parser Peg {
Erd
}
root <- expression EOT /
expression <.+> {p.Err(begin, buffer)} EOT /
<.+> {p.Err(begin, buffer)} EOT
EOT <- !.
expression <-
(title_info / relation_info / table_info / comment_line / empty_line)*
empty_line <- ws { p.ClearTableAndColumn() }
comment_line <- space* '#' comment_string newline
title_info <- 'title' ws* '{' ws* (title_attribute ws* attribute_sep? ws*)* ws* '}' newline
table_info <-
'[' table_title ']' (space* '{' ws* (table_attribute ws* attribute_sep?)* ws* '}' space*)? newline_or_eot (table_column / empty_line)*
table_title <-
<string> { p.AddTable(text) }
table_column <-
space* column_name (space* '{' ws* (column_attribute ws* attribute_sep?)* ws* '}' space*)? newline_or_eot
column_name <-
<string> { p.AddColumn(text) }
relation_info <-
space* relation_left space* cardinality_left '--' cardinality_right space* relation_right (ws* '{' ws* (relation_attribute ws* attribute_sep? ws*)* ws* '}')? newline_or_eot { p.AddRelation() }
relation_left <-
<string> { p.SetRelationLeft(text) }
cardinality_left <-
<cardinality> { p.SetCardinalityLeft(text)}
relation_right <-
<string> { p.SetRelationRight(text) }
cardinality_right <-
<cardinality> { p.SetCardinalityRight(text)}
title_attribute <-
attribute_key space* ':' space* attribute_value { p.AddTitleKeyValue() }
table_attribute <-
attribute_key space* ':' space* attribute_value { p.AddTableKeyValue() }
column_attribute <-
attribute_key space* ':' space* attribute_value { p.AddColumnKeyValue() }
relation_attribute <-
attribute_key space* ':' space* attribute_value { p.AddRelationKeyValue() }
attribute_key <-
<string> { p.SetKey(text) }
attribute_value <- bare_value / quoted_value
bare_value <-
<string> { p.SetValue(text) }
quoted_value <-
< '"' string_in_quote '"' > { p.SetValue(text) }
attribute_sep <-
space* ',' space*
comment_string <- (![\r\n] .)*
ws <- [ \t\r\n]+
newline <- '\r\n' / '\n' / '\r'
newline_or_eot <- newline / EOT
space <- [ \t]+
string <- (!["\t\r\n/:,\[\]{} ].)+
string_in_quote <- (!["\t\r\n].)+
cardinality <- [01*]