diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/files.lua | 2 | ||||
-rw-r--r-- | script/glob/gitignore.lua | 12 | ||||
-rw-r--r-- | script/glob/glob.lua | 7 |
3 files changed, 15 insertions, 6 deletions
diff --git a/script/files.lua b/script/files.lua index db33dab1..71981a83 100644 --- a/script/files.lua +++ b/script/files.lua @@ -367,7 +367,7 @@ end ---@param uri string ---@return boolean function m.isLua(uri) - local ext = uri:match '%.([^%.%/%\\]-)$' + local ext = uri:match '%.([^%.%/%\\]+)$' if not ext then return false end diff --git a/script/glob/gitignore.lua b/script/glob/gitignore.lua index f98a2f31..1368d18f 100644 --- a/script/glob/gitignore.lua +++ b/script/glob/gitignore.lua @@ -19,7 +19,7 @@ end local parser = m.P { 'Main', ['Sp'] = m.S(' \t')^0, - ['Slash'] = m.S('/\\')^1, + ['Slash'] = m.S('/')^1, ['Main'] = m.Ct(m.V'Sp' * m.P'{' * m.V'Pattern' * (',' * expect(m.V'Pattern', 'Miss exp after ","'))^0 * m.P'}') + m.Ct(m.V'Pattern') + m.T'Main Failed' @@ -35,12 +35,15 @@ local parser = m.P { + object('?', m.P'?') + object('[]', m.V'Range') , - ['Char'] = object('char', (1 - m.S',{}[]*?/\\')^1), + ['SimpleChar'] = m.P(1) - m.S',{}[]*?/', + ['EscChar'] = m.P'\\' / '' * m.P(1), + ['Char'] = object('char', m.Cs((m.V'EscChar' + m.V'SimpleChar')^1)), ['FSymbol'] = object('**', m.P'**'), ['Range'] = m.P'[' * m.Ct(m.V'RangeUnit'^0) * m.P']'^-1, ['RangeUnit'] = m.Ct(- m.P']' * m.C(m.P(1)) * (m.P'-' * - m.P']' * m.C(m.P(1)))^-1), } +---@class gitignore local mt = {} mt.__index = mt mt.__name = 'gitignore' @@ -170,7 +173,9 @@ function mt:scan(callback) if type(result) == 'table' then for _, path in ipairs(result) do local filename = path:match '([^/\\]+)[/\\]*$' - if filename then + if filename + and filename ~= '.' + and filename ~= '..' then list[#list+1] = current .. '/' .. filename end end @@ -185,6 +190,7 @@ function mt:__call(path) if self.options.ignoreCase then path = path:lower() end + path = path:gsub('^[/\\]+', '') return self:finishMatch(path) end diff --git a/script/glob/glob.lua b/script/glob/glob.lua index aa8923f3..59fa83a8 100644 --- a/script/glob/glob.lua +++ b/script/glob/glob.lua @@ -19,7 +19,7 @@ end local parser = m.P { 'Main', ['Sp'] = m.S(' \t')^0, - ['Slash'] = m.S('/\\')^1, + ['Slash'] = m.P('/')^1, ['Main'] = m.Ct(m.V'Sp' * m.P'{' * m.V'Pattern' * (',' * expect(m.V'Pattern', 'Miss exp after ","'))^0 * m.P'}') + m.Ct(m.V'Pattern') + m.T'Main Failed' @@ -35,7 +35,9 @@ local parser = m.P { + object('?', m.P'?') + object('[]', m.V'Range') , - ['Char'] = object('char', (1 - m.S',{}[]*?/\\')^1), + ['SimpleChar'] = m.P(1) - m.S',{}[]*?/', + ['EscChar'] = m.P'\\' / '' * m.P(1), + ['Char'] = object('char', m.Cs((m.V'EscChar' + m.V'SimpleChar')^1)), ['FSymbol'] = object('**', m.P'**'), ['RangeWord'] = 1 - m.P']', ['Range'] = m.P'[' * m.Ct(m.V'RangeUnit'^0) * m.P']'^-1, @@ -83,6 +85,7 @@ function mt:__call(path) if self.options.ignoreCase then path = path:lower() end + path = path:gsub('^[/\\]+', '') for _, refused in ipairs(self.refused) do if refused(path) then return false |