I was wondering if other parser/code generator implementers has some words of wisdom about implementing code to apply resource types and traits to resources and method.
The spec is silent on the topic of collisions and precedence, but it seems that what makes the most sense is for say in a method hierarchy scalar properties having precedence over trait scalar properties and non-scalar properties being merged. Thus, the method is a specialization of the trait.
Similarly, the later or right most trait on a method should have high precedence, and method traits have higher precedence than resource traits.
This is simple enough to implement by say merging traits into the method in reversed precedence other ensuring that existing scalar properties are not overwritten.
The problem arrises when one tries to implement optional properties. When they are involved the method is not so much seen as a specialization of the traits, as the optional properties depend on values in the method. Implementing optional properties works best by merging the trait into the method and checking for the property existence to determine whether to apply a portion of the trait. If you have multiple traits you have to evaluate them from resource traits to method traits from left to right, as later traits may depend on keys created by earlier traits to be applied. But evaluating from earliest to latest is tricky. You want later trait scalars to override previous trait scalars, but not the method scalars.
Not sure if I was clear, but thoughts?