Skip to content

Instantly share code, notes, and snippets.

@jasondown
Created August 3, 2021 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasondown/743596ce2c0ce5ebc12d9fe2e069cbe6 to your computer and use it in GitHub Desktop.
Save jasondown/743596ce2c0ce5ebc12d9fe2e069cbe6 to your computer and use it in GitHub Desktop.
public abstract class ParserState
{
private readonly Parser _parser;
protected ParserState(Parser parser)
{
_parser = parser;
InitRegex();
}
public Parser Parser
{
get { return _parser; }
}
protected Regex VariableRegex { get; private set; }
protected int ObjectTypeIndex { get; set; }
protected int ObjectIdIndex
{
get;
set;
}
// required by all state classes to handle specific
// parsing strategy
public abstract void ReadLine(string line);
public virtual void Reset()
{
// related to nested levels of code,
// tracking if we are ready for variable declarations etc.
}
protected void ParseVariable(string line)
{
// variable parsing logic here based on the regex below
}
private void InitRegex()
{
// Matching against variablename@variableid : type objectid;
// e.g. BinContent@1000 : Record 7302;
// VariableRegex is set here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment