Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'parsimmon' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
const simplePseudoOp: Parser = (function() {
// FIXME: No expressions allowed in DB statements, to make it fast to parse.
const dbConst: Parser = alt(
numberLiteral.map(n => [n]), // 8BIT but no exprs pls
stringLiteral.map(s => s.split('').map(c => c.charCodeAt(0)))
);
const db = symbol('DB').skip(optSpace)
.then(sepBy(dbConst, string(',').then(optSpace)))
// Support both DB as nullary var declaration and DB as data constants.
.map(data => data.length > 0 ? [].concat.apply([], data) : [0]);
const dw = symbol('DW').skip(optSpace)
.then(sepBy(const_16bit, string(',').then(optSpace)))
.map(data => [].concat.apply([], data));
return alt(
db,
dw,
binaryOp('SECTION', stringLiteral, seq(sectionType, indirect(numberLiteral)))
.map(([name, [sectionType, address]]) => [{
kind: 'section',
name,
sectionType,
address
seq(string(';'), takeWhile(c => c !== '\n'), string('\n')),
string('\n')
)
);
type Macro = { kind: 'macro', name: string; body: string; };
const equ: Parser = seqMap(
optLineSpace.then(token).skip(lineSpace), string('EQU').skip(lineSpace),
takeWhile(c => c !== ';' && c !== '\n'), eol,
(name, _, body, _2) => ({ kind: 'macro', name, body } as Macro)
);
const equs: Parser = seqMap(
optLineSpace.then(token).skip(lineSpace), string('EQUS').skip(lineSpace),
string('"').then(takeWhile(c => c !== '"')).skip(string('"')), eol,
(name, _, body, _2) => ({ kind: 'macro', name, body } as Macro)
);
// This parser needs to be information-preserving.
type Statement = { kind: 'statement', tokens: string[] };
const statement: Parser =
optLineSpace.then(
alt(token, lineSpace)
.many()
.map((tokens) => ({ kind: 'statement', tokens } as Statement))
).skip(eol);
const file: Parser<(Macro|Statement)[]> = alt(
equs,
equ,
// @flow
import P from 'parsimmon'
import crap from './crap'
import TupleParser from './collections/tuple'
import IdentifierParser from './identifier'
import type { LambdaNodeValueType, NodeType, VariableNodeType } from '../types'
export default P.alt(
P.seq(
P.string('$')
.then(IdentifierParser.atMost(1))
.skip(crap)
.skip(P.string('=>')),
crap.then(TupleParser)
).map(
([variable, definition]: [
Array,
NodeType
]): LambdaNodeValueType => ({
variable: variable.length ? variable[0].value : 'input',
definition
})
),
P.string('\\')
// @flow
import P from 'parsimmon'
import type { NodeType } from '../../types'
export default P.regexp(
/(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/
).map((value: string): NodeType => ({
name: 'primitive',
value
}))
function contributorsParser(strict) {
// Need to remove '^' and '$' from the regex, parsimmon does not expect those.
const contributor = strict
? pm.seqMap(pm.regexp(/([^<]+) /, 1), pm.regexp(/\/, 1), (name, username) => ({ name, url: "https://github.com/" + username }))
: pm.seqMap(pm.regexp(/([^<]+) /, 1), pm.regexp(/<([^>]+)>/, 1), (name, url) => ({ name, url }));
const contributors = pm.sepBy1(contributor, separator);
if (!strict) {
// Allow trailing whitespace.
return pm.seqMap(contributors, pm.regexp(/ */), a => a);
}
return contributors;
}
// TODO: Should we do something with the URL?
// @flow
import P from 'parsimmon'
import type { InputPropNodeType } from '../types'
export default P.regexp(/\.[$A-Z_][0-9A-Z_$]*/i)
.map((value: string): InputPropNodeType => ({
name: 'inputProp',
value
}))
.desc('inputProp')
function contributorsParser(strict) {
// Need to remove '^' and '$' from the regex, parsimmon does not expect those.
const contributor = strict
? pm.seqMap(pm.regexp(/([^<]+) /, 1), pm.regexp(/\/, 1), (name, username) => ({ name, url: "https://github.com/" + username }))
: pm.seqMap(pm.regexp(/([^<]+) /, 1), pm.regexp(/<([^>]+)>/, 1), (name, url) => ({ name, url }));
const contributors = pm.sepBy1(contributor, separator);
if (!strict) {
// Allow trailing whitespace.
return pm.seqMap(contributors, pm.regexp(/ */), a => a);
}
return contributors;
}
// TODO: Should we do something with the URL?
/* eslint-disable */
const fs = require('fs');
const P = require('parsimmon');
const config = require('../config');
const lTagArrow = P.string('<');
const rTagArrow = P.string('>');
const endLine = P.string('/');
const doubleQuote = P.string('"');
const singleQuote = P.string("'");
const whitespaces = P.regex(/\s*/).desc('whitespaces');
const Wxml = P.createLanguage({
Symbol: function () {
return P.regexp(/[a-zA-Z_-][a-zA-Z0-9_-]*/).desc("symbol");
},
StringExpression: function () {
// return P.regexp(/[^<]+/);
return P.regex(/((?!<\/).)+/);
},
singleQuoteString: function () {
return P.seqMap(
singleQuote,
P.regexp(/[^']*/),
singleQuote,
function (r1, r2, r3) {
return {
type: 'single',
)
),
Parsimmon.string('\udb40\udc7f') // cancel tag
);
var ZeroWidthJoiner = Parsimmon.string('\u200d')
.desc('zero-width joiner (\\u200d)');
var OptionalFitzpatrickModifier =
Parsimmon.regex(/(\ud83c[\udffb-\udfff]){0,1}/)
.desc('an optional Fitzpatrick modifier');
var SimpleEmoji = Parsimmon.alt(
// Simple Unicode emoji
Parsimmon.regex(/[\u203c-\u2bff]/),
Parsimmon.regex(/[\u2702-\u27b0]/),
// Enclosed CJK Letters and Months
Parsimmon.regex(/[\u3200-\u32ff]/),
// Emoji flags
FlagEmoji,
GreatBritainEmoji,
// Surrogate pairs
Parsimmon.regex(/\ud83c[\udc04-\udfff]/),
Parsimmon.regex(/\ud83d[\udc00-\udfff]/),
Parsimmon.regex(/\ud83e[\udc00-\udfff]/)
);
var VariationSelectorEmoji = Parsimmon.seq(
// Single characters that become emoji only with a variation selector
Parsimmon.alt(
Parsimmon.string('\u00a9'), // trademark
Parsimmon.string('\u00ae'), // copyright
"use strict";
/* Parser combinator based parser for the
* protobuf text format.
*/
var Parsimmon = require('parsimmon');
var regex = Parsimmon.regex
, string = Parsimmon.string
, optWhitespace = Parsimmon.optWhitespace
, lazy = Parsimmon.lazy
, alt = Parsimmon.alt
, seq = Parsimmon.seq;
var comment = regex(/#.+/).then(optWhitespace.atMost(1));
var whitespace = optWhitespace.then(comment.atMost(1));
var lexeme = function(p){ return p.skip(whitespace); }
var colon = lexeme(string(':'));
var lbrace = lexeme(string('{'))
, rbrace = lexeme(string('}'));
var stripFirstLast = function(x) {
return x.substr(1, x.length-2);