Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse humanReadable program string #50

Open
nhamlv-55 opened this issue Apr 28, 2021 · 4 comments
Open

Parse humanReadable program string #50

nhamlv-55 opened this issue Apr 28, 2021 · 4 comments

Comments

@nhamlv-55
Copy link

Hello,
I was following the tutorial, but at this step
var ast = ProgramNode.Parse("Id(simpleInput)", grammar, ASTSerializationFormat.HumanReadable);
I got Unhandled exception. System.NotSupportedException: Deserializing human-readable ASTs is not supported.
In which Id is my identity function that does nothing.

If I use the equivalent XML as the input
program_string = "<NonterminalNode symbol=\"simpleOutput\" rule=\"Id\"><VariableNode symbol=\"simpleInput\" /></NonterminalNode>";
and parse with ASTSerializationFormat.XML, then it works.

I look into the code and it seems like only the XML format is currently supported. So given a more complicated function, like "Substring(x, PositionPair(AbsolutePosition(x, 0), AbsolutePosition(x, 5)))", how do I manually construct the XML to test?
Thanks.

@danpere
Copy link
Contributor

danpere commented Apr 28, 2021

Sorry, we have not updated the tutorial after we removed support for parsing ASTSerializationFormat.HumanReadable. The ambiguity of parsing such strings caused enough problems that we decided to disable that feature.

I think the XML for that program would be something like this:

<NonterminalNode symbol="?" rule="Substring">
    <VariableNode symbol="x" />
    <NonterminalNode symbol="?" rule="PositionPair">
    </NonterminalNode>
    <NonterminalNode symbol="?" rule="AbsolutePosition">
        <VariableNode symbol="x" />
        <LiteralNode symbol="k"><![CDATA[0]]></LiteralNode>
    </NonterminalNode>
    <NonterminalNode symbol="?" rule="AbsolutePosition">
        <VariableNode symbol="x" />
        <LiteralNode symbol="k"><![CDATA[5]]></LiteralNode>
    </NonterminalNode>
</NonterminalNode>

(I don't know the symbol names off the top of my head, so I've put in ? for those. You should be able to find them in the grammar.)

@nhamlv-55
Copy link
Author

nhamlv-55 commented Apr 28, 2021

Thank you. Where could I read more about the XML grammar? The XML that you have written for me doesn't look straightforward for me to apply somewhere else. For example, I could not have guessed the <![CDATA[5]]> part. Any pointer to read more about that?
Thanks a lot.

My use case is that I need to test my program first (kinda like running it 'forward', before asking Prose to learn the params for it via witness functions) to make sure that it indeed does the transformation that I want.

@danpere
Copy link
Contributor

danpere commented Apr 29, 2021

Sorry, there's no documentation on that. (Apologies, our documentation is a bit lacking; we know.) I found that XML example by running ProgramNode.PrintAst() and seeing what it looked like.

@nhamlv-55
Copy link
Author

Thanks.
But given that I only have the grammar and the semantics, how can I construct the ProgramNode? It is also the reason I want to parse the humanReadable string in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants