XML::Invisible - transform "invisible XML" documents into XML using a grammar
use XML::Invisible qw(make_parser); my $transformer = make_parser(from_file($ixmlspec)); my $xmldoc = $transformer->(from_file($ixml_input)); to_file($outputfile, $xmldoc->toStringC14N(1)); # or, with conventional pre-compiled Pegex grammar my $parser = Pegex::Parser->new( grammar => My::Thing::Grammar->new, receiver => XML::Invisible::Receiver->new, ); my $got = $parser->parse($input); # from command line cpanm XML::Invisible XML::Twig perl -MXML::Invisible=make_parser -e \ 'print make_parser(join "", <>)->("(a+b)")->toStringC14N(1)' \ examples/arith-grammar.ixml | xml_pp
An implementation of Steven Pemberton's Invisible XML concept, using Pegex. Supply it with your grammar, in Pegex format (slightly different from Steven's specification due to differences between his notation and Pegex's), it returns you a function, which you can call to transform "invisible XML" documents into actual XML.
This is largely a Pegex "receiver" class that exploits the + and - syntax in rules in slightly unintended ways, and a wrapper to make this operate.
+
-
See Pegex::Syntax. Generally, all rules will result in an XML element. All terminals will need to capture with () (see example below).
()
However, if you specify a dependent token with + it will instead become an attribute (equivalent of Steven's @). If -, this will "flatten" (equivalent of Steven's -) - the children will be included without making an element of that node. Since in Pegex any element can be skipped entirely with ., you can use that instead of - to omit terminals.
@
.
E.g.
expr: +open -arith +close open: /( LPAREN )/ close: /( RPAREN )/ arith: left -op right left: +name right: -name name: /(a)/ | /(b)/ op: +sign sign: /( PLUS )/
When given (a+b) yields:
(a+b)
<expr open="(" sign="+" close=")"> <left name="a"/> <right>b</right> </expr>
Exportable. Returns a function that when called with an "invisible XML" document, it will return an object of class XML::LibXML::Document.
Arguments:
Exportable. The function used by "make_parser" to turn an AST from XML::Invisible::Receiver into an object of class XML::LibXML::Document.
To debug, set environment variable XML_INVISIBLE_DEBUG to a true value.
XML_INVISIBLE_DEBUG
Pegex
https://homepages.cwi.nl/~steven/ixml/ - Steven Pemberton's Invisible XML page
Ed J, <etj at cpan.org>
<etj at cpan.org>
Please report any bugs or feature requests on https://github.com/mohawk2/xml-invisible/issues.
Or, if you prefer email and/or RT: to bug-xml-invisible at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=XML-Invisible. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-xml-invisible at rt.cpan.org
Copyright 2018 Ed J.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
To install XML::Invisible, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::Invisible
CPAN shell
perl -MCPAN -e shell install XML::Invisible
For more information on module installation, please visit the detailed CPAN module installation guide.