GithubHelp home page GithubHelp logo

lguzzon-scratchbook / pegjs-strip Goto Github PK

View Code? Open in Web Editor NEW

This project forked from okaxaki/pegjs-strip

0.0 1.0 0.0 54 KB

Remove Javascript code from a PEG.js grammer file.

License: ISC License

JavaScript 100.00%

pegjs-strip's Introduction

pegjs-strip npm version

pegjs-strip is a utility for removing Javascript code fragments from the specified PEG.js grammer file.

The utility removes all code-related statements such as the initializer block, actions and labels. The semantic predicate &{<code>} and !{<code>} are replaced with &{return true;} or !{return false;} respectively.

By default, the utility does not strip comment blocks. To remove comments, --strip-comment option can be used.

Usage

Usage: pegjs-strip [options] file


Options:
 -h, --help                     show this help.
     --strip-comment            Strip comments.
     --keep-initializer         Keep the initializer block.
     --keep-action              Keep actions.
     --keep-label               Keep labels.
     --keep-semantic-predicate  Keep semantic predicates.

Example

The following grammer is from the PEG.js documentation.

start
  = additive

additive
  = left:multiplicative "+" right:additive { return left + right; }
  / multiplicative

multiplicative
  = left:primary "*" right:multiplicative { return left * right; }
  / primary

primary
  = integer
  / "(" additive:additive ")" { return additive; }

integer "integer"
  = digits:[0-9]+ { return parseInt(digits.join(""), 10); }

To remove all the code in the grammer, just run the utility with the grammer file as the first argument. The result is then written to the standard output as follows.

$ pegjs-strip example.pegjs

start
  = additive

additive
  = multiplicative "+" additive
  / multiplicative

multiplicative
  = primary "*" multiplicative
  / primary

primary
  = integer
  / "(" additive ")"

integer "integer"
  = [0-9]+

--keep-label option is available to leave all labels in the resulting output.

$ pegjs-strip --keep-label example.pegjs 

start
  = additive

additive
  = left:multiplicative "+" right:additive
  / multiplicative

multiplicative
  = left:primary "*" right:multiplicative
  / primary

primary
  = integer
  / "(" additive:additive ")"

integer "integer"
  = digits:[0-9]+

pegjs-strip's People

Contributors

okaxaki avatar

Watchers

 avatar

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.