On 12/16/2013 03:26 AM, Anton Lavrik wrote:
> Essentially, if my understanding of your use case is correct, you
> need only two steps to achieve what you want:
>
> 1. Sugared XML -> Desugar to XML-encoded piqi-lang 2. convert the
> XML-encoded piqi-lang to .piqi as shown by the example in my
> previous reply
OK, after two hours of messing around with this, I *think* I figured it out:
Consider foobar.piqi:
### foobar.piqi ###
.module foobar
.record [
.name delete-output-type
.field [
.name id
.type int32
]
]
.function [
.name delete
.output delete-output-type
]
.erlang-type-prefix ""
#############
First of all, the the output of
piqi compile --self-spec piqi.piqi.pb -t xml -o foobar.xml foobar.piqi
is framed (i.e. wrapped in <piqi>) and piqi convert does not seem to
accept that with any of --type piqi, --type piqi/piqi or --type
piq-lang/piqi, it outputs:
(Warning: foobar.xml:3:8: unknown field: "piqi")
and produces no output.
But this is not so relevant for me (as I generate this and can just not
generate the <piqi> element). What I was confused about is that when
trying to do (assuming no <piqi> framing in foobar.xml):
piqi convert -e erlang --type piqi -f xml foobar.xml
this works, but you get:
Warning: foobar.xml:26:24: unknown field: "erlang-type-prefix"
Warning: foobar.xml:27:24: unknown field: "erlang-string-type"
and the unknown fields are dropped.
Alternatively, if you try:
piqi convert -e erlang --type piqi-lang/piqi -f xml foobar.xml
this fails in the presence of e.g. <function> definitions with
foobar.xml:23:14: exactly one XML element expected as a variant value
Line 23 is <output>delete-output-type</output>
It turns out I had to use `piqi convert` with `--type piqi/piqi`!
Perhaps this is something obvious, but I am personally a bit confused
about the whole extension mechanism. Maybe some time should be invested
in creating a few diagrams regarding the relationship between the three
types (piqi, piqi/piqi, piqi-lang/piqi) in the docs.
Also now when using piqic-erlang I get warnings (which are harmless, but
not nice to see):
Warning: blergh.piqi:21:1: unknown field: erlang-type-prefix
Warning: blergh.piqi:22:1: unknown field: erlang-string-type
though the output is correct (i.e. no prefixes) so they *are* recognised.
Anyway, I'm mostly posting this for documentation purposes, as it seems
I can do everything I want now.
I do think however that:
* the framing problem seems like a bug and should be fixed
* "more bidirectional transformations should be possible"
* the warnings in piqic-erlang should not be there
Thanks again,
Ignas
P.S. I owe you 10 beers if we meet at some conference or so!