close Warning: Can't synchronize with repository "(default)" (/var/svn/tolp does not appear to be a Subversion repository.). Look in the Trac log for more information.

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#1445 closed enhancement (fixed)

Unparse

Reported by: Alfredo Torre Owned by: Víctor de Buen Remiro
Priority: normal Milestone: Mantainance
Component: Kernel Version: 3.1
Severity: normal Keywords: Parse, Unparse
Cc: prcoco.bbvasp@…

Description (last modified by Víctor de Buen Remiro)

Hello,
¿would it be posible to have the inverse function of Parse?

This function would allow to build TOL expressions from a "Parse Set". Something like this:

Text txt01 = Unparse(Parse(__TOL_EXPRESSION__));

txt01 should be "the same" as TOL_EXPRESSION

Change History (6)

comment:1 Changed 13 years ago by Víctor de Buen Remiro

Description: modified (diff)

I think it could be possible, but the resulting expression will become the standarized form of initial one, not exactly the same.

There is no biyective relation between expressions and syntax trees. For example, you can add white spaces or line breaks or a final ';' to an expression without changing the resulting tree.

Set expr = [[
  "Real x = a&b",
  "Real x = a&b;",
  "Real x = a & b;"
]];

Set table = For(1,Card(expr),Set(Real k_)
{[[
  Real k = k_;
  Text expression = expr[k]; 
  Set tree = Parse(expression);
  Text tree_dump = ""<<tree
]]}); 

comment:2 Changed 13 years ago by Víctor de Buen Remiro

(In [4179]) Refs #1445

comment:3 Changed 13 years ago by Víctor de Buen Remiro

Resolution: fixed
Status: newclosed

(In [4180]) Fixes #1445
New methods TextEncoding::Parsing and TextEncoding::Unparsing

comment:4 Changed 13 years ago by Víctor de Buen Remiro

Here you can see an example of use:

#Require TextEncoding;
Text expression = ReadFile("check.01.tol");
Set tree.1 = TextEncoding::Parsing(expression);
Text unparsed.1 = TextEncoding::Unparsing(tree.1);
WriteLn("unparsed.1=\n"+unparsed.1+"\n");
Set tree.2 = TextEncoding::Parsing(unparsed.1);
Text unparsed.2 = TextEncoding::Unparsing(tree.2);
WriteLn("unparsed.2=\n"+unparsed.1+"\n");
Real ok = unparsed.1==unparsed.2;

comment:5 Changed 13 years ago by Alfredo Torre

Great!

Thank you very much.

Brilliant the check between two unparsed texts!

comment:6 Changed 13 years ago by Víctor de Buen Remiro

Sorry, version TextEncoding.2.1 is required.

Note: See TracTickets for help on using tickets.