1computer1 / lexure Goto Github PK
View Code? Open in Web Editor NEWParser and utilities for non-technical user input
License: MIT License
Parser and utilities for non-technical user input
License: MIT License
Allow multiple values in an option, e.g. --foo 1 --foo 2 --foo 3
would give 'foo' => ['1', '2', '3']
in the result,
Basically, an Args#singleFromEnd
that would retrieve from the end.
This way, users can express "last n arguments" or similar.
Many parsing methods return null
rather than throwing. I think throwing an error is nicer to write code for as a user and is closer to what Node.js does (ex. new URL('invalid')
throws). Here I've rewritten the basic example from the readme the way it would be if it no longer returned null
:
const input = '!hello world "cool stuff" --foo --bar=baz a b c';
const lexer = new lexure.Lexer(input)
.setQuotes([
['"', '"'],
['“', '”']
]);
try {
const res = lexer.lexCommand(s => s.startsWith('!') ? 1 : null);
console.log(res);
} catch (error) {
console.error('Bad input:', error);
}
If Lexure is having an error parsing that should be reflected in the code. This also has the added benefit of making return types cleaner since there's no more Whatever | null
.
Interesting in hearing your thoughts on this.
Right now, longStrategy
and longShortStrategy
are hardcoded to use the usual --
and =
syntax.
It would be nice to support more styles, such as --flag:
or \flag
by allowing users to pass in their own prefix and separator.
Current way to do this is to simply copy paste those strategies and modify the regex.
The following error pops up when trying to use the module:
Error: File 'node_modules/lexure/dist/types/index.d.ts' is not a module.
Install lexure (I used yarn add lexure
, which installed [email protected]
).
import { Lexer, Parser, Tokens, Unordered } from 'lexure';
Results in the error shown above.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.