Skip to content

Instantly share code, notes, and snippets.

@agocke
Created May 8, 2023 16:53
Show Gist options
  • Save agocke/77e8fcf2b3797c25e2c39bb9f632907a to your computer and use it in GitHub Desktop.
Save agocke/77e8fcf2b3797c25e2c39bb9f632907a to your computer and use it in GitHub Desktop.
ref struct Lexer
{
private Span<char> _buffer;
private int _loc;
public Lexer(Span<char> buffer)
{
_buffer = buffer;
_loc = 0;
}
/// Move past the next token, incrementing _loc
public void EatToken() { ... }
}
public static LexHelpers
{
public static EatHelper(ref Lexer lex) => lex.EatToken(); // Pass by ref to preserve mutation
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment