kevinpt / syntrax Goto Github PK
View Code? Open in Web Editor NEWRailroad syntax diagram generator
Home Page: https://kevinpt.github.io/syntrax
License: MIT License
Railroad syntax diagram generator
Home Page: https://kevinpt.github.io/syntrax
License: MIT License
Hi,
is it possible to create a rounded bubble with a slash ("/") as text?
Cheers,
Ronny
On the main page, section "Toploop", there is this example:
toploop(line('(', 'forward', ')'), line(')', 'backward', '('))
which looks pretty, but it would mean, that after the forward part, with its closing brace, you close another brace, then comes the word "backward", then an opening brace.
Since the example might be completely made up, this could be valid syntax, but I guess what was meant was: toploop(line('(', 'forward', ')'), line('(', 'backward', ')'))
which looks awkward in the diagram, because of our habit to read from left to right, but more reasonable.
On the following spec file:
opt(loop('A',None))
syntrax 1.0 throws:
Rendering to test.png using cairo backend
Traceback (most recent call last):
File "/usr/local/bin/syntrax", line 11, in <module>
load_entry_point('syntrax==1.0', 'console_scripts', 'syntrax')()
File "/usr/local/lib/python2.7/dist-packages/syntrax.py", line 2028, in main
render_railroad(spec, args.title, url_map, args.output, backend, styles, args.scale, args.transparent)
File "/usr/local/lib/python2.7/dist-packages/syntrax.py", line 1747, in render_railroad
layout.draw_diagram(spec)
File "/usr/local/lib/python2.7/dist-packages/syntrax.py", line 1678, in draw_diagram
return self.draw_line(spec[1:])
File "/usr/local/lib/python2.7/dist-packages/syntrax.py", line 1287, in draw_line
t, texx, texy = self.draw_diagram(term) # Draw each element
File "/usr/local/lib/python2.7/dist-packages/syntrax.py", line 1695, in draw_diagram
return self.draw_or([None, args])
File "/usr/local/lib/python2.7/dist-packages/syntrax.py", line 1604, in draw_or
m[i] = mx = self.draw_diagram(term)
File "/usr/local/lib/python2.7/dist-packages/syntrax.py", line 1673, in draw_diagram
return self.draw_bubble(spec[0])
File "/usr/local/lib/python2.7/dist-packages/syntrax.py", line 1206, in draw_bubble
txt, node_style = self.format_text(txt)
File "/usr/local/lib/python2.7/dist-packages/syntrax.py", line 1182, in format_text
if re.match(ns.pattern, txt):
File "/usr/lib/python2.7/re.py", line 141, in match
return _compile(pattern, flags).match(string)
TypeError: expected string or buffer
I was attempting to use a separate library (syntrax
) and ran into the problem that gi is still using the old print statement. This isn't a problem in the larger sense. Normally when I run into projects like this I write a pull request to port the dependency to python3.
In this case, however, I discovered that gi
isn't a supported package anymore and the last release was in 2014.
If you look at the gi
dependency on pypi you'll find that it has a home page listed. If you look look at the project home page you'll see that the page is down and that inconditus
doesn't have it listed under their repositories anymore.
I would suggest moving to a new dependency if possible. I don't know enough about this space right now to suggest an alternative but if you'd like help I can find the time later to look into it.
syntrax
Traceback (most recent call last):
File "/Users/alexlord/.virtualenvs/presentations/lib/python3.6/site-packages/syntrax.py", line 20, in <module>
import pango
ModuleNotFoundError: No module named 'pango'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/alexlord/.virtualenvs/presentations/bin/syntrax", line 7, in <module>
from syntrax import main
File "/Users/alexlord/.virtualenvs/presentations/lib/python3.6/site-packages/syntrax.py", line 24, in <module>
from gi.repository import Pango as pango
File "/Users/alexlord/.virtualenvs/presentations/lib/python3.6/site-packages/gi/__init__.py", line 39
print url
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(t url)?
It seems that cairo
is a hard, non-conditional dependency:
Line 16 in eecc271
However, it's not listed as a dependency:
Line 33 in eecc271
Thus, simply installing and then importing syntrax
gives me:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/tmp.GgRTr2Nt4J/venv/lib/python3.6/site-packages/syntrax.py", line 16, in <module>
import cairo
ModuleNotFoundError: No module named 'cairo'
Users (including myself) will want to know how to generate an entire diagram from within Python. The constructor functions like loop()
are documented, but it would be nice if render_railroad()
were also documented.
Is it possible to define multiple graphs in a single source file? I.e., I'd like to get multiple productions in a single output file. Something like
line( '/sign', choice(None, '+', '-') ),
line( '/digit', 'test' )
and get two separate graphs in the output image.
Feature request:
Make the title (optional) part of the spec-file. Of course, it is possible to write a script, which takes the title from the filename, but not every useful attribute of a title is fine as filename. We like filenames to be short, but titles might sometimes be more verbose. If I work in an editor like Geany, I can configure it, so that it will produce a PNG when I hit the compile button, but the title has to be set manually, which makes it a less productive workflow.
The implementation might use an additional, optional key-value notation in the file, to keep all old spec files compatibel, or use an annotation in the comment section, to create a title.
Hello Kevin,
can Syntrax be used with Sphinx?
We are currently using Railroad Diagrams in our online documentation rendered with Sphinx on ReadTheDocs. It uses in-line JavaScript/JSON to describe the syntax diagram.
.. raw:: html
<style>
ddiv svg.railroad-diagram {
width: 80%; /* Scale to the width of the parent */
height: 100%; /* Preserve the ratio. Could be related to https://bugs.webkit.org/show_bug.cgi?id=82489 */
}
</style>
<link rel="stylesheet" href="../../_static/css/railroad-diagrams.css" />
<script type="text/javascript" src="../../_static/javascript/railroad-diagrams.js" ></script>
*.ini Format
############
.. raw:: html
<div>
<script type="text/javascript">
ComplexDiagram(
Choice(0,
NonTerminal('Section'),
Sequence(
Choice(0,
Sequence('#', NonTerminal('CommentText')),
Sequence(NonTerminal('WhiteSpace'))
),
Choice(0, '\\n', '\\r\\n', '\\r')
)
)
).addTo(this.parentElement);
</script>
</div>
GitHub: https://github.com/tabatkins/railroad-diagrams
Online editor: https://tabatkins.github.io/railroad-diagrams/generator.html
Kind regards
Patrick
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.