-1

Can't figure out how to match the node pattern for enum options.

Code I want to match, enum that has prefix: true (or scoped: true for later versions):

enum bla: { active: 0, not_active: 1 }, _prefix:true

Will get node as:

ruby-parse -e 'enum bla: { active: 0, not_active: 1 }, _prefix:true'

(send nil :enum
  (hash
    (pair
      (sym :bla)
      (hash
        (pair
          (sym :active)
          (int 0))
        (pair
          (sym :not_active)
          (int 1))))
    (pair
      (sym :_prefix)
      (true))))

My pattern:

'(send nil? :enum (hash (pair (sym {:_prefix :true}))))'

Tried out a bunch of versions without sym and nil/_.

What I'm doing wrong in this matching? Do I Need to skip nodes before the prefix node?

1 Answers1

1

You want to use the any order <> for keyword argument lookups:

(send nil? :enum (hash <(pair (sym :_prefix) true) ...>))

Also, the true in this pattern means a node that is true_type?, thus a node corresponding to a literal true in Ruby.

You can see it in action

Marc-André Lafortune
  • 78,216
  • 16
  • 166
  • 166