DOT format abstract syntax tree class, based on official documentation. More...
#include <ogdf/fileformats/DotParser.h>
Classes | |
struct | AList |
struct | AsgnStmt |
struct | AttrList |
struct | AttrStmt |
struct | CompassPt |
struct | EdgeLhs |
struct | EdgeRhs |
struct | EdgeStmt |
struct | Graph |
struct | NodeId |
struct | NodeStmt |
struct | Port |
struct | Stmt |
struct | StmtList |
struct | Subgraph |
Public Member Functions | |
Ast (const Tokens &tokens) | |
Initializes AST building but does not trigger the process itself. | |
~Ast () | |
bool | build () |
Builds the DOT format AST. | |
Graph * | root () const |
Returns the root of the AST (nullptr if none). | |
Private Types | |
using | Iterator = Tokens::const_iterator |
using | Tokens = std::vector< Token > |
Private Member Functions | |
AList * | parseAList (Iterator current, Iterator &rest) |
AsgnStmt * | parseAsgnStmt (Iterator current, Iterator &rest) |
AttrList * | parseAttrList (Iterator current, Iterator &rest) |
AttrStmt * | parseAttrStmt (Iterator current, Iterator &rest) |
CompassPt * | parseCompassPt (Iterator current, Iterator &rest) |
EdgeRhs * | parseEdgeRhs (Iterator current, Iterator &rest) |
EdgeStmt * | parseEdgeStmt (Iterator current, Iterator &rest) |
Graph * | parseGraph (Iterator current, Iterator &rest) |
NodeId * | parseNodeId (Iterator current, Iterator &rest) |
NodeStmt * | parseNodeStmt (Iterator current, Iterator &rest) |
Port * | parsePort (Iterator current, Iterator &rest) |
Stmt * | parseStmt (Iterator current, Iterator &rest) |
StmtList * | parseStmtList (Iterator current, Iterator &rest) |
Subgraph * | parseSubgraph (Iterator current, Iterator &rest) |
Private Attributes | |
Graph * | m_graph |
const Iterator | m_tend |
const Tokens | m_tokens |
DOT format abstract syntax tree class, based on official documentation.
To provide easier modification and improve code readability the DOT format parsing process is divided to three stages. Building an abstract syntax tree is the second one. AST elements are also involved in reading to Graph, GraphAttributes, ClusterGraph and ClusterGraphAttributes.
This class provide method for building such tree from a token list. The AST is then represented by tree of structures corresponding to DOT's language abstract grammar. That grammar is nearly 100% like official one - minor adjustments have been made just for my convenience. Neverthless, my version should be equal to the official one in terms of represented language.
Graph = [ 'strict' ] ( 'graph' | 'digraph' ) [ id ] '{' [ StmtList ] '}' Subgraph = [ 'subgraph' [ id ] ] '{' StmtList '}' StmtList = Stmt [ ';' ] [ StmtList ] Stmt = NodeStmt | EdgeStmt | AttrStmt | AsgnStmt | Subgraph NodeStmt = NodeId [ AttrList ] NodeId = id [ port ] EdgeStmt = ( NodeId | Subgraph ) EdgeRhs [ AttrList ] EdgeRhs = ( '--' | '->' ) ( NodeId | Subgraph) [ EdgeRhs ] AttrStmt = ( 'graph' | 'node' | 'edge' ) AttrList AsgnStmt = id '=' id AttrList = '[' [ AList ] ']' [ AttrList ] AList = AsgnStmt [ ',' ] [ AList ] Port = ':' id [ ':' CompassPt ] | ':' CompassPt CompassPt = ( 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw' | 'c' | '_' )
The AST building process tries to mirror given grammar as much as possible keeping the code clean and simple. Each grammar's nonterminal symbol has corresponding parse function. These parse functions take two args: current iterator and rest iterator. current iterator indicates a position where the parsing should begin. On successfull parse, function returns (pointer to) tree element and moves rest iterator to a place where it has ended. On failure, function returns nullptr
and does nothing to rest iterator.
Finally, non-list AST elements provide read methods. These functions allow to, surprisingly, read Graph structure and/or associated attributes. The entry point is Ast::Graph::read method which reads basic attributes like graph strictness and triggers recursively read of its ancestors.
Definition at line 112 of file DotParser.h.
|
private |
Definition at line 133 of file DotParser.h.
|
private |
Definition at line 132 of file DotParser.h.
Initializes AST building but does not trigger the process itself.
tokens | DOT format token list to build the AST. |
ogdf::dot::Ast::~Ast | ( | ) |
bool ogdf::dot::Ast::build | ( | ) |
Builds the DOT format AST.
Graph * ogdf::dot::Ast::root | ( | ) | const |
Returns the root of the AST (nullptr if none).
|
private |
Definition at line 138 of file DotParser.h.
Definition at line 136 of file DotParser.h.
Definition at line 135 of file DotParser.h.