Jump to page: 1 2
Thread overview
ES6 Parser in Dlang
Feb 27, 2020
James Lu
Feb 27, 2020
Dejan Lekic
Feb 27, 2020
JN
Feb 27, 2020
Sönke Ludwig
Feb 27, 2020
Meta
Feb 27, 2020
Stefan Koch
Feb 27, 2020
Sebastiaan Koppe
Feb 27, 2020
aberba
Feb 28, 2020
drug
Feb 28, 2020
Sebastiaan Koppe
Feb 28, 2020
drug
Feb 28, 2020
Sebastiaan Koppe
Mar 02, 2020
James Lu
Feb 27, 2020
Walter Bright
February 27, 2020
I want to implement an ES6 (JavaScript) parser in Dlang so I can implement a transpiler. Because it's a transpiler, I need to be able to visit and rewrite AST nodes, then generate code from the AST. Ideally, the parser generator supports streaming the input into the AST visitor out to the output.

What parser generator library should I use for this purpose?
February 27, 2020
On Thursday, 27 February 2020 at 14:06:19 UTC, James Lu wrote:
> I want to implement an ES6 (JavaScript) parser in Dlang so I can implement a transpiler. Because it's a transpiler, I need to be able to visit and rewrite AST nodes, then generate code from the AST. Ideally, the parser generator supports streaming the input into the AST visitor out to the output.
>
> What parser generator library should I use for this purpose?

Have a look at similar work: https://github.com/higgsjs/Higgs
February 27, 2020
On Thursday, 27 February 2020 at 14:06:19 UTC, James Lu wrote:
> I want to implement an ES6 (JavaScript) parser in Dlang so I can implement a transpiler. Because it's a transpiler, I need to be able to visit and rewrite AST nodes, then generate code from the AST. Ideally, the parser generator supports streaming the input into the AST visitor out to the output.
>
> What parser generator library should I use for this purpose?

Check this out: http://code.dlang.org/packages/es6-grammar looks like a good starting point.
February 27, 2020
Am 27.02.2020 um 15:06 schrieb James Lu:
> I want to implement an ES6 (JavaScript) parser in Dlang so I can implement a transpiler. Because it's a transpiler, I need to be able to visit and rewrite AST nodes, then generate code from the AST. Ideally, the parser generator supports streaming the input into the AST visitor out to the output.
> 
> What parser generator library should I use for this purpose?

There is also DMDScript, which is more or less ECMAScript v3. It should pretty straight forward to get that updated to v5, as there haven't many parser related changes (property getters/setters is an exception). I was already thinking of whether it makes sense to invest that work, because that would enable running the TypeScript compiler through it.

v6 has a few more parser related changes, but still nothing really bad. The DMDScript parser is in https://github.com/DigitalMars/DMDScript/blob/master/engine/source/dmdscript/parse.d

Higgs is much closer to ES6, though.
February 27, 2020
On Thursday, 27 February 2020 at 14:06:19 UTC, James Lu wrote:
> I want to implement an ES6 (JavaScript) parser in Dlang so I can implement a transpiler. Because it's a transpiler, I need to be able to visit and rewrite AST nodes, then generate code from the AST. Ideally, the parser generator supports streaming the input into the AST visitor out to the output.
>
> What parser generator library should I use for this purpose?

There's also Pegged:

https://code.dlang.org/packages/pegged
February 27, 2020
On Thursday, 27 February 2020 at 16:49:19 UTC, Meta wrote:
> On Thursday, 27 February 2020 at 14:06:19 UTC, James Lu wrote:
>> I want to implement an ES6 (JavaScript) parser in Dlang so I can implement a transpiler. Because it's a transpiler, I need to be able to visit and rewrite AST nodes, then generate code from the AST. Ideally, the parser generator supports streaming the input into the AST visitor out to the output.
>>
>> What parser generator library should I use for this purpose?
>
> There's also Pegged:
>
> https://code.dlang.org/packages/pegged

http://code.dlang.org/packages/es6-grammar

is based on Pegged, btw.
February 27, 2020
On Thursday, 27 February 2020 at 14:06:19 UTC, James Lu wrote:
> I want to implement an ES6 (JavaScript) parser in Dlang so I can implement a transpiler. Because it's a transpiler, I need to be able to visit and rewrite AST nodes, then generate code from the AST. Ideally, the parser generator supports streaming the input into the AST visitor out to the output.
>
> What parser generator library should I use for this purpose?

I would write my own. Maybe with some tooling to take care of the boring stuff.

February 27, 2020
On Thursday, 27 February 2020 at 14:06:19 UTC, James Lu wrote:
> I want to implement an ES6 (JavaScript) parser in Dlang so I can implement a transpiler. Because it's a transpiler, I need to be able to visit and rewrite AST nodes, then generate code from the AST. Ideally, the parser generator supports streaming the input into the AST visitor out to the output.
>
> What parser generator library should I use for this purpose?

I dunno. I wrote the es6-grammar library that uses pegged. Then I decided to hand write mine own.

https://github.com/skoppe/jazr

It is a pretty complete and fast JS minifier. It has lots of passes and minifies code pretty well:

https://github.com/skoppe/jazr/blob/master/source/es6/minifier.d#L286

In general it is about 30 times faster than uglify-js (and uses 3-4 times less memory). It parses JS code at about 60 Mb/s. The minifier was a bit slower at 20 Mb/s if I remember correctly.

I fuzzed the lexer and parser, so there are little to no spurious crashes on weird input.

Use it as you please, or just as an indication of the effort involved.
February 27, 2020
On Thursday, 27 February 2020 at 22:22:59 UTC, Sebastiaan Koppe wrote:
> On Thursday, 27 February 2020 at 14:06:19 UTC, James Lu wrote:
>> [...]
>
> I dunno. I wrote the es6-grammar library that uses pegged. Then I decided to hand write mine own.
>
> https://github.com/skoppe/jazr
>
> It is a pretty complete and fast JS minifier. It has lots of passes and minifies code pretty well:
>
> https://github.com/skoppe/jazr/blob/master/source/es6/minifier.d#L286
>
> In general it is about 30 times faster than uglify-js (and uses 3-4 times less memory). It parses JS code at about 60 Mb/s. The minifier was a bit slower at 20 Mb/s if I remember correctly.
>
> I fuzzed the lexer and parser, so there are little to no spurious crashes on weird input.
>
> Use it as you please, or just as an indication of the effort involved.

Nice!!
February 27, 2020
On 2/27/2020 6:06 AM, James Lu wrote:
> What parser generator library should I use for this purpose?

https://github.com/DigitalMars/DMDScript
« First   ‹ Prev
1 2