Deparsing
Deparsing is the reverse process of parsing, which translates the AST back into code. Currently, Sidef supports deparsing into two languages with the -R lang command-line switch:
    -R perl
      Deparses the AST into valid Perl code.
    -R sidef
      Deparses the AST into valid Sidef code.
Example:
1
$ sidef -Rperl script.sf | perl
Copied!
The -Rsidef switch (or simply -r) is useful for verifying how the code is parsed.
Example:
1
$ sidef -r -E '1 + 2/3'
Copied!
Outputs:
1
(1)->+((2)->/(3));
Copied!
Deparsing can also be enabled in interactive mode:
1
$ sidef -i -r
2
Sidef 3.05 on linux
3
Type "help", "copyright" or "license" for more information.
4
>> [1,2,3].map { .sqrt }
5
[1, 2, 3]->map({|_| (_->sqrt()) });
6
>>
Copied!
Last modified 1yr ago
Copy link