From 0e90d68efabf613e79eb85b7349d6270901e007a Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 2 Feb 2019 19:49:26 -0800 Subject: [PATCH] Added XML format outputter --- lib/tools/parse.nom | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/tools/parse.nom b/lib/tools/parse.nom index a7e306e..f0c35a3 100755 --- a/lib/tools/parse.nom +++ b/lib/tools/parse.nom @@ -37,6 +37,23 @@ use "commandline" else: say "\$indent \(quote $arg)" +($ as xml) means: + when (type of $) is: + "a Syntax Tree": + $body = ([: for $bit in $: add ($bit as xml)], joined with " ") + if ($.type == "Action"): + return (" + \$body + ") + ..else: + return (" + <\($.type)>\$body + ") + "Text": + return ($, with "&" -> "&", with "\"" -> """, with "'" -> "'", with "<" -> "<", with ">" -> ">") + else: + return "\$" + command line program with $args: for $filename in $args.extras: $file = (read file $filename) @@ -44,4 +61,7 @@ command line program with $args: fail "File does not exist: \$filename" $nomsu = (NomsuCode from (Source $filename 1 (size of $file)) $file) $tree = ($nomsu parsed) - print tree $tree at indent "" + if ($args.x or $args.xml): + say ($tree as xml) + ..else: + print tree $tree at indent ""