Code Monkey home page Code Monkey logo

peggy-tag's Issues

Any interest in pegjs-template features?

I just discovered peggyjs. Really nice work!

This peggy-tag library plays a similar role to my pegjs-template library for PEG.js. I'd love to contribute the features from that library to this one. In particular, I'd be interested in contributing:

  1. The ability to interpolate in functions and use them as semantic actions. This allows you to get syntax highlighting and type checking for semantic actions, to use TypeScript in them, to capture JavaScript variables, etc etc. This isn't just interpolating the functions' source as a string; that would prevent things like capturing variables. Instead, under the hood, the functions are passed in to the parser via the grammar context.
  2. The ability to define "partial" grammars that you can interpolate into other grammars, allowing you to share common definitions across multiple grammars. I find this pretty useful for lexical stuff in particular. Again, this isn't just interpolating the shared definitions as a string, because we want to take functions along for the ride.

I've found these features quite useful in my own work. What do you think; do these feel like a good fit for peggy-tag?

Better estimation of first-line column numbers

With the PR about to drop, line numbers will be correct from this code:

import peggy from "peggy-tag";

const parse123 = peggy`foo = $("f" "o"+)`;
console.log(parse123("foooo")); // "foooo"

but column numbers for errors thrown from the last line will be off by three. Find a way to determine where "foooo" actually starts.

Code review

@sanket143 can you take a look at this please, to see if it's more-or-less what you wanted, and to see if there's anything that can be improved?

Grammar-source offsets

It would be nice if peggy.GrammarError.format supported line and column offsets so that errors could be formatted with the CallSite of the place where the template originated. This will work in node, and possibly in v8-based browsers with the trick from stack-trace.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.