On 02/22/2014 10:25 AM, Anton Lavrik wrote:
> Can't think of such a way of the top of my head... The "default"
> property is defined as "any" which means it is holds a dynamically
> typed value. The actual semantics of the value is subject to a
> specific interpretation. In this case, it is the Piqi language
> implementation that handles it when you call it with --type piqi.
> Pure syntax-based conversion, obviously, wouldn't know how to
> interpret it.
Yeah, I understand that. Though wouldn't it make sense to remove
.default from piqi lang completely and just have it as a piqi spec only
extension?
>> I'm forced to use piqi-lang/piqi due to reasons discussed in the
>> previous thread.
>
> Can you remind me what was the reason? I tried to find it but there's
> just too much stuff and I don't want to misinterpret it.
The general problem is, vaguely, "you can't do everything in the XML
representation of piqi spec".
The first reason was that I couldn't define a piqi spec in XML with an
<erlang-type-prefix/>, i.e. this example fails:
$ cat foo.piqi.xml
<?xml version="1.0" encoding="UTF-8"?>
<value>
<module>foo</module>
<custom-field>erlang-type-prefix</custom-field>
<erlang-type-prefix></erlang-type-prefix>
<typedef>
<alias>
<name>foo</name>
<type>int32</type>
</alias>
</typedef>
</value>
$ piqi convert --type piqi -e erlang --piq-frameless-output true
foo.piqi.xml
Warning: foo.piqi.xml:4:16: unknown field: "custom-field"
Warning: foo.piqi.xml:5:22: unknown field: "erlang-type-prefix"
.module foo
.alias [
.name foo
.type int32
]
Notice: erlang-type-prefix declarations are gone.
To fix this, you suggested to do a purely syntax based conversion, i.e.
using `--type piqi-lang/piqi`. This works correctly, but now I'm facing
the problem described in this thread.
Moreover, I am now also using <erlang-name> and explicit piqi-lang
representations, to do the function I/O typename change we discussed in
a previous thread, which is not possible using piqi spec even in Piq.
Though I would rather drop this and somehow work around it, than give up
the availability of defaults.
I understand I'm doing unorthodox things here, however this mismatch
between possible functionality in different representations is a bit
confusing.
One possible hack for me would be to generate piqi spec in XML without
using the extra features, then desugar the XML into piqi-lang (so expand
defaults, function definitions, etc) and then do another transformation
on this XML to add things like <erlang-type-prefix> and <erlang-name>.
But earlier you mentioned there's no way to do the desugaring either, so
not sure.
I could also ditch generating XML completely, but since my initial
source of transformation is XML, it's much more elegant to at first
generate piqi in XML and then let piqi convert to the rest of the work.
Cheers,
Ignas
P.S. As an aside, I think bidirectional transformations between the
sugared and desugared forms would benefit piqi in the long term, just
like in any language! If only for being able to inspect "how things work".