Add -> operator to Dsp.g4 grammar - #126
Conversation
|
@copilot 搞错了, 应该和 |
Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
-> operator to BNF grammar-> operator to Dsp.g4 grammar
Co-authored-by: hzhangxyz <11623447+hzhangxyz@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds the -> (arrow) binary operator to the Dsp grammar file with the same precedence as the . (dot) operator by modifying the grammar rule to accept either operator at the same precedence level.
- Modified line 16 in the grammar to support both
.and->operators using ANTLR4's alternation syntax - Positioned the new operator above the subscript operator as required
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| | '(' term ')' # parentheses | ||
| | term '::' term # binary | ||
| | term '.' term # binary | ||
| | term ('.' | '->') term # binary |
There was a problem hiding this comment.
The examples in the PR description suggest that p -> q . y should parse as p -> (q . y) (right-associative), but the grammar implementation makes both . and -> left-associative by default in ANTLR4. This means p -> q . y will actually parse as (p -> q) . y. If right-associativity is intended for these operators, they would need separate grammar rules or explicit associativity directives. Please verify the expected associativity behavior and update the PR description examples if needed.
| | term ('.' | '->') term # binary | |
| | <assoc=right> term ('.' | '->') term # binary |
| | '(' term ')' # parentheses | ||
| | term '::' term # binary | ||
| | term '.' term # binary | ||
| | term ('.' | '->') term # binary |
There was a problem hiding this comment.
The new -> operator lacks test coverage. Given that comprehensive tests exist for other operators (binary, unary, subscript, function), tests should be added for the -> operator to verify parsing and unparsing behavior, especially its precedence relationship with . operator. Consider adding tests similar to test_parse_binary_operator and test_unparse_binary_operator that specifically test the -> operator.
Adds the
->(arrow) binary operator to the Dsp grammar with the same precedence as the.(dot) operator.Changes
bnf/Dsp.g4to| term ('.' | '->') term # binary, placing both.and->operators on the same line with equal precedence[](subscript) operator per requirementsExample
Original prompt
->这个operator</issue_title><issue_description>在
下面
上面
不需要添加readme或者docs</issue_description>
Comments on the Issue (you are @copilot in this section)
Original prompt
->这个operator #125💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.