We don't have an API like that in the scanner/parser, for two reasons:

a) Chunking -- data comes to the scanner in chunks (e.g. for streaming),
and we do very little rewinding when parsing, so we want to be able to
discard chunks once they're no longer needed.
b) Escaping -- you can have unicode escapes in strings and even in
identifiers, and those should be treated as the equivalent unicode
character.

So, for things like strings and identifiers, we actually copy the source
data into a local buffer while scanning, to be able to turn them into heap
strings after. It looks like you want to have a substring representation of
the source instead? Would it make sense for you to store the start and end
positions, and use those to get a substring of the script's source string?

On Sun, Oct 4, 2020 at 6:53 PM Gus Caplan <[email protected]> wrote:

>
> Hey folks, I'm trying to figure out how to capture a range of source text
> in the parser. Ideally the container of the source text is something that
> can easily be turned into a heap string.
>
> int start = peek_position();
> ParseAssignmentExpression();
> int end = end_position();
> auto source = somehow_get_source_text(start, end);
>
> Any advice is appreciated.
>
> --
> --
> v8-dev mailing list
> [email protected]
> http://groups.google.com/group/v8-dev
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/v8-dev/f6e9e16a-0335-4005-912c-069009492a0an%40googlegroups.com
> <https://groups.google.com/d/msgid/v8-dev/f6e9e16a-0335-4005-912c-069009492a0an%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/CAGRskv85-bT%3D33u6wausrM9yE%3DDqtr6yTrnU0aNmCm%3DA6OfUzg%40mail.gmail.com.

Reply via email to