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

Fake Typescript support #562

Open
1 task done
StoneCypher opened this issue Jan 31, 2018 · 9 comments
Open
1 task done

Fake Typescript support #562

StoneCypher opened this issue Jan 31, 2018 · 9 comments

Comments

@StoneCypher
Copy link

Issue type

  • Feature Request

Wut

So, I'm actually pretty into @pjmolina 's typescript plugin from #514. However, at the end, it returns all.

I was hoping that you would help me cheat. I actually just want to write the signature to parse/1 slightly differently, by adding some kind of thing to the peg syntax that says "make this the return type of parse/1," and also by marking the in argument :string if there's an out type. Then, you'd just have to blindly typecast the last return value, et voila.

To a typescript (or flowtype) user, this would have a profound impact on checkability, even though it's fake.

How many cappucinos do I need to mail you in order to make this happen, and to what address would I send them

@StoneCypher
Copy link
Author

All I actually need is for the function's signature to be written like

function parse(input: string): MyType { ... }

(or whatever)

@Mingun
Copy link
Contributor

Mingun commented Jan 31, 2018

You can be inspired by this. Beforehand it is necessary to label types of all code blocks, it can be done with annotations. After this preparatory work it is possible to enter information on types in the generator.

@StoneCypher
Copy link
Author

@Mingun - this is interesting, but also very difficult to understand

Your annotation thing seems to be a near-ideal case here - that would allow the annotation of individual parsing rules with types, allowing the return of more than one real type

@reverofevil
Copy link

(The weird moment when I understood @Mingun is Russian too.)

Actually TypeScript won't make development of grammars any easier, because you have to annotate types everywhere, and because its type system is kinda broken. Recently I've made a small experiment on making a PEG.ts, and TypeScript's type checker spew such horrific error messages when I fed it with recursive types, that I couldn't even finish it.

I'd recommend to look rather into Infernu support.

@StoneCypher
Copy link
Author

@polkovnikov-ph - yeah, that choice isn't in my hands, and besides, as a 1990s c++ template dev, typescript's error messages do not scare me

@StoneCypher
Copy link
Author

anyway, what i need is to be able to add parsers to a typescript system, so, it is of value to me to get typescript annotations out of parse/1

right now i'm doing it with gross master types and casting. i wish i could do better

image

@pjmolina
Copy link

Hi! Related to this, in the plugin ts-pegjs we have implemented optional output typing for production rules. Issue 11, PR 16

We did it using a table of pairs "rule-name": "return-type" via the returnTypes option.

I am cc you, just in case you decided to optionally add type information on pegjs at the DSL level to anonnate productions directly.
It could be quite useful for TypeScript output, also for Flow, or any other typed JS variant.

@StoneCypher
Copy link
Author

People are still asking for this in #597

The new maintainer created and housed a .d.ts, so he's obviously open to typescript

This is a same-day "we have typescript" with no major changes, which can be done in five lines of code plus the replacement es6 module footer. I don't understand why it isn't being done

I have a patch ready against 0.11 but 0.11 isn't being merged, and 0.12 isn't available to work against

@zm-cttae-archive
Copy link

zm-cttae-archive commented Mar 31, 2023

metadevpro/ts-pegjs#92 - plan to enhance existing JS results using estree injection

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

5 participants