Documentation
¶
Overview ¶
Package dot provides a parser for the DOT language.
The parser implements an error-resilient recursive descent parser that produces a concrete syntax tree (CST) representation of DOT source code. It can parse syntactically invalid input and recover to continue parsing, collecting all errors encountered during parsing.
DOT Grammar ¶
The parser implements the following grammar from the DOT language specification:
graph : [ 'strict' ] ( 'graph' | 'digraph' ) [ ID ] '{' stmt_list '}'
stmt_list : [ stmt [ ';' ] stmt_list ]
stmt : node_stmt | edge_stmt | attr_stmt | ID '=' ID | subgraph
attr_stmt : ( 'graph' | 'node' | 'edge' ) attr_list
attr_list : '[' [ a_list ] ']' [ attr_list ]
a_list : ID '=' ID [ ( ';' | ',' ) ] [ a_list ]
edge_stmt : ( node_id | subgraph ) edgeRHS [ attr_list ]
edgeRHS : edgeop ( node_id | subgraph ) [ edgeRHS ]
node_stmt : node_id [ attr_list ]
node_id : ID [ port ]
port : ':' ID [ ':' compass_pt ] | ':' compass_pt
subgraph : [ 'subgraph' [ ID ] ] '{' stmt_list '}'
compass_pt : 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw' | 'c' | '_'
Where edgeop is '--' for undirected graphs and '->' for directed graphs.
Index ¶
- func FirstID(tree *Tree) (token.Token, bool)
- func TokenAt(tree *Tree, want token.Kind, at int) (token.Token, bool)
- func TokenFirst(tree *Tree, want token.Kind) (token.Token, bool)
- func TokenFirstWithin(tree *Tree, want token.Kind, last int) (token.Token, int, bool)
- type Child
- type Error
- type Format
- type Parser
- type Scanner
- type TokenChild
- type Tree
- type TreeChild
- type TreeKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TokenAt ¶
TokenAt returns the child token at semantic index if it matches want. Comments are skipped.
func TokenFirst ¶
TokenFirst returns the first child token matching want.
Types ¶
type Child ¶
type Child interface {
// contains filtered or unexported methods
}
Child is a marker interface for tree node children. Implementations are TreeChild and TokenChild.
type Error ¶
Error represents a parse error in DOT source code. The position Pos points to the beginning of the offending token, and the error condition is described by Msg.
type Format ¶
type Format int
Format specifies the output representation for rendering a Tree.
const ( // Default renders the formatted output as indented text. Default Format = iota // Scheme renders the tree as S-expressions with position annotations. Each node is rendered // as (NodeType (@ startLine startCol endLine endCol) children...) and tokens are rendered as // ('token' (@ startLine startCol endLine endCol)). Scheme )
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses DOT language source code into a concrete syntax tree.
Parser continues parsing after encountering errors, collecting all errors for later retrieval via Parser.Errors.
The parser uses one token of lookahead (LL(1)) and produces a Tree that preserves all tokens from the source.
func (*Parser) Parse ¶
Parse parses the DOT source code and returns the concrete syntax tree representation.
The returned Tree has type [File] and contains zero or more graphs. Parse always returns a tree, even when errors are encountered. Syntax errors are collected and can be retrieved via Parser.Errors.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner tokenizes DOT language source code into a stream of tokens.
func NewScanner ¶
NewScanner creates a new scanner that tokenizes the given DOT source code.
func (*Scanner) Next ¶
Next advances the scanners position by one token and returns it. When encountering invalid input, the scanner continues scanning. Invalid input results in a token of type token.ERROR with the error message in token.Token.Error that greedily consumes characters until a separator is encountered. A token of type token.EOF is returned once the end of input is reached.
type TokenChild ¶
TokenChild wraps a token.Token as a child of a tree node.
type Tree ¶
Tree represents a node in the concrete syntax tree.
Type identifies the syntactic construct (e.g., [Graph], [NodeStmt], [ID]). Children contains the node's children in source order, which may be either TreeChild (subtrees) or TokenChild (tokens). Start and End mark the source positions.
func TreeAt ¶
TreeAt returns the child tree at semantic index if it matches want. Comments are skipped.
func TreeFirstWithin ¶
TreeFirstWithin returns the first child tree matching want within [0, last]. Comments are skipped.
type TreeChild ¶
type TreeChild struct {
*Tree
}
TreeChild wraps a Tree as a child of another tree node.
type TreeKind ¶
type TreeKind uint32
TreeKind represents the type of syntax tree node (non-terminals).
const ( KindErrorTree TreeKind = 1 << iota // Graph structure KindFile KindGraph KindSubgraph // Statements KindStmtList KindNodeStmt KindEdgeStmt KindAttrStmt // Node and Edge components KindNodeID KindPort KindCompassPoint // Attributes KindAttrList KindAList KindAttribute KindAttrName KindAttrValue KindID )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ast provides an abstract syntax tree representation for DOT graphs.
|
Package ast provides an abstract syntax tree representation for DOT graphs. |
|
cmd
|
|
|
dotx
command
|
|
|
internal
|
|
|
assert
Package assert provides runtime assertion checking for invariants.
|
Package assert provides runtime assertion checking for invariants. |
|
format
Package format provides file and directory formatting for DOT files.
|
Package format provides file and directory formatting for DOT files. |
|
layout
Package layout provides a declarative toolkit for building pretty printers and code formatters.
|
Package layout provides a declarative toolkit for building pretty printers and code formatters. |
|
version
Package version provides build version information.
|
Package version provides build version information. |
|
Package lsp implements a Language Server Protocol server for the DOT graph language.
|
Package lsp implements a Language Server Protocol server for the DOT graph language. |
|
internal/attribute
Package attribute provides Graphviz attribute definitions and types.
|
Package attribute provides Graphviz attribute definitions and types. |
|
internal/completion
Package completion provides autocompletion for DOT graph attributes.
|
Package completion provides autocompletion for DOT graph attributes. |
|
internal/diagnostic
Package diagnostic provides parse error diagnostics for DOT graph files.
|
Package diagnostic provides parse error diagnostics for DOT graph files. |
|
internal/hover
Package hover provides hover documentation for DOT graph elements.
|
Package hover provides hover documentation for DOT graph elements. |
|
internal/navigate
Package navigate provides code navigation features for DOT graph documents.
|
Package navigate provides code navigation features for DOT graph documents. |
|
internal/rpc
Package rpc implements JSON-RPC 2.0 message types for the Language Server Protocol.
|
Package rpc implements JSON-RPC 2.0 message types for the Language Server Protocol. |
|
internal/tree
Package tree provides utilities for traversing DOT syntax trees.
|
Package tree provides utilities for traversing DOT syntax trees. |
|
Package printer prints DOT syntax trees formatted in the spirit of [gofumpt].
|
Package printer prints DOT syntax trees formatted in the spirit of [gofumpt]. |
|
Package token defines constants representing the lexical tokens of the DOT language together with operations like printing, detecting Keywords or identifiers.
|
Package token defines constants representing the lexical tokens of the DOT language together with operations like printing, detecting Keywords or identifiers. |
|
Package watch provides a file watcher that serves DOT graphs as SVG via HTTP.
|
Package watch provides a file watcher that serves DOT graphs as SVG via HTTP. |