;;; wisent-dot.wy --- GraphViz DOT file parser ;; Copyright (C) 2003, 2004 Eric M. Ludlam ;; Author: Eric Ludlam ;; Keywords: syntax ;; X-RCS: $Id: wisent-dot.wy,v 1.7 2005/09/30 20:07:11 zappo Exp $ ;; This file is not part of GNU Emacs. ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2, or (at ;; your option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; ;; Parser for GraphViz DOT language. ;; The language is declaritive and the whole thing is parsed. ;; The result could be used as a data structure representing a graph. %languagemode graphviz-dot-mode %start dot_file ;; Needed for EXPANDFULL %start graph-contents %start node-description ;;; KEYWORDS %type %keyword DIGRAPH "digraph" %put DIGRAPH summary "digraph { ... }" %keyword GRAPH "graph" %put GRAPH summary "graph { ... }" %keyword SUBGRAPH "subgraph" %put SUBGRAPH summary "subgraph { ... }" %keyword NODE "node" %put NODE summary "node [...];" %keyword SHAPE "shape" %put SHAPE summary "shape=" %keyword LABEL "label" %put LABEL summary "label=\"string\"" %keyword COLOR "color" %put COLOR summary "color=" %keyword STYLE "style" %put STYLE summary "style=" %keyword LEN "len" %put LEN summary "len=" %keyword FONTNAME "fontname" %put FONTNAME summary "fontname=" %keyword FONTSIZE "fontsize" %put FONTSIZE summary "fontsize=" %keyword WIDTH "width" %keyword HEIGHT "height" %keyword SPLINES "splines" %keyword OVERLAP "overlap" ;;; Punctuation Types %type syntax "\\s.+" %token DILINK "->" %put DILINK summary " -> ; Directed link" %token LINK "--" %put LINK summary " -- ; Link" %token EQUAL "=" %token SEMI ";" %token COMMA "," ;;; BLOCK types %type %token BRACKET_BLOCK "(LBRACKET RBRACKET)" %token BRACE_BLOCK "(LBRACE RBRACE)" %token PAREN_BLOCK "(LPAREN RPAREN)" %token LBRACE "{" %token RBRACE "}" %token LBRACKET "[" %token RBRACKET "]" %token LPAREN "(" %token RPAREN ")" ;;; Bland default types %type %token symbol %type %token string %type %token number %% dot_file : digraph | graph ; digraph : DIGRAPH symbol BRACE_BLOCK (TAG $2 'digraph :members (EXPANDFULL $3 graph-contents)) ; graph : GRAPH symbol BRACE_BLOCK (TAG $2 'graph :members (EXPANDFULL $3 graph-contents)) ; graph-contents : LBRACE () | RBRACE () | label | style | graph-attributes | subgraph | node | named-node | links ; label : LABEL EQUAL string SEMI (TAG $3 'label) ; style : STYLE EQUAL symbol SEMI (TAG $3 'style) ; subgraph : SUBGRAPH symbol BRACE_BLOCK (TAG $2 'graph :members (EXPANDFULL $3 graph-contents)) ; node : NODE BRACKET_BLOCK SEMI (TAG "NODE" 'generic-node :attributes (EXPANDFULL $2 node-description)) ; graph-attributes : GRAPH BRACKET_BLOCK SEMI (TAG "GRAPH" 'graph-attributes :attributes (EXPANDFULL $2 node-description)) ; named-node : symbol BRACKET_BLOCK SEMI (TAG $1 'node :attributes (EXPANDFULL $2 node-description)) ; node-description : LBRACKET () | RBRACKET () | COMMA () | SHAPE EQUAL symbol (TAG $1 'attribute :value $3) | LABEL EQUAL string (TAG $1 'attribute :value $3) | FONTNAME EQUAL string (TAG $1 'attribute :value $3) | FONTSIZE EQUAL number (TAG $1 'attribute :value $3) ;; This is a catch-all in case we miss some keyword. | symbol EQUAL symbol (TAG $1 'attribute :value $3) ; links : symbol DILINK symbol opt-link-attributes opt-semi (TAG $1 'link :to $3 :attributes $4) | BRACE_BLOCK ;; Links in braces get properties. Deal with this later. ; opt-semi : SEMI () | ;; Empty ; opt-link-attributes : BRACKET_BLOCK (EXPANDFULL $1 node-description) | ;; Empty ; %% (define-lex wisent-dot-lexer "Lexical analyzer that handles DOT buffers. It ignores whitespace, newlines and comments." semantic-lex-ignore-whitespace semantic-lex-ignore-newline semantic-lex-ignore-comments wisent-dot-wy---keyword-analyzer wisent-dot-wy---regexp-analyzer wisent-dot-wy---block-analyzer ;; ?? semantic-lex-close-paren wisent-dot-wy---regexp-analyzer wisent-dot-wy---sexp-analyzer wisent-dot-wy---string-analyzer semantic-lex-default-action ) ;;; wisent-dot.wy ends here