src/cpp-common: add `bt2c::StrScanner` class
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 27 Oct 2023 19:21:05 +0000 (19:21 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 4 Sep 2024 19:05:14 +0000 (15:05 -0400)
commitdc64abe778d9e0dbed08a4f2fc30a8cf18147c2f
tree78515961488d4e6e0c791597315061dff0cfa46d
parent6f3c472e6b793025065c48f9576066dbb40a490d
src/cpp-common: add `bt2c::StrScanner` class

This patch adds the `bt2c::StrScanner` class, defined in
`str-scanner.hpp` and implemented in `str-scanner.cpp`.

A string scanner is a simple lexical scanner. This one is a
stripped-down version of yactfr's `yactfr::internal::StrScanner`,
stripped-down because yactfr uses this to parse TSDL, therefore it needs
more features.

What's left for the `bt2c::StrScanner` version is:

tryScanLitStr():
    Tries to scan a double-quoted literal string, possibly containing
    escape sequences.

tryScanConstInt():
    Tries to scan a constant unsigned or signed decimal integer string.

tryScanConstReal():
    Tries to scan a real number string.

tryScanToken():
    Tries to scan an exact string.

skipWhitespaces():
    Skips the next whitespaces.

See the specific comments in `str-scanner.hpp` for more details.

I could have used the `GScanner` API [1], as we do to parse the value of
the `--params` CLI option of `babeltrace2`, but:

• `yactfr::internal::StrScanner` is already working, tested,
  and documented.

  `bt2c::StrScanner` is a much lighter version of it.

• Should we ever make an effort to remove the GLib dependency, this part
  will already be done.

• The `GScanner` API doesn't support `\u` escape sequences in literal
  strings (needed for JSON strings) out of the box, so we'd need this
  part on our side anyway.

`bt2c::StrScanner` could eventually replace `GScanner` elsewhere in the
tree, but it would require a few more features (which already exist
in `yactfr::internal::StrScanner`, that is).

This is part of an effort to implement a JSON parser to
support CTF2‑SPEC‑2.0 [2].

[1]: https://docs.gtk.org/glib/struct.Scanner.html
[2]: https://diamon.org/ctf/CTF2-SPEC-2.0.html

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I8317917124218618278611794f32a67be4b9a6dd
Reviewed-on: https://review.lttng.org/c/babeltrace/+/7410
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12681
src/Makefile.am
src/cpp-common/bt2c/str-scanner.cpp [new file with mode: 0644]
src/cpp-common/bt2c/str-scanner.hpp [new file with mode: 0644]
This page took 0.024622 seconds and 4 git commands to generate.