kphp icon indicating copy to clipboard operation
kphp copied to clipboard

Add yaml parsing & emitting support

Open NikOsint opened this issue 2 years ago • 7 comments

KPHP YAML

Solution for Issue #639

Implementation of 4 functions from PHP YAML using yaml-cpp:

yaml_emit_file(string $filename, mixed $data): bool
yaml_emit(mixed $data): string
yaml_parse_file(string $filename, int $pos = 0): mixed
yaml_parse(string $data, int $pos = 0): mixed

C++ tests are written and implemented.

~~There is one major issue: strings like "10", "98.13' are emitted without quotes, so then they are parsed as integers and doubles respectively.~~

More informative README can be found here.

NikOsint avatar Dec 18 '22 18:12 NikOsint

@Tsygankov-Slava Thank you for your review! All the comments were taken into account and the corresponding parts of the code were corrected. Some other small improvements were done.

For now, the problem of emitting number strings such as "10", "5.34" without quotes remains due to poor documentation of yaml-cpp library. I will let you know when a solution is found.

NikOsint avatar Dec 23 '22 18:12 NikOsint

@Tsygankov-Slava @unserialize The problem of emitting numbers and numbers-as-strings has been solved.

Converting from mixed to a YAML document has been rewritten without use of yaml-cpp as it does not provide any way to emit strings with quotes and numbers without.

Also now booleans are parsed&emitted correctly (as booleans, not strings or integers).

More C++ tests has been written and a complex PHP test has been implemented, too.

For the PHP test to work, a 'yaml.so' extension has been added to the tests/python/lib/kphp_run_once.py file. Without it, the test would throw an error when running with PHP because PHP does not have its YAML module by default.

In the PHP test, serialize() method is used to output mixed. var_dump() is not used as its output is different in PHP and KPHP.

NikOsint avatar Feb 27 '23 19:02 NikOsint

Merged VKCOM:master into my master branch so that there are no conflicts.

NikOsint avatar Feb 28 '23 17:02 NikOsint

I'll try to review it next week

tolk-vm avatar Mar 09 '23 07:03 tolk-vm

Now special characters escaping is implemented.

The following characters are escaped:

  • Line feed as \n
  • Backspace as \b
  • Horizontal tab as \t
  • Vertical tab as \v
  • Backslash as \\
  • Double quote as \"

Single quote ' is not escaped since it does not act as a string delimiter because strings are covered in double quotes.

Please tell me if there are other symbols that should be escaped but were not taken into account yet.

NikOsint avatar May 22 '23 09:05 NikOsint

There is one major issue: strings like "10", "98.13' are emitted without quotes, so then they are parsed as integers and doubles respectively.

Is this issue (from PR description) still actual? I can't see such a behaviour looking at source code

tolk-vm avatar Oct 19 '23 15:10 tolk-vm

There is one major issue: strings like "10", "98.13' are emitted without quotes, so then they are parsed as integers and doubles respectively.

Is this issue (from PR description) still actual? I can't see such a behaviour looking at source code

No, it is outdated, now everything in double quotes is emitted as string Thanks for this remark, updated description

NikOsint avatar Oct 22 '23 12:10 NikOsint