Skip to content

A scan_peek in core:text/scanner #800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ThisDevDane opened this issue Dec 6, 2020 · 3 comments
Closed

A scan_peek in core:text/scanner #800

ThisDevDane opened this issue Dec 6, 2020 · 3 comments
Assignees

Comments

@ThisDevDane
Copy link
Member

Is your feature request related to a problem? Please describe.
In core:text/scanner I want a peek that actually does the scan behavior but resets the position in the data instead of just giving us the next rune.

Describe the solution you'd like
A probably smarter solution than below as I believe a few of them are reset anyway each scan/advance:

scan_peek :: proc(s: ^Scanner) -> rune {
    src_pos := s.src_pos;
    src_end := s.src_end;
    tok_pos := s.tok_pos;
    tok_end := s.tok_end;
    ch := s.ch;
    line := s.line;
    column := s.column;
    prev_line_len := s.prev_line_len;
    prev_char_len := s.prev_char_len;

    tok := scan(s);

    s.src_pos = src_pos;
    s.src_end = src_end;
    s.tok_pos = tok_pos;
    s.tok_end = tok_end;
    s.ch = ch;
    s.line = line;
    s.column = column;
    s.prev_line_len = prev_line_len;
    s.prev_char_len = prev_char_len;

    return tok;
}
@gingerBill
Copy link
Member

Implemented with scanner.peek_n with commit 96d8971

@ThisDevDane
Copy link
Member Author

ThisDevDane commented Dec 7, 2020

That does not implement the scan behavior? It just calls next which calls peek which calls advance?.

@ThisDevDane ThisDevDane reopened this Dec 7, 2020
@gingerBill
Copy link
Member

Whoops. I'll add peek_token_n too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants