Simple DSL editor with code completion using PEG.js

1,682 views
Skip to first unread message

Marcin Stefaniuk

unread,
Oct 12, 2011, 9:39:00 AM10/12/11
to PEG.js: Parser Generator for JavaScript
I would like to present small DSL I've created as proof-of-concept.
Using single PEG grammar I've defined a transforming parser and code
editor with simple content completion. All built with excellent
PEG.js.

The language as its output gives metamodel for Concrete editor (http://
concrete-editor.org/). You can check the demo on
http://mstefaniuk.github.com/Concrete-Freetext/editor/index.html. Base
implementation details are described on
http://eutechne.stefaniuk.info/2011/10/dsl-editor-with-code-completion-in.html.

I have few suggestion that can be taken into account in next versions
of PEG.js.
1. To make grammar more readable maybe implementation can be
optionally separated as in Mouse - Java PEG parser (http://
www.romanredz.se/freesoft.htm). It gives possibility to use single
grammar with pluggable parsing logic.
2. It would be more convenient to receive parser using constructor
than via global variable. Constructor gives possibility to provide
configuration object that can be used internally by parser.
Configuration can be external model, resources or parsing settings.
3. To build a code completion I need to slighty modify generated
parser to provide in error structure also expectations list (https://
gist.github.com/1281239). Is it possible to add it in next version?

Jamon

unread,
Dec 8, 2011, 12:07:30 AM12/8/11
to pe...@googlegroups.com
Great work.  I'm looking to build something similar for an online IDE for Google Closure Templates (an HTML templating library).  Have you given any thought to being able to do syntax highlighting and coloring?  Any ideas on how to accomplish that?

Thanks,
Jamon

Marcin Stefaniuk

unread,
Dec 12, 2011, 4:08:17 AM12/12/11
to PEG.js: Parser Generator for JavaScript
I'm not sure that it is best place to discuss it but I can suggest you
Ace editor. It has simple definitions of syntax coloring based on
regex. Most of these you can get directly from your grammar or even
you can build small highlighting rules extractor using grammar AST
built by PEG.js itself.

Regards
Marcin

Ulric Wilfred

unread,
Feb 1, 2012, 8:15:58 AM2/1/12
to pe...@googlegroups.com
The CodeMirror2 is also great variant to do the highlighting 

David Majda

unread,
Feb 1, 2012, 2:01:53 PM2/1/12
to pe...@googlegroups.com
Hi!

2011/10/12 Marcin Stefaniuk <marcin.s...@gmail.com>:


> I would like to present small DSL I've created as proof-of-concept.
> Using single PEG grammar I've defined a transforming parser and code
> editor with simple content completion. All built with excellent
> PEG.js.
>
> The language as its output gives metamodel for Concrete editor (http://
> concrete-editor.org/). You can check the demo on
> http://mstefaniuk.github.com/Concrete-Freetext/editor/index.html. Base
> implementation details are described on
> http://eutechne.stefaniuk.info/2011/10/dsl-editor-with-code-completion-in.html.

I looked only briefly, but it looks like a very nice project.

> I have few suggestion that can be taken into account in next versions
> of PEG.js.
> 1. To make grammar more readable maybe implementation can be
> optionally separated as in Mouse - Java PEG parser (http://
> www.romanredz.se/freesoft.htm). It gives possibility to use single
> grammar with pluggable parsing logic.

Please file an issue on GitHub. I'd really appreciate more specific
thoughts about how would you like this to work.

> 2. It would be more convenient to receive parser using constructor
> than via global variable. Constructor gives possibility to provide
> configuration object that can be used internally by parser.
> Configuration can be external model, resources or parsing settings.

Why wouldn't a configuration object passed to the "parse" method be sufficient?

> 3. To build a code completion I need to slighty modify generated
> parser to provide in error structure also expectations list (https://
> gist.github.com/1281239). Is it possible to add it in next version?

Sure, I'll reply to the mail with the patch you sent me later.

--
David Majda
Entropy fighter
http://majda.cz/

Marcin Stefaniuk

unread,
Feb 4, 2012, 10:45:16 AM2/4/12
to PEG.js: Parser Generator for JavaScript
On 1 Lut, 20:01, David Majda <da...@majda.cz> wrote:
> > I have few suggestion that can be taken into account in next versions
> > of PEG.js.
> > 1. To make grammar more readable maybe implementation can be
> > optionally separated as in Mouse - Java PEG parser (http://
> >www.romanredz.se/freesoft.htm). It gives possibility to use single
> > grammar with pluggable parsing logic.
>
> Please file an issue on GitHub. I'd really appreciate more specific
> thoughts about how would you like this to work.
I've submitted an issue.

> > 2. It would be more convenient to receive parser using constructor
> > than via global variable. Constructor gives possibility to provide
> > configuration object that can be used internally by parser.
> > Configuration can be external model, resources or parsing settings.
>
> Why wouldn't a configuration object passed to the "parse" method be sufficient?
Sorry for silly question but how could I do it now?

Regards
--
Marcin Stefaniuk
mar...@stefaniuk.info
http://eutechne.stefaniuk.info

David Majda

unread,
May 5, 2012, 10:51:14 AM5/5/12
to pe...@googlegroups.com
2012/2/4 Marcin Stefaniuk <marcin.s...@gmail.com>:
>> > 2. It would be more convenient to receive parser using constructor
>> > than via global variable. Constructor gives possibility to provide
>> > configuration object that can be used internally by parser.
>> > Configuration can be external model, resources or parsing settings.
>>
>> Why wouldn't a configuration object passed to the "parse" method be sufficient?
> Sorry for silly question but how could I do it now?

You can't do that now, but it seems like a simpler solution to me. The
question really should have been something like:

Would the ability to pass a configuration object to the "parse"
method (which would be visible in the parser) be a sufficient solution
for you?

Sorry for being unclear.

Marcin Stefaniuk

unread,
Jul 20, 2012, 2:12:22 PM7/20/12
to pe...@googlegroups.com
W dniu sobota, 5 maja 2012 16:51:14 UTC+2 użytkownik David Majda napisał:
Would the ability to pass a configuration object to the "parse"
method (which would be visible in the parser) be a sufficient solution
for you?
Yes, it would be sufficient and flexible.

Best regards
Marcin Stefaniuk 
Reply all
Reply to author
Forward
0 new messages