Grammar railroad diagram

Đang mở
#261 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tài liệu
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
javascript
Lĩnh vực
documentation

Hướng nghiên cứu

Bắt đầu với dbml/parser.pegjs và so sánh ngữ pháp của nó với EBNF được cung cấp, sau đó dán EBNF vào BottleCaps Railroad Diagram Generator để kiểm tra kết quả. Issue không xác định tệp nào trong repository hoặc sản phẩm bàn giao được yêu cầu; để hoàn thành, cần thống nhất một vị trí và có một sơ đồ được render thể hiện chính xác ngữ pháp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Using a custom parser that translates dbml/parser.pegjs grammar to an EBNF understood by https://www.bottlecaps.de/rr/ui and manually fixing small errors we can have nice railroad diagram (https://en.wikipedia.org/wiki/Syntax_diagram) to help show/understand the syntax.

Copy and paste the EBNF shown bellow at https://www.bottlecaps.de/rr/ui on the tab Edit Grammar then click on the tab View Diagram.

//To be viewd at https://www.bottlecaps.de/rr/ui

rules ::=
	 expr*

expr ::=
	 TableSyntax
	| RefSyntax
	| EnumSyntax
	| TableGroupSyntax
	| ProjectSyntax
	| __

TableSyntax ::=
	 table sp+ schema_name? name alias_def? sp* TableSettings? _ "{" TableBody "}"

RefSyntax ::=
	 ref_long
	| ref_short

EnumSyntax ::=
	 enum sp+ schema_name? name _ "{" EnumBody "}"

TableGroupSyntax ::=
	 table_group sp+ schema_name? name _ "{" _ table_group_body _ "}"

ProjectSyntax ::=
	 project ( __ name )? _ "{" _ ProjectBody _ "}"

__ ::=
	 ( comment | whitespace )+

project ::=
	 "project"

name ::=
	 character+
	| ( quote [^\"\n]+ quote )

_ ::=
	 ( comment | whitespace )*

ProjectBody ::=
	 _ ProjectElement* _

ProjectElement ::=
	 ( _ ObjectNoteElement _ )
	| ( _ TableSyntax _ )
	| ( _ RefSyntax _ )
	| ( _ EnumSyntax _ )
	| ( TableGroupSyntax _ )
	| ( _ ProjectField _ )

ObjectNoteElement ::=
	 ObjectNote
	| ( "note" _ "{" _ StringLiteral _ "}" )

ProjectField ::=
	 name _ ":" _ StringLiteral

StringLiteral ::=
	 ( '"' DoubleStringCharacter* '"' )
	| ( "'''" MultiLineStringCharacter* "'''" )
	| ( "'" SingleStringCharacter* "'" )

table_group ::=
	 "TableGroup"

sp ::=
	 " "

schema_name ::=
	 name "."

table_group_body ::=
	 ( schema_name? name __ )*

ref_long ::=
	 ref ( __ name )? _ "{" _ ref_body _ "}"

ref_short ::=
	 ref ( sp+ name )? sp* ":" sp* ref_body

ref ::=
	 "ref"

ref_body ::=
	 field_identifier sp+ relation sp+ field_identifier sp* RefSettings?

field_identifier ::=
	 ( name "." name "." RefField )
	| ( name "." RefField )

relation ::=
	 [>-<]

RefSettings ::=
	 "[" RefSetting ( Comma RefSetting )* "]"

RefField ::=
	 RefSingleField
	| RefMultipleFields

RefSingleField ::=
	 name

RefMultipleFields ::=
	 "(" sp* RefSingleField ( sp* Comma sp* RefSingleField )* sp* ")"

Comma ::=
	 ","

RefSetting ::=
	 ( _ OnUpdate _ )
	| ( _ OnDelete _ )

OnUpdate ::=
	 "update:" _ ( no_action | restrict | cascade | set_null | set_default )

OnDelete ::=
	 "delete:" _ ( no_action | restrict | cascade | set_null | set_default )

no_action ::=
	 "no action"

restrict ::=
	 "restrict"

cascade ::=
	 "cascade"

set_null ::=
	 "set null"

set_default ::=
	 "set default"

table ::=
	 "table"

alias_def ::=
	 sp+ "as" sp+ name

TableSettings ::=
	 "[" TableSetting ( Comma TableSetting )* "]"

TableBody ::=
	 _ Field+ _ TableElement* _

Field ::=
	 _ name sp+ schema_name? type ( sp+ constrain )* ( sp+ FieldSettings )? sp* comment? newline

TableElement ::=
	 ( _ Indexes _ )
	| ( _ ObjectNoteElement _ )

Indexes ::=
	 _ indexes _ "{" IndexesBody "}"

type ::=
	 type_name ( sp* "(" sp* expression sp* ")" )?

constrain ::=
	 unique
	| pk

FieldSettings ::=
	 "[" FieldSetting ( Comma FieldSetting )* "]"

comment ::=
	 single_line_comment
	| multi_lime_comment

newline ::=
	 "\r\n"
	| "\n"

enum ::=
	 "enum"

EnumBody ::=
	 _ EnumValue+ _

EnumValue ::=
	 _ name sp* EnumSetting? sp* comment? newline

EnumSetting ::=
	 "[" _ ObjectNote _ "]"

ObjectNote ::=
	 "note:" _ StringLiteral

FieldSetting ::=
	 ( _ "not null" _ )
	| ( _ "null" _ )
	| ( _ "primary key" _ )
	| ( _ "pk" _ )
	| ( _ "unique" _ )
	| ( _ "increment" _ )
	| ( _ ObjectNote _ )
	| ( _ RefInline _ )
	| ( _ Default _ )

TableSetting ::=
	 ( _ ObjectNote _ )
	| ( _ HeaderColor _ )

HeaderColor ::=
	 _ header_color ":" _ sharp hex_color _

RefInline ::=
	 "ref:" sp* relation sp+ inline_field_identifier

Default ::=
	 "default:" _ DefaultVal

indexes ::=
	 "indexes"

IndexesBody ::=
	 _ Index+ _

Index ::=
	 _ ( SingleIndexSyntax | CompositeIndexSyntax ) _

SingleIndexSyntax ::=
	 _ SingleIndex sp* IndexSettings?

CompositeIndexSyntax ::=
	 _ CompositeIndex sp* IndexSettings?

SingleIndex ::=
	 ( name sp* )
	| Expression

IndexSettings ::=
	 ( "[" sp* pk sp* "]" )
	| ( "[" IndexSetting ( Comma IndexSetting )* "]" )

CompositeIndex ::=
	 "(" sp* SingleIndex ( Comma sp* SingleIndex )* ")"

Expression ::=
	 "`" [^`]* "`"

pk ::=
	 "pk"

IndexSetting ::=
	 ( _ "unique" _ )
	| ( _ IndexName _ )
	| ( _ IndexType _ )
	| ( _ ObjectNote _ )

IndexName ::=
	 "name:" _ StringLiteral

IndexType ::=
	 "type:" _ ( btree | hash )

btree ::=
	 "btree"

hash ::=
	 "hash"

inline_field_identifier ::=
	 ( name "." name "." name )
	| ( name "." name )

DefaultVal ::=
	 StringLiteral
	| Expression
	| BooleanLiteral
	| NumberLiteral

BooleanLiteral ::=
	 'true'
	| 'false'
	| 'null'

NumberLiteral ::=
	 "-"? ( float | integer )

header_color ::=
	 "headercolor"

sharp ::=
	 "#"

hex_color ::=
	 six_char
	| three_char

six_char ::=
	 hex_char hex_char hex_char hex_char hex_char hex_char

three_char ::=
	 hex_char hex_char hex_char

hex_char ::=
	 [0-9a-fA-F]

unique ::=
	 "unique"

as ::=
	 "as"

character ::=
	 [a-zA-Z0-9_]

quote ::=
	 '"'

type_name ::=
	 type_character+
	| ( quote [^\"\n]+ quote )

type_character ::=
	 character
	| [#x5B#x5D]

expression ::=
	 factor*

factor ::=
	 ( character+ sp* "(" expression ")" )
	| ( "(" expression ")" )
	| ( exprCharNoCommaSpace+ ( sp* | "," | ");" | ( endline ");" ) ) )
	| ( exprChar+ . )

exprCharNoCommaSpace ::=
	 [\'.a-zA-Z0-9_+-]

endline ::=
	 sp* newline

exprChar ::=
	 [\',.a-zA-Z0-9_+-`]
	| sp
	| newline
	| tab

tab ::=
	 "\t"

allowed_chars ::=
	 _NOT_  ( '{' | '}' | whitespace_quote ) .

whitespace_quote ::=
	 [ \t\r\n\r\"]

whitespace ::=
	 [ \t\r\n\r]

single_line_comment ::=
	 "//" [^\n]*

multi_lime_comment ::=
	 "/*" ( _NOT_  "*/" . )* "*/"

DoubleStringCharacter ::=
	 ( '\\' '"' )
	| ( _NOT_  '"' SourceCharacter )

MultiLineStringCharacter ::=
	 "\\'"
	| ( "\\" "\\"+ )
	| ( "\\" "\n"? )
	| ( _NOT_  "'''" SourceCharacter )

SingleStringCharacter ::=
	 "\\'"
	| ( _NOT_  "'" SourceCharacter )

SourceCharacter ::=
	 .

digit ::=
	 [0-9]

decimal_point ::=
	 dot

dot ::=
	 '.'

equal ::=
	 '='

float ::=
	 [0-9]+ "." [0-9]+

integer ::=
	 [0-9]+


//Added tokens for railroad generation
_NOT_ ::= '!'
_AND_ ::= '&'
Ngôn ngữ chính
JavaScript
Star
3.7k
Fork
233
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
23

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của holistics/dbml

Tất cả issue của holistics/dbml

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.