Improved git pathing
This commit is contained in:
184
build_file.cpp
184
build_file.cpp
@@ -225,68 +225,54 @@ function SkipLineAndColumn(s)
|
||||
return line, col, s
|
||||
end
|
||||
|
||||
function ChopLineAndColumn(s)
|
||||
local line = 1
|
||||
local col = 1
|
||||
local function SkipSlashes(s)
|
||||
found_slash = false
|
||||
while s:sub(1,1) == '/' or s:sub(1,1) == '\\' do
|
||||
s = s:sub(2)
|
||||
found_slash = true
|
||||
end
|
||||
return s, found_slash
|
||||
end
|
||||
|
||||
-- filename:line:column
|
||||
local lci, lcj = s:find(":%d+:%d+$")
|
||||
if lci then
|
||||
local line_and_col = s:sub(lci, lcj)
|
||||
local i, j = line_and_col:find("%d+")
|
||||
line = line_and_col:sub(i, j)
|
||||
col = line_and_col:sub(j + 2, -1)
|
||||
s = s:sub(1, lci - 1)
|
||||
return line, col, s
|
||||
else
|
||||
local li, lj = s:find(":%d+$")
|
||||
if li then
|
||||
local line_string = s:sub(li, lj)
|
||||
line = line_string:sub(2, -1)
|
||||
s = s:sub(1, li - 1)
|
||||
return line, col, s
|
||||
end
|
||||
local function SkipDrive(s)
|
||||
local i, j = s:find("^%a:")
|
||||
if not i then return s, nil, true end
|
||||
|
||||
local drive = s:sub(i, j)
|
||||
local new_s = s:sub(j + 1)
|
||||
|
||||
new_s, found_slash = SkipSlashes(new_s)
|
||||
if not found_slash then return s, drive, false end
|
||||
|
||||
return new_s, drive, true
|
||||
end
|
||||
|
||||
local function SkipPathCell(s)
|
||||
local i, j = s:find("^[%w_%.-% +]+")
|
||||
if not i then return s, nil, false end
|
||||
|
||||
local word = s:sub(i, j)
|
||||
local new_s = s:sub(j + 1)
|
||||
local new_s, found_slash = SkipSlashes(new_s)
|
||||
|
||||
return new_s, word, found_slash
|
||||
end
|
||||
|
||||
local function SkipPath(s)
|
||||
local input_s = s
|
||||
local s, drive, ok = SkipDrive(s)
|
||||
if not ok then return s end
|
||||
|
||||
local cells = {}
|
||||
while true do
|
||||
s, word, slash_eaten = SkipPathCell(s)
|
||||
if word then cells[#cells + 1] = word end
|
||||
if not slash_eaten then break end
|
||||
end
|
||||
|
||||
-- filename(line,col):
|
||||
local lci, lcj = s:find("%(%d+,%d+%):$")
|
||||
if lci then
|
||||
local line_and_col = s:sub(lci, lcj)
|
||||
local i, j = line_and_col:find("%d+")
|
||||
line = line_and_col:sub(i, j)
|
||||
col = line_and_col:sub(j + 2, -3)
|
||||
s = s:sub(1, lci - 1)
|
||||
return line, col, s
|
||||
else
|
||||
local li, lj = s:find("%(%d+%):$")
|
||||
if li then
|
||||
local line_string = s:sub(li, lj)
|
||||
line = line_string:sub(2, -3)
|
||||
s = s:sub(1, li - 1)
|
||||
return line, col, s
|
||||
end
|
||||
end
|
||||
|
||||
-- filename(line,col)
|
||||
local lci, lcj = s:find("%(%d+,%d+%)$")
|
||||
if lci then
|
||||
local line_and_col = s:sub(lci, lcj)
|
||||
local i, j = line_and_col:find("%d+")
|
||||
line = line_and_col:sub(i, j)
|
||||
col = line_and_col:sub(j + 2, -2)
|
||||
s = s:sub(1, lci - 1)
|
||||
return line, col, s
|
||||
else
|
||||
local li, lj = s:find("%(%d+%)$")
|
||||
if li then
|
||||
local line_string = s:sub(li, lj)
|
||||
line = line_string:sub(2, -2)
|
||||
s = s:sub(1, li - 1)
|
||||
return line, col, s
|
||||
end
|
||||
end
|
||||
|
||||
return 1, 1, s
|
||||
local skip_size = input_s:len() - s:len()
|
||||
local path = input_s:sub(1, skip_size)
|
||||
return s, path, drive, cells
|
||||
end
|
||||
|
||||
function BufferNameExists(name)
|
||||
@@ -300,76 +286,16 @@ function BufferNameExists(name)
|
||||
return false
|
||||
end
|
||||
|
||||
function ChopColon(s)
|
||||
if s:sub(-1) == ':' then
|
||||
s = s:sub(1, -2)
|
||||
function MatchWindowsPath(_s)
|
||||
local s, file_path, drive = SkipPath(_s)
|
||||
if not drive then
|
||||
local d = GetCurrentBufferDir()
|
||||
file_path = d..'/'..file_path
|
||||
end
|
||||
return s
|
||||
end
|
||||
local line, col, s = SkipLineAndColumn(s)
|
||||
|
||||
function GenericTextFileRule(_s)
|
||||
function match_path(s)
|
||||
-- ./something
|
||||
-- add working directory
|
||||
local working_dir_i, working_dir_j = string.find(s, "^%./.+")
|
||||
if working_dir_j then
|
||||
result = s:sub(3)
|
||||
result = GetCurrentBufferDir().."/"..result
|
||||
return result
|
||||
end
|
||||
|
||||
-- C:/something
|
||||
local abs_i, abs_j = string.find(s, "^%a:/.+")
|
||||
if abs_i then
|
||||
return s
|
||||
end
|
||||
|
||||
-- C:\something
|
||||
local abs_i, abs_j = s:find("^%a:\\.+")
|
||||
if abs_i then
|
||||
s = s:gsub("\\", "/")
|
||||
return s
|
||||
end
|
||||
|
||||
-- /mnt/something
|
||||
local abs_i, abs_j = s:find("^/.*")
|
||||
if abs_i then
|
||||
return s
|
||||
end
|
||||
|
||||
if BufferNameExists(s) then
|
||||
return s
|
||||
end
|
||||
|
||||
-- other_random_filename
|
||||
buffer_dir = GetCurrentBufferDir()
|
||||
if buffer_dir:len() == 0 then
|
||||
return s
|
||||
else
|
||||
return buffer_dir..'/'..s
|
||||
end
|
||||
end
|
||||
|
||||
_s = ChopColon(_s)
|
||||
line, col, _s = ChopLineAndColumn(_s)
|
||||
file_path = match_path(_s)
|
||||
return {kind = "text", file_path = file_path, line = line, col = col}
|
||||
end
|
||||
|
||||
function MatchAgainstIncludes(s)
|
||||
line, col, s = ChopLineAndColumn(s)
|
||||
include_paths = {
|
||||
"C:/Work/text_editor/src",
|
||||
"C:/Work/text_editor/src/text_editor",
|
||||
}
|
||||
for i = 1,#include_paths do
|
||||
file_path = include_paths[i] .. '/' .. s
|
||||
if FileExists(file_path) then
|
||||
return {kind = "text", file_path = file_path, line = line, col = col}
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
print("OPEN :: INPUT = ".._s.." KIND = ".."text".." ".."FILE_PATH = "..file_path.."["..line..","..col.."]")
|
||||
return {kind = "text", file_path = file_path, line = line, col = col}
|
||||
end
|
||||
|
||||
function MatchGitCommit(s)
|
||||
@@ -383,8 +309,7 @@ function MatchGitCommit(s)
|
||||
end
|
||||
|
||||
Rules = {
|
||||
GenericTextFileRule,
|
||||
MatchAgainstIncludes,
|
||||
MatchWindowsPath,
|
||||
MatchGitCommit,
|
||||
}
|
||||
|
||||
@@ -399,6 +324,7 @@ function ApplyRules(s)
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
)==";
|
||||
|
||||
void GenerateConfig() {
|
||||
|
||||
Reference in New Issue
Block a user