2022-12-18 00:25:44 -07:00
|
|
|
import { query as q } from 'good-enough-parser';
|
|
|
|
import { regEx } from '../../../../util/regex';
|
|
|
|
import type { Ctx } from '../types';
|
2023-02-03 11:36:00 -07:00
|
|
|
import { cleanupTempVars, qValueMatcher, storeInTokenMap } from './common';
|
2022-12-18 00:25:44 -07:00
|
|
|
import { handleApplyFrom } from './handlers';
|
|
|
|
|
2023-01-05 06:43:52 -07:00
|
|
|
// apply from: 'foo.gradle'
|
|
|
|
// apply(from = property("foo"))
|
2022-12-18 00:25:44 -07:00
|
|
|
const qApplyFromFile = q
|
|
|
|
.alt(
|
|
|
|
q
|
|
|
|
.alt(
|
|
|
|
q
|
|
|
|
.opt(q.sym<Ctx>(regEx(/^(?:rootProject|project)$/)).op('.'))
|
|
|
|
.sym('file'),
|
2023-11-07 08:50:29 -07:00
|
|
|
q.opt<Ctx>(q.sym('new')).sym('File'),
|
2022-12-18 00:25:44 -07:00
|
|
|
)
|
|
|
|
.tree({
|
|
|
|
maxDepth: 1,
|
|
|
|
startsWith: '(',
|
|
|
|
endsWith: ')',
|
|
|
|
search: q
|
|
|
|
.begin<Ctx>()
|
|
|
|
.opt(
|
2023-01-05 06:43:52 -07:00
|
|
|
q
|
2023-02-03 11:36:00 -07:00
|
|
|
.join(qValueMatcher, q.op(','))
|
2023-11-07 08:50:29 -07:00
|
|
|
.handler((ctx) => storeInTokenMap(ctx, 'parentPath')),
|
2022-12-18 00:25:44 -07:00
|
|
|
)
|
2023-02-03 11:36:00 -07:00
|
|
|
.join(qValueMatcher)
|
2022-12-18 00:25:44 -07:00
|
|
|
.end(),
|
2023-01-05 06:43:52 -07:00
|
|
|
}),
|
2023-11-07 08:50:29 -07:00
|
|
|
qValueMatcher,
|
2022-12-18 00:25:44 -07:00
|
|
|
)
|
|
|
|
.handler((ctx) => storeInTokenMap(ctx, 'scriptFile'));
|
|
|
|
|
|
|
|
export const qApplyFrom = q
|
|
|
|
.sym<Ctx>('apply')
|
|
|
|
.alt(
|
|
|
|
q // apply from: rootProject.file("basedir", "foo/bar.gradle")
|
|
|
|
.sym<Ctx>('from')
|
|
|
|
.op(':')
|
|
|
|
.join(qApplyFromFile),
|
|
|
|
q // apply(from = File(base, "bar.gradle"))
|
|
|
|
.tree({
|
|
|
|
maxDepth: 1,
|
|
|
|
maxMatches: 1,
|
|
|
|
startsWith: '(',
|
|
|
|
endsWith: ')',
|
|
|
|
search: q.begin<Ctx>().sym('from').op('=').join(qApplyFromFile).end(),
|
2023-11-07 08:50:29 -07:00
|
|
|
}),
|
2022-12-18 00:25:44 -07:00
|
|
|
)
|
|
|
|
.handler(handleApplyFrom)
|
|
|
|
.handler(cleanupTempVars);
|