Created
January 22, 2023 21:14
-
-
Save valer-cara/9f7af6b95309fceecde551f51a3fd0c0 to your computer and use it in GitHub Desktop.
Instaparse grammar for dot/graphviz. Incomplete.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; original spec https://graphviz.org/doc/info/lang.html | |
;; this is only a partial implementation | |
(def grammar " | |
G = 'digraph' <WS> graph-name <WS*> block <WS*> | |
<ws> = <#'[\\s\\t]+'> (* whitespace *) | |
<WS> = <#'[\\s\\t\\n\\r]+'> (* multiline whitespace, graphviz is very newline tolerant *) | |
<string-q> = <'\"'> #'[^\"]*' <'\"'> | |
<string-uq> = #'[a-zA-Z_][a-zA-Z_0-9]+' | |
<string> = string-q | string-uq | |
block = <'{'> WS* stmt-list WS* <'}'> | |
graph-name = string | |
node = string | |
node-from = node | |
node-to = node | |
arrow = '->' | |
propName = string | |
propValue = string | |
prop = propName <'='> propValue | |
propList = propList? prop <ws*> | |
props = <'['> propList? <']'> | |
nodeSpec = <WS*> node <WS*> props? | |
edgeSpec = <WS*> node-from <WS*> <arrow> <WS*> node-to <WS*> props? | |
stmt-list = stmt-list? stmt | |
<stmt> = nodeSpec | edgeSpec | |
") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment