Implement XPath abbreviate of parentheses and fix some bugs#328
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Extends the XPath abbreviation logic to cover additional XPath expression node types (arithmetic, grouping, unary negation) and adds tests to validate the new behavior.
Changes:
- Added parser tests for literals, unary/binary operators, grouping/parentheses, functions, and unknown nodes.
- Updated
abbreviateto delegate more node types topredicate_to_path. - Expanded
predicate_to_pathto format+,-,*, unary negation, and grouping nodes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/parser/test_xpath.rb | Adds test coverage for arithmetic/grouping/function formatting and unknown-node handling. |
| lib/rexml/parsers/xpathparser.rb | Updates abbreviation/serialization logic to support more parsed XPath node types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| when :neg | ||
| parsed.shift | ||
| path << "-" | ||
| path << predicate_to_path( parsed, &block ) |
| def test_unknown_not_infinitly_recursing | ||
| assert_instance_of(String, abbreviate([:unknown])) | ||
| end |
| when :function, :literal, :group, :neg, :and, :or, :mult, :plus, :minus, :neq, :eq, :lt, :gt, :lteq, :gteq, :div, :mod, :union | ||
| component = '' | ||
| components << component | ||
| parsed.unshift(op) | ||
| component << predicate_to_path(parsed) {|x| abbreviate(x)} |
| component << " )" | ||
| when :literal | ||
| component << quote_literal(parsed.shift) | ||
| when :function, :literal, :group, :neg, :and, :or, :mult, :plus, :minus, :neq, :eq, :lt, :gt, :lteq, :gteq, :div, :mod, :union |
There was a problem hiding this comment.
This is not good, but we need to do this to avoid infinite recursion of unknown operator.
predicate_to_path calls abbreviate if predicate_to_path doesn't know the operator.
Some possible workaround for this may break XPathParser#expand which is not tested and the spec is unknown.
b6a2707 to
7487772
Compare
Implement
abbreviateof parenthesized:groupadded in #317Also fixes these bugs so that we can test parenthesized xpaths such as
(1+2)*3