From eduardoochs at id.uff.br Tue Feb 6 15:36:21 2024 From: eduardoochs at id.uff.br (Eduardo Nahum Ochs) Date: Tue, 6 Feb 2024 11:36:21 -0300 Subject: [pgf-tikz] Need help to understand the parser (and to draw parse trees) Message-ID: Hi list, I'm looking for some help to create parse trees for TikZ - not parse trees _in_ TikZ, parse trees _for_ Tikz, that would show how certain TikZ commands are parsed... Let me try to explain. I've been working on a certain set of tools for Lpeg that can display the parse tree of an expression like this one if (x>9) { x=0; y=y+1; } both as a tree in ascii art, like this one, Stmt__.________________. | | | if Expr__._____. Stmt | | | | Id Optr Num StmtList_______. | | | | | x > 9 Stmt__.__. Stmt__.__. | | | | | | Id = Expr Id = Expr__._____. | | | | | | x Num y Id Optr Num | | | | 0 y + 1 and as an underbrace diagram, like in this screenshot: http://anggtwu.net/IMAGES/emacsconf2023-repls-b.jpg http://anggtwu.net/emacsconf2023.html There are tons of examples in the TikZ manual that I don't know how to parse. Here's an example: \documentclass[]{book} \usepackage{tikz} \usetikzlibrary{arrows.meta, positioning} % \begin{document} \begin{tikzpicture}[ auto,bend right ] \node (a) at (0:1) {A}; \node (b) at (120:1) {B}; \node (c) at (240:1) {C}; \draw [->] (a) to (b); \draw [->] (b) to node {BC} (c); \draw [->] (c) to node [swap] {CA} (a); \end{tikzpicture} \end{document} I took it from the section "\subsection{Adding Labels Next to Lines}" in pgfmanual-en-tutorial-nodes.tex and modified it a bit. I _guess_ that its third \node its parsed in this way: Node__.__________________________________. | | | node NameAtCoordinate__.___. Contents | | | | Name at Coordinate {C} | | (c) CanvasPolar | (240:1) http://anggtwu.net/IMAGES/2024-ParseTikz1-1.png So: I know several places in the TikZ manual in which it explains \node, \draw, and \path in different levels of detail, and some of these places, like the \section{Syntax for Path Specifications} in pgfmanual-en-tikz-paths.tex, even try to explain what is the exact language that TikZ is able to parse... but the TikZ parser is still a mystery to me, and in constructs like these ones... \subsection{The Move-To Operation} \subsubsection{Horizontal and Vertical Lines} ...I don't have any good guesses on how to name certain subtrees of my parse trees. Questions: what are the internal names of move-to, -|, and |-? Where does the parser define support for them? Also, suppose that my approach works, and that I manage to produce, say, 20 nice underbrace diagrams showing how to parse TikZ commands that I found hard to understand... then I will need names for many non-terminals in the TikZ language, and I will need a good way to choose those names. Do you have any other suggestions on how to choose those names besides - this is just a wild guess - looking at the tex macros with names of the form such and such in tikz.code.tex? Also, btw, is the parser written by hand? Thanks in advance! Eduardo Ochs eduardoochs at gmail.com http://anggtwu.net/#eev http://anggtwu.net/eev-tikz.html P.S.: I'm sending this from a secondary e-mail because mailmain says that in my gmail address "You already have a subscription pending confirmation"... anyone knows how to solve that? -------------- next part -------------- An HTML attachment was scrubbed... URL: