Skip to content

Commit d3cda27

Browse files
committed
config: parse include and exclude as lexical_path.Patterns
... and accept `lexical_path.Pattern`s in more places
1 parent ce95f9d commit d3cda27

File tree

8 files changed

+80
-20
lines changed

8 files changed

+80
-20
lines changed

build/cyan/commands/build.lua

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/cyan/config.lua

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/cyan/fs.lua

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cyan/commands/build.tl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ local function build(args: command.Args, loaded_config: config.Config, starting_
9393
local include <const> = loaded_config.include or {}
9494
local exclude <const> = loaded_config.exclude and { table.unpack(loaded_config.exclude) } or {}
9595
if abs_source_dir == starting_dir then
96-
table.insert(exclude, "tlconfig.lua")
96+
table.insert(exclude, lexical_path.parse_pattern "tlconfig.lua")
9797
end
9898
local dont_write_lua_files <const> = source_dir == build_dir
9999

src/cyan/config.tl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ local record Config
1919

2020
build_dir: lexical_path.Path
2121
source_dir: lexical_path.Path
22-
include: {string}
23-
exclude: {string}
22+
include: {lexical_path.Pattern}
23+
exclude: {lexical_path.Pattern}
2424
global_env_def: string
2525
include_dir: {lexical_path.Path}
2626

@@ -292,6 +292,25 @@ function config.is_config(c_in: any): Config, {string}, {string}
292292
end
293293

294294
result.externals = c.externals as {string:any}
295+
296+
if type(c.include) == "table" then
297+
result.include = {}
298+
for i, patt in ipairs(c.include as {any}) do
299+
if patt is string then
300+
result.include[i] = lexical_path.parse_pattern(patt)
301+
end
302+
end
303+
end
304+
305+
if type(c.exclude) == "table" then
306+
result.exclude = {}
307+
for i, patt in ipairs(c.exclude as {any}) do
308+
if patt is string then
309+
result.exclude[i] = lexical_path.parse_pattern(patt)
310+
end
311+
end
312+
end
313+
295314
for k in pairs(valid_keys) do
296315
if (result as {string:any})[k] == nil then
297316
(result as {string:any})[k] = copy(c[k])

src/cyan/fs.tl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ end
130130
---@desc
131131
--- If the given path matches any of the patterns in `patterns`, returns the index of the matched pattern
132132
--- otherwise returns `nil`
133-
function fs.match_any(path: lexical_path.Path, patterns: {lexical_path.Pattern}): integer
133+
function fs.match_any(path: lexical_path.Path, patterns: {string | lexical_path.Pattern}): integer
134134
for i, pattern in ipairs(patterns) do
135135
if path:match(pattern) then
136136
return i
@@ -143,9 +143,20 @@ end
143143
--- Recursively iterate over the files in a directory, following the provided `include` and `exclude` patterns
144144
---
145145
--- For information on path patterns, see the `Path:match()` method
146-
function fs.scan_directory(dir: lexical_path.Path, include?: {string}, exclude?: {string}, include_directories?: boolean): function(): lexical_path.Path
147-
local include_patterns <const>: {lexical_path.Pattern} = util.tab.map(include or {}, lexical_path.parse_pattern)
148-
local exclude_patterns <const>: {lexical_path.Pattern} = util.tab.map(exclude or {}, lexical_path.parse_pattern)
146+
function fs.scan_directory(
147+
dir: lexical_path.Path,
148+
include?: {string | lexical_path.Pattern},
149+
exclude?: {string | lexical_path.Pattern},
150+
include_directories?: boolean
151+
): function(): lexical_path.Path
152+
local function ensure_pattern(x: string | lexical_path.Pattern): lexical_path.Pattern
153+
if x is string then
154+
return lexical_path.parse_pattern(x)
155+
end
156+
return x
157+
end
158+
local include_patterns <const>: {lexical_path.Pattern} = util.tab.map(include or {}, ensure_pattern)
159+
local exclude_patterns <const>: {lexical_path.Pattern} = util.tab.map(exclude or {}, ensure_pattern)
149160

150161
local function matches(to_match: lexical_path.Path): boolean
151162
local inc: integer = nil

src/cyan/graph.tl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ end
260260
---
261261
--- Returns `nil` if a circular dependency was found, along
262262
--- with a list of the filenames in the cycle
263-
function graph.scan_directory(dir: lexical_path.Path, include?: {string}, exclude?: {string}): Dag, {string}
263+
function graph.scan_directory(dir: lexical_path.Path, include?: {string | lexical_path.Pattern}, exclude?: {string | lexical_path.Pattern}): Dag, {string}
264264
local d <const> = graph.empty()
265265

266266
for p in fs.scan_directory(dir, include, exclude) do

0 commit comments

Comments
 (0)