Skip to content
[WIP] ⚙️ JavaScript parser for Twig files, based on Twing.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test/unit
.appveyor.yml
.gitignore
.travis.yml
LICENSE
README.md
jest.config.js
package.json
rollup.browser.config.js
rollup.config.js
tsconfig.json
yarn.lock

README.md

Twig Parser

npm (scoped) Build Status Build status

JavaScript parser for Twig files, based on Twing.

WORK IN PROGRESS

This project is still in early development.

Installation and usage steps may not work for the moment.

Be patient or contribute! :)

Goals

This package was initially created to be used by the Prettier plugin for Twig files. The plugin used the Twing engine at early state, but it quickly showed some issues with the final AST (see this and this).

This parser will:

  • Simple parse your code into tokens and an AST
  • Keep traces of whitespace control modifier

This parser will not:

  • Alter text nodes values (ref)
  • Render something, it's not an engine. If you need to render Twig files, use Twing instead

Installation

With yarn:

$ yarn add -D @kocal/twig-parser

With npm:

$ npm install --save-dev @kocal/twig-parser

Usage

With Node.js

const { tokenize, parse } = require('@kocal/twig-parser');

const code = '{{ "Put your Twig code here "}}';
const tokens = tokenize(code);
const ast = parse(tokens);

console.log(ast);

In the Browser

<script src="https://unpkg.com/@kocal/twig-parser/dist/browser.min.js"></script>
<script>
const code = '{{ "Put your Twig code here "}}';
const tokens = TwigParser.tokenize(code);
const ast = TwigParser.parse(tokens);
  
console.log(ast);
</script>

Contribution

  • Fork the project
  • Create a new branch
  • Try to write tests before adding a feature or fixing a bug
  • Open a pull request 🎉

License

MIT.

You can’t perform that action at this time.