antlr/antlr4 · error · Exception

missing start tag in pattern: %s

Error message

missing start tag in pattern: %s

What it means

Raised by ParseTreePatternMatcher.split() when the pattern contains more stop delimiters than start delimiters, i.e. a '>' appears with no opening '<'. The chunker requires balanced, paired delimiters.

Source

Thrown at runtime/Python3/src/antlr4/tree/ParseTreePatternMatcher.py:332

            if p == pattern.find(self.escape + self.start, p):
                p += len(self.escape) + len(self.start)
            elif p == pattern.find(self.escape + self.stop, p):
                p += len(self.escape) + len(self.stop)
            elif p == pattern.find(self.start, p):
                starts.append(p)
                p += len(self.start)
            elif p == pattern.find(self.stop, p):
                stops.append(p)
                p += len(self.stop)
            else:
                p += 1

        nt = len(starts)

        if nt > len(stops):
            raise Exception("unterminated tag in pattern: " + pattern)
        if nt < len(stops):
            raise Exception("missing start tag in pattern: " + pattern)

        for i in range(0, nt):
            if starts[i] >= stops[i]:
                raise Exception("tag delimiters out of order in pattern: " + pattern)

        # collect into chunks now
        if nt==0:
            chunks.append(TextChunk(pattern))

        if nt>0 and starts[0]>0: # copy text up to first tag into chunks
            text = pattern[0:starts[0]]
            chunks.add(TextChunk(text))

        for i in range(0, nt):
            # copy inside of <tag>
            tag = pattern[starts[i] + len(self.start) : stops[i]]
            ruleOrToken = tag
            label = None

View on GitHub (pinned to 7d5770395b)

Solutions

  1. Escape literal '>' characters in the pattern with the escape sequence
  2. Remove or pair the stray stop delimiter
  3. Consider different delimiters via setDelimiters when the target language is full of angle brackets

Example fix

# before
pattern = parser.compilePattern('<ID> > 3', 0)

# after
pattern = parser.compilePattern('<ID> \\> 3', 0)
Defensive patterns

Strategy: validation

Validate before calling

if pattern.count(matcher.start) < pattern.count(matcher.stop):
    raise ValueError('missing start tag in pattern')

Try / catch

try:
    p = matcher.compileTreePattern(pat, idx)
except Exception as e:
    if 'missing start tag' in str(e):
        # remove or escape stray '>'
        ...

Prevention

When it happens

Trigger: Compiling a pattern like 'ID > 42' or 'a > <ID>' where a stray '>' appears before or outside any tag.

Common situations: Matching source text that contains '>' (comparisons, closing brackets, generics) without escaping it.

Related errors


AI-assisted analysis of antlr/antlr4@7d5770395b (2026-08-14). Data as JSON: /api/errors/968e023e0ba012e7. Report an issue: GitHub.