tropwer
v0.1.8
Published
## Developed in <img align="center" alt="javascript" height="30" width="30" src="https://raw.githubusercontent.com/devicons/devicon/master/icons/javascript/javascript-plain.svg"> and <img align="center" alt="typescript" height="30" width="30" src="https:/
Downloads
6
Readme
Tropwer
Developed in and
How use?
To start with (Tropwer) we must have 3 files
- index.js or index.ts
- lexer.js or lexer.ts
- grammar.tr
In index.js or (index.ts) we do:
const grammar = require('./grammar')
const { name, type, value, data } = grammar.feed("x=1")
console.log(`==${name}==\n\nVariable name : ${data[0]}\n Variable value : ${data[1]}`)
In lexer.js or (lexer.ts) we do:
const moo = require("moo");
const lexer = moo.compile({
equals: "=",
identifier: /[a-zA-Z]+/,
number: /[0-9]+/
})
module.exports = lexer;
In grammar.tr we do:
# Declare a token with (name: variable, type: variable)
variable -> %identifier %equals %number
Now we just have to compile the grammar.tr to a javascript or a typescript
npx tropwer grammar.tr --o=grammar.js --lexer=lexer.js
and finally run
node index.js
Why Tropwer was created?
Because I had a lot of problems with nearley and that's why I created my own parser (Tropwer) with the purpose of simplicity and ease
Why name (tropwer):
Yes this name came from the head I don't even know where I was thinking when I put this name