aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-09-23 21:42:31 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-09-23 22:23:47 +0200
commit484fffc6c5946b8d90decb803bfc9e318ba3a2e0 (patch)
treeb930e52badc13f029479c027321706000047dca0
parentDocument and parameterize use2dot-all. (diff)
downloadcalp-484fffc6c5946b8d90decb803bfc9e318ba3a2e0.tar.gz
calp-484fffc6c5946b8d90decb803bfc9e318ba3a2e0.tar.xz
Document and parameterize peg-to-graph.
-rwxr-xr-xmodule/scripts/peg-to-graph.scm46
1 files changed, 30 insertions, 16 deletions
diff --git a/module/scripts/peg-to-graph.scm b/module/scripts/peg-to-graph.scm
index 0472fd02..e2a829f9 100755
--- a/module/scripts/peg-to-graph.scm
+++ b/module/scripts/peg-to-graph.scm
@@ -4,10 +4,20 @@
:use-module ((hnh module-introspection static-util) :select (get-forms))
:use-module (srfi srfi-1)
:use-module (ice-9 match)
+ :use-module (hnh util options)
+ :use-module (ice-9 getopt-long)
:export (main))
+(define option-spec
+ `((engine (value #t)
+ (description "Graphviz rendering engine to use. Defaults to DOT"))
+ (output (single-char #\o)
+ (value #t)
+ (description "Name of output pdf"))))
+
(define %summary "Output peg-pattern relations as a graphviz graph.")
-(define %include-in-list #t)
+(define %synopsis "peg-to-graph [options] <filename>")
+(define %help (format-arg-help option-spec))
(define peg-primitives
'(and or * + ? followed-by not-followed-by peg-any range
@@ -30,20 +40,24 @@
(unique-symbols (list body)))))))
(define (main . args)
- (when (< 1 (length args))
- (format #t "Usage: guild peg-to-graph <filename>~%")
- (exit 1))
+ (define options (getopt-long (cons "peg-to-graph" argrs)
+ (getopt-opt option-spec)))
+ (define engine (option-ref options 'engine "dot"))
+ (define output-file (option-ref options 'output "lex2.pdf"))
+ (define input-file (let ((filenames (option-ref options '() '())))
+ (when (null? filenames)
+ (format #t "Usage: ~a~%" %summary)
+ (exit 1))
+ (car filenames)))
+
(let ((graph (gv:digraph "G")))
- (let ((input-file (car args)))
- (for-each (lambda (form) handle-peg-form! graph form)
- (filter (lambda (x)
- (and (list? x)
- (not (null? x))
- (eq? 'define-peg-pattern (car x))))
- (call-with-input-file input-file get-forms))))
-
- (gv:layout graph "dot")
- (gv:render graph "pdf" "lex2.pdf")
-
- (display "done\n")))
+ (for-each (lambda (form) handle-peg-form! graph form)
+ (filter (lambda (x)
+ (and (list? x)
+ (not (null? x))
+ (eq? 'define-peg-pattern (car x))))
+ (call-with-input-file input-file get-forms)))
+
+ (gv:layout graph engine)
+ (gv:render graph "pdf" output-file)))