ExtractAnswer(parseTree) { let multiLineAnswer = parseTree.qnaDefinition().qnaAnswerBody().multiLineAnswer().getText().trim(); // trim first and last line let answerRegexp = /^```(markdown)?\r*\n(?<answer>(.|\n|\r\n|\t| )*)\r?\n.*?```$/gim; let answer = answerRegexp.exec(multiLineAnswer); return answer.groups.answer !== undefined ? answer.groups.answer : ''; }
ExtractAssignedId(parseTree) { let idAssignment = parseTree.qnaDefinition().qnaIdMark() if (idAssignment) { let idTextRegExp = /^\<a[ ]*id[ ]*=[ ]*[\"\'](?<idCaptured>.*?)[\"\'][ ]*>[ ]*\<\/a\>$/gmi; let idTextParsed = idTextRegExp.exec(idAssignment.getText().trim()); return idTextParsed.groups.idCaptured || undefined; } return undefined; }
const gitVersion = async () => { const {stdout} = await execa('git', ['version']); const match = /git version (?<version>\d+\.\d+\.\d+).*/.exec(stdout); return match && match.groups.version; }
parsedContent.LUISJsonStructure.settings.find(setting => setting.name == settingsPair.groups.property)
function splitFilename(filename) { const result = leadingUnderscoresRegex.exec(filename) || {groups: {}}; const {leading = '', tailing = filename} = result.groups; const words = []; let lastWord; for (const char of tailing) { const isIgnored = isIgnoredChar(char); if (lastWord && lastWord.ignored === isIgnored) { lastWord.word += char; } else { lastWord = { word: char, ignored: isIgnored }; words.push(lastWord); } } return { leading, words }; }
function parseTodoWithArguments(string, {terms}) { const lowerCaseString = string.toLowerCase(); const lowerCaseTerms = terms.map(term => term.toLowerCase()); const hasTerm = lowerCaseTerms.some(term => lowerCaseString.includes(term)); if (!hasTerm) { return false; } const TODO_ARGUMENT_RE = /\[(?<rawArguments>[^}]+)]/i; const result = TODO_ARGUMENT_RE.exec(string); if (!result) { return false; } const {rawArguments} = result.groups; const parsedArguments = rawArguments .split(',') .map(argument => parseArgument(argument.trim())); return createArgumentGroup(parsedArguments); }
const create = context => ({ Program: node => { for (const comment of node.comments) { const value = comment.value.trim(); const result = disableRegex.exec(value); if ( result && // It's a eslint-disable comment !result.groups.ruleId // But it did not specify any rules ) { context.report({ loc: { start: { ...comment.loc.start, column: -1 }, end: comment.loc.end }, message: 'Specify the rules you want to disable.' }); } } } })
const usageRulesMatch = /## Usage.*?"rules": (?<rules>{.*?})/ms.exec(readme); t.truthy(usageRulesMatch, 'List of rules should be defined in readme.md ## Usage'); usageRules = JSON.parse(usageRulesMatch.groups.rules); } catch {} const {rulesText} = rulesMatch.groups; const re = /- \[(?<id>.*?)]\((?<link>.*?)\) - (?<description>.*)\n/gm; const rules = []; match = re.exec(rulesText); if (match) { const {id, link, description} = match.groups; t.is(link, `docs/rules/${id}.md`, `${id} link to docs should be correct`); t.true(description.trim().length > 0, `${id} should have description in readme.md ## Rules`);
})) promptDefinitions.push(splitLine.groups);
dotAndDigits, scientificNotationSuffix } = match.groups;
throw (new exception(retCode.errorCode.INVALID_INPUT, error.toString(), [error])); let childEntityName = groupsFound.groups.entityName.replace(/^['"]/g, '').replace(/['"]$/g, ''); let childEntityType = groupsFound.groups.instanceOf.trim(); let childFeatures = groupsFound.groups.features ? groupsFound.groups.features.trim().split(/[,;]/g).map(item => item.trim()) : undefined; let tabLevel = Math.ceil(groupsFound.groups.leadingSpaces !== undefined ? groupsFound.groups.leadingSpaces.length / SPACEASTABS : 0) || (groupsFound.groups.leadingTabs !== undefined ? groupsFound.groups.leadingTabs.length : 0); if (defLine === range.Start.Line + 1) { if (groupsFound.groups.instanceOf.toLowerCase().trim() === EntityTypeEnum.SIMPLE) { pushNDepthChild(currentParentEntity.entity, childEntityName, context, childFeatures); } else if (groupsFound.groups.instanceOf.toLowerCase().trim() === EntityTypeEnum.ML) { pushNDepthChild(currentParentEntity.entity, childEntityName, context, childFeatures); let newParent = currentParentEntity.entity.children.find(item => item.name == childEntityName);
const {condition, version} = result.groups;
ExtractSourceInfo(parseTree) { let srcAssignment = parseTree.qnaDefinition().qnaSourceInfo() if (srcAssignment) { let srcRegExp = /^[ ]*\>[ ]*!#[ ]*@qna.pair.source[ ]*=[ ]*(?<sourceInfo>.*?)$/gmi; let srcParsed = srcRegExp.exec(srcAssignment.getText().trim()); return srcParsed.groups.sourceInfo || QNA_GENERIC_SOURCE; } return QNA_GENERIC_SOURCE }
// @flow export default function parseAcceptLanguage(acceptLanguage: ?string) { let [language, territory] = ['en', 'US']; // valid acceptLanguage: en || en_us || en_US || en-US || en-US,en;q=0.9,sl;q=0.8 const localeRegex = /^(?<language>[a-z]{2})(?:[-_](?<territory>[a-z]{2}))?(?:,|;|$)/i; if (acceptLanguage) { const match = localeRegex.exec(acceptLanguage); if (match !== null) { language = match.groups?.language ?? 'en'; territory = match.groups?.territory ?? 'US'; } } return [language, territory.toUpperCase()]; }
/** * Parses the `link` response header to calculate the number of pages * based on a maximum of 100 items per page * * @param {*} options */ const calculate_pages = (options) => { return axios({ method: 'get', url: `${construct_api_url(options)}?per_page=1`, headers: { 'User-Agent': 'Starred-Search Node.js module' }, }) .then((response) => { let pages = {}; // The GitHub API handles pagine in the header item "link". More details // about that here: https://developer.github.com/v3/#pagination pages['total'] = /page=(?<last_page>[0-9]+)>; rel="last"/.exec(response.headers['link']).groups['last_page']; pages['number_of_pages'] = Math.ceil(pages['total']/100); return pages; }); }