Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options documentation is confusing. #44

Closed
AlansCodeLog opened this issue Nov 9, 2019 · 6 comments
Closed

Options documentation is confusing. #44

AlansCodeLog opened this issue Nov 9, 2019 · 6 comments

Comments

@AlansCodeLog
Copy link

First in the readme some options are named with dashes and others aren't, not sure why?

Also I was trying to get returnTypes working and since there's no examples and it was grouped with the plugin options that went under the tspegjs property, I assumed it would go there. Had to search the code to find out what was going on.

A example in the readme using all the options possible would be nice.

Additionally I can't get returnTypes to work. I mean I can see it's typing all the rule functions, but since peg$parsestart is wrapped by peg$startRuleFunction and peg$parse is further typed as ParseFunction, both returning any, even if I set the start rule type, the type of parse is always any. Is this intended? Should I open an issue?

@Enteee
Copy link

Enteee commented Feb 4, 2020

Yep can confirm. Just spent a few hours trying to get returnType working before checking the code.

Additionally I can't get returnTypes to work. I mean I can see it's typing all the rule functions, but since peg$parsestart is wrapped by peg$startRuleFunction and peg$parse is further typed as ParseFunction, both returning any, even if I set the start rule type, the type of parse is always any. Is this intended? Should I open an issue?

There is more information about this in this issue: #11 . Especially in this comment by @pjmolina. If I get this right, @pjmolina suggest wrapping parse.

I am struggling a bit with typing intermediate production rules. Which always seem to fail. A bit of documentation around this would be nice as well.

@wy193777
Copy link

So if I understand it right, there is no way to specify types for parse function from returnTypes?

@Enteee
Copy link

Enteee commented Feb 26, 2020

@wy193777 as far as I understand it this is correct. But you can do what I did and wrap parse to force a typed parse.

@pjmolina
Copy link
Contributor

@AlansCodeLog First in the readme some options are named with dashes and others aren't, not sure why?

  • Options with long names uses double-dashes -- like in --cache.
  • Short-hands options (one letter) uses single-dashes - like in -o, some time they can be grouped when working as binary flags like in -oc.
  • In code options (JS) uses no dashes as it is JSON objects.
    The first two conventions are inherited from pegjs and this inherits for common practice in the UNIX/POSIX world.

A example in the readme using all the options possible would be nice.

You are right, I will prepare a better documentation for this.
So far, the best example is to take a look to one example here.

As commented, ts-pegjs is a plugin for pegjs this involves:

  • knowledge about how pegjs works (not repeating here what is already documented on pegjs)
  • it is a soft rewrite to TS of what is actually generated by JS.
  • so typing here is more than a hack on the final public production rules than a proper and complete typings. As discussed before complete typings should be done extending the pegjs grammar to accept types as first citizens.

@AlansCodeLog
Copy link
Author

Options with long names uses double-dashes -- like in --cache.
Sorry I wasn't clearer, I meant that some of the options are named like some-option and some in CamelCase. Felt a bit weird and inconsistent.

Also I tested the example, and it has the same issue I described. The export ends up getting typed as any. I filed the issue because I was wondering if this was intentional. I mean, I guess it's a bit helpful for the output to be typed, but I was expecting the plugin to type the parse function it exports (using the start rule, or a union of possible rules) for consumption. I have ended up just re-exporting the function with the types I want, but it would help to clarify this needs to be done.

so typing here is more than a hack on the final public production rules than a proper and complete typings. As discussed before complete typings should be done extending the pegjs grammar to accept types as first citizens.

Yeah too bad development seems to have stalled. Anyways, I have something satisfactory working, and at least now there's this issue if others are wondering about this.

@pjmolina
Copy link
Contributor

pjmolina commented Mar 6, 2020

Oh. About camelCase and snake-case. It is the same POSIX standard uses snake-case. When used on json objects converted to camelCase.

Typing parse() with a union of types is a good idea. I will work on a PR for that or feel free to make it if you like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants