Grammar railroad diagram

Aperta
#261 1 commento 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Documentazione
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript
Ambito
documentation

Direzione di ricerca

Inizia da dbml/parser.pegjs e confronta la relativa grammatica con l’EBNF fornita, quindi incolla l’EBNF in BottleCaps Railroad Diagram Generator per esaminare il risultato. L’issue non identifica alcun file del repository né un deliverable richiesto; per completarla sarebbero necessari una posizione concordata e un diagramma renderizzato che rappresenti accuratamente la grammatica.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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_ ::= '&'
Lingua principale
JavaScript
Stelle
3.7k
Fork
233
Merge medio
2g 4h
PR unite (30g)
23

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di holistics/dbml

Tutte le issue di holistics/dbml

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.