mirror of https://github.com/renovatebot/renovate
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { query as q } from 'good-enough-parser';
|
|
import { regEx } from '../../../../util/regex';
|
|
import type { Ctx } from '../context';
|
|
import * as starlark from '../starlark';
|
|
|
|
const booleanValuesRegex = regEx(`^${starlark.booleanStringValues.join('|')}$`);
|
|
const supportedRules = [
|
|
'archive_override',
|
|
'bazel_dep',
|
|
'git_override',
|
|
'local_path_override',
|
|
'single_version_override',
|
|
];
|
|
const supportedRulesRegex = regEx(`^${supportedRules.join('|')}$`);
|
|
|
|
/**
|
|
* Matches key-value pairs:
|
|
* - `name = "foobar"`
|
|
* - `name = True`
|
|
**/
|
|
const kvParams = q
|
|
.sym<Ctx>((ctx, token) => ctx.startAttribute(token.value))
|
|
.op('=')
|
|
.alt(
|
|
q.str((ctx, token) => ctx.addString(token.value)),
|
|
q.sym<Ctx>(booleanValuesRegex, (ctx, token) => ctx.addBoolean(token.value)),
|
|
);
|
|
|
|
export const moduleRules = q
|
|
.sym<Ctx>(supportedRulesRegex, (ctx, token) => ctx.startRule(token.value))
|
|
.join(
|
|
q.tree({
|
|
type: 'wrapped-tree',
|
|
maxDepth: 1,
|
|
search: kvParams,
|
|
postHandler: (ctx) => ctx.endRule(),
|
|
}),
|
|
);
|