antlr/antlr4 · error · ArgumentException
stop cannot be null or empty
Error message
stop cannot be null or empty
What it means
ParseTreePatternMatcher.SetDelimiters rejects a null or empty stop delimiter. The stop delimiter closes a tag in a pattern string; without it the tag scanner cannot find tag boundaries, so the call fails fast. Note the escape (third) argument is not validated — only start and stop are.
Source
Thrown at runtime/CSharp/src/Tree/Pattern/ParseTreePatternMatcher.cs:222
/// or empty.
/// </exception>
/// <exception>
/// IllegalArgumentException
/// if
/// <paramref name="stop"/>
/// is
/// <see langword="null"/>
/// or empty.
/// </exception>
public virtual void SetDelimiters(string start, string stop, string escapeLeft)
{
if (string.IsNullOrEmpty(start))
{
throw new ArgumentException("start cannot be null or empty");
}
if (string.IsNullOrEmpty(stop))
{
throw new ArgumentException("stop cannot be null or empty");
}
this.start = start;
this.stop = stop;
this.escape = escapeLeft;
}
/// <summary>
/// Does
/// <paramref name="pattern"/>
/// matched as rule
/// <paramref name="patternRuleIndex"/>
/// match
/// <paramref name="tree"/>
/// ?
/// </summary>
public virtual bool Matches(IParseTree tree, string pattern, int patternRuleIndex)
{
ParseTreePattern p = Compile(pattern, patternRuleIndex);View on GitHub (pinned to 7d5770395b)
Solutions
- Pass a non-empty stop delimiter, e.g. SetDelimiters("[", "]", "\\").
- Check both delimiter values with string.IsNullOrEmpty before calling and report which one is missing.
- Keep the default delimiters ('<', '>') unless there is a concrete grammar conflict with angle brackets.
Example fix
// before
matcher.SetDelimiters("[", "", "\\");
// after
matcher.SetDelimiters("[", "]", "\\"); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(start) || string.IsNullOrEmpty(stop)) throw new ConfigurationErrorsException("tag delimiters must be non-empty");
matcher.SetDelimiters(start, stop, escape); Type guard
static bool IsValidDelimiter(string s) => !string.IsNullOrEmpty(s);
Prevention
- Treat delimiters as a pair and validate both together.
- Unit-test delimiter configuration at startup before parsing begins.
When it happens
Trigger: Calling matcher.SetDelimiters("[", "", "\\") or SetDelimiters("[", null, ...) — e.g. reading delimiters from user input where only the opening one was provided.
Common situations: Delimiter pairs configured from a single config value where the closing one is derived incorrectly; interactive tooling that lets users set tag delimiters; typos in the argument order (start/stop swapped or escape passed in the stop slot).
Related errors
- start cannot be null or empty
- Invalid state number.
- The ATN must be a lexer ATN.
- tree cannot be null
- patternTree cannot be null
AI-assisted analysis of antlr/antlr4@7d5770395b (2026-08-14).
Data as JSON: /api/errors/589e213980072213.
Report an issue: GitHub.