ohm-editor icon indicating copy to clipboard operation
ohm-editor copied to clipboard

Visualizer: Show a useful definition for inherited primitive rules

Open pdubroy opened this issue 9 years ago • 6 comments

In the grammar view, we now show the definition of inherited rules, e.g. ListOf, lower, etc. For rules that are parsed from a grammar, we show the original source, but for primitive rules (e.g. any) we should figure out something useful to show. Maybe something like any = (primitive rule with arity 1).

pdubroy avatar Mar 09 '16 12:03 pdubroy

Which are these primitive rules? Is there a list so we can "brainstorm" here a bit? I feel reminded of what Regex101 offers here:

screen shot 2016-03-10 at 2 50 24 pm

screen shot 2016-03-10 at 2 50 15 pm

So any could be something like Any single character plus a phrase for object matching.

mroeder avatar Mar 10 '16 22:03 mroeder

The primitive rules are all in the ProtoBuiltInRules grammar, which is the supergrammar of BuiltInRules (which every grammar in "userland" inherits from, at least transitively).

You can find ProtoBuiltInRules in src/Grammar.js.

On Thu, Mar 10, 2016 at 2:52 PM, mroeder [email protected] wrote:

Which are these primitive rules? Is there a list so we can "brainstorm" here a bit? I feel reminded of what Regex101 offers here:

[image: screen shot 2016-03-10 at 2 50 24 pm] https://cloud.githubusercontent.com/assets/160313/13687343/85917490-e6cf-11e5-8ae7-9f999b804b98.png

[image: screen shot 2016-03-10 at 2 50 15 pm] https://cloud.githubusercontent.com/assets/160313/13687338/7cf0d0ba-e6cf-11e5-8dce-e7f8657cae96.png

So any could be something like Any single character plus a phrase for object matching.

— Reply to this email directly or view it on GitHub https://github.com/cdglabs/ohm/issues/74#issuecomment-195086541.

alexwarth avatar Mar 11 '16 18:03 alexwarth

https://github.com/cdglabs/ohm/blob/master/src/Grammar.js#L286 ... and they already come with some explanation:

any: any object end: end of input space: a space -> Range('\x00', ' ') spaces: space* lower: a lowercase letter -> UnicodeChar('Ll') upper: an uppercase letter -> UnicodeChar('Lu') unicodeLtmo: -> UnicodeChar('Ltmo'), union of Lt (titlecase), Lm (modifier), and Lo (other) Boolean: -> TypeCheck('boolean') Number: -> TypeCheck('number') String: -> TypeCheck('string')

mroeder avatar Mar 11 '16 18:03 mroeder

Yes, I'm just not sure that's all you need to know -- the arity is necessary if you are going to write a semantic action for that rule. Also, TypeCheck and UnicodeChar are not really public things, so I don't think we should be showing them in the UI.

Maybe we should show something like:

lower (a lowercase letter) = /* a primitive rule with arity 1 */

pdubroy avatar Mar 11 '16 18:03 pdubroy

FWIW, I think all of the primitive rules have arity 1.

On Fri, Mar 11, 2016 at 10:53 AM, Patrick Dubroy [email protected] wrote:

Yes, I'm just not sure that's all you need to know -- the arity is necessary if you are going to write a semantic action for that rule. Also, TypeCheck and UnicodeChar are not really public things, so I don't think we should be showing them in the UI.

Maybe we should show something like:

`lower (a lowercase letter) = /* a primitive rule with arity 1 */

— Reply to this email directly or view it on GitHub https://github.com/cdglabs/ohm/issues/74#issuecomment-195496646.

alexwarth avatar Mar 11 '16 19:03 alexwarth

Good point.

pdubroy avatar Mar 11 '16 19:03 pdubroy