masaori335 commented on code in PR #13665:
URL: https://github.com/apache/trafficserver/pull/13665#discussion_r3976832189
##########
tools/hrw4u/src/ast_nodes.py:
##########
@@ -77,33 +81,37 @@ class RegexValue:
raw: str
-ValueExpr = Union[LiteralStringValue, IdentValue, IPValue, ParamRef, int,
bool, tuple[IPValue, ...]]
+@dataclass(frozen=True, kw_only=True)
+class SetValue:
+ """An `in [...]` operand. Emitted as `(raw)`, so the brackets are stripped
but quoting is not."""
+ raw: str
@dataclass(frozen=True, kw_only=True)
-class Node:
- line: int
+class IpRangeValue:
+ """An `in {...}` operand. Emitted verbatim, braces included."""
+ raw: str
-@dataclass(frozen=True)
-class Target:
- namespace: str | None
- field: str
+ValueExpr = Union[LiteralStringValue, IdentValue, IPValue, ParamRef, int,
bool, IpRangeValue]
Review Comment:
Not taking the shared type, because the asymmetry tracks the grammar rather
than being an accident of modelling.
`hrw4u.g4`'s `value` rule admits `iprange` but not `set_`:
```
value
: number=NUMBER | str=STRING | TRUE | FALSE
| ident=IDENT | ip | iprange | paramRef
;
```
So an iprange is legal anywhere a value is — `_extract_value` returns
`IpRangeValue` for a plain `value` context — while a set is only reachable
after `in`. Folding both into `MembershipValue` and using it for
`Comparison.right` would make the type admit a set in positions the grammar
rejects, and would drop `IpRangeValue` from the one alias that correctly
describes where it can appear.
The confusion you're naming is real though — nothing at the definition said
why. Added a comment there:
```python
# IpRangeValue is a ValueExpr but SetValue is not, because the grammar's
`value` rule admits
# `iprange` and not `set_`: an iprange is legal anywhere a value is, a set
only after `in`.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]