hrw4u: grammar accepts bare operator statements (`no-op;`) that can never compile

Open Beginner friendly
#13,701 0 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
compilers

Research direction

Start at tools/hrw4u/grammar/hrw4u.g4 around line 171 and compare the bare-operator alternative with the documented call form and separate break alternative. Remove the unreachable bare form, then check the tests/data corpus and confirm call-form operators still work while bare operators produce a syntax error.

Written by the indexing model from the issue text.

Description

hrw4u

Summary

The grammar has a statement alternative for a bare operator without parentheses:
https://github.com/apache/trafficserver/blob/13ef6a7618bda4c36835aab291de95d02e86f2ed/tools/hrw4u/grammar/hrw4u.g4#L171

Nothing written that way compiles. Every op is rejected, so the alternative is
unreachable and should be removed from the grammar.

Reproduce

source result
no-op(); no-op
no-op; error: This operator requires an argument
skip-remap;, set-debug; same error

Why remove rather than fix

The call form is the only form anything produces or documents:

producer form
doc/admin-guide/configuration/hrw4u.en.rst no-op();, set-debug(), skip-remap()
reverse conversion, u4wrh (src/hrw_symbols.py:315) always name()
test corpus (tests/data) no-op();, 0 bare-op inputs

Making the bare form work instead (check arity rather than validator presence)
would add a second spelling for the same statement with no caller asking for
it. break; is a separate alternative and is unaffected either way.

Trade-off: after removal, no-op; becomes an ANTLR syntax error rather than a
named one. If the friendlier message matters, it belongs in the suggestion
engine, not in a grammar alternative that produces no output.

Note

test_the_corpus_reaches_every_grammar_rule does not catch this: it records
rule names, and statement is reached through its other alternatives.

Dominant language
C++
Stars
2k
Forks
877
Avg merge
4d 18h
Merged PRs (30d)
52

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/trafficserver

All issues in apache/trafficserver

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.