
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
fruitsconfits
Advanced tools
FruitsConfits - A well typed and sugared parser combinator framework for TypeScript/JavaScript.
npm install fruitsconfits
NOTICE:
Use withwebpack >= 5
If you get the error:
Module not found: Error: Can't resolve '(importing/path/to/filename)' in '(path/to/node_modules/path/to/dirname)' Did you mean '(filename).js'?`
Add following setting to your
webpack.config.js
.
{ test: /\.m?js/, resolve: { fullySpecified: false, }, },
On
webpack >= 5
, the extension in the request is mandatory for it to be fully specified if the origin is a '.mjs' file or a '.js' file where the package.json contains '"type": "module"'.
See CHANGELOG.md.
Get the string parser generators.
export function getStringParsers<C, R>(
params: {
rawToToken: (rawToken: string) => R,
concatTokens: (tokens: R[]) => R[],
});
rawToToken
: function to convert string token to AST element.concatTokens
: function to merge two AST elements into one AST element.returns an object that containing the parsers.
seq(needle: string)
needle
cls(...needles: string[])
needles
notCls(...needles: string[])
needles
clsFn(needle: (src: string) => number)
needle
alpha
upper
lower
num
nonzero
0
bin
oct
hex
alnum
space
spaceWithinSingleLine
ctrl
newline
word
any
bin(...prefixes: StringParserFnWithCtx<C, R>[])
oct(...prefixes: StringParserFnWithCtx<C, R>[])
hex(...prefixes: StringParserFnWithCtx<C, R>[])
int
bigint
float
isParam(criteria: (o: any) => boolean, conv?: (o: any) => any)
cat(...parsers: StringParserFnWithCtx<C, R>[])
parsers
once(parser: StringParserFnWithCtx<C, R>)
parser
repeat(parser: StringParserFnWithCtx<C, R>)
parser
qty(min?: number, max?: number) => (parser: StringParserFnWithCtx<C, R>)
parser
repeat
parserzeroWidth(helper?: () => R)
helper
err(message: string)
message
beginning(helper?: () => R)
helper
end(helper?: () => R)
helper
first(...parsers: StringParserFnWithCtx<C, R>[])
parsers
or(...parsers: StringParserFnWithCtx<C, R>[])
parsers
combine(...parsers: StringParserFnWithCtx<C, R>[])
parsers
erase(...parsers: StringParserFnWithCtx<C, R>[])
parsers
and return empty result []
trans(fn: (tokens: R[]) => R[]) => (...parsers: StringParserFnWithCtx<C, R>[])
parsers
and transform the result by fn
ahead(...parsers: StringParserFnWithCtx<C, R>[])
parsers
behind(n: number, helper?: () => R)(...parsers: StringParserFnWithCtx<C, R>[])
parsers
and return result that is provided by helper
rules(args: ApplyProductionRulesArg<string, C, R>) => (lexer: StringParserFnWithCtx<C, R>)
args
makeProgram
ParseError
thrown to a return valueGet the object list parser generators.
export function getObjectParsers<T extends ArrayLike<T[number]>, C, R>(
params: {
rawToToken: (rawToken: T[number]) => R,
concatTokens: (tokens: R[]) => R[],
comparator: (a: T[number], b: T[number]) => boolean,
});
rawToToken
: function to convert the input object list item to AST element.concatTokens
: function to merge two AST elements into one AST element.comparator
: function to compare two input object list items.returns an object that containing the parsers.
seq(needle: T)
needle
cls(...needles: T[number][])
needles
notCls(...needles: T[number][])
needles
clsFn(needle: (src: T[number]) => boolean)
needle
any
cat(...parsers: ParserFnWithCtx<T, C, R>[])
parsers
once(parser: ParserFnWithCtx<T, C, R>)
parser
repeat(parser: ParserFnWithCtx<T, C, R>)
parser
qty(min?: number, max?: number) => (parser: ParserFnWithCtx<T, C, R>)
parser
repeat
parserzeroWidth(helper?: () => R)
helper
err(message: string)
message
beginning(helper?: () => R)
helper
end(helper?: () => R)
helper
first(...parsers: ParserFnWithCtx<T, C, R>[])
parsers
or(...parsers: ParserFnWithCtx<T, C, R>[])
parsers
combine(...parsers: ParserFnWithCtx<T, C, R>[])
parsers
erase(...parsers: ParserFnWithCtx<T, C, R>[])
parsers
and return empty result []
trans(fn: (tokens: R[]) => R[]) => (...parsers: ParserFnWithCtx<T, C, R>[])
parsers
and transform the result by fn
ahead(...parsers: ParserFnWithCtx<T, C, R>[])
parsers
behind(n: number, helper?: () => R)(...parsers: ParserFnWithCtx<T, C, R>[])
parsers
and return result that is provided by helper
rules(args: ApplyProductionRulesArg<T, C, R>) => (lexer: ParserFnWithCtx<T, C, R>)
args
makeProgram
ParseError
thrown to a return valueBuild a parser input.
Example:
...
const program = makeProgram(trans(tokens => tokens)(
erase(repeat(commentOrSpace)),
first(listValue, objectValue, constExpr(end())),
erase(repeat(commentOrSpace)),
end(), ));
export function parse(s: string) {
const z = program(parserInput(s));
if (! z.succeeded) {
throw new Error(formatErrorMessage(z));
}
return z.tokens[0].value;
}
Build a parser input from ES6 template strings.
Example:
const program = makeProgram(combine(
seq('Hello,'),
isParam(o => String(o) === 'world'),
seq('!'),
end(), ));
export function parse(strings: TemplateStringsArray, ...values: any[]) {
const z = program(templateStringsParserInput(strings, values));
if (! z.succeeded) {
throw new Error(formatErrorMessage(z));
}
return z.tokens;
}
ISC
Copyright (c) 2019 Shellyl_N and Authors.
FAQs
FruitsConfits - A well typed and sugared parser combinator framework for TypeScript/JavaScript.
The npm package fruitsconfits receives a total of 4 weekly downloads. As such, fruitsconfits popularity was classified as not popular.
We found that fruitsconfits demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.