Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
saecki committed Jul 1, 2023
1 parent 2589619 commit f5da000
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
4 changes: 3 additions & 1 deletion teal/crates/diagnostic.tl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ function M.process_api_crate(crate: toml.Crate, api_crate: Crate): CrateInfo, {D
}
local diagnostics = {}

if crate.path then
if crate.workspace then
info.dep_kind = "workspace"
elseif crate.path then
info.dep_kind = "path"
elseif crate.git then
info.dep_kind = "git"
Expand Down
47 changes: 45 additions & 2 deletions teal/crates/toml.tl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ local record M
path: Path
git: Git
pkg: Pkg
workspace: Workspace
def: Def
feat: Feat
section: Section
Expand Down Expand Up @@ -72,6 +73,14 @@ local record M
quote: Quotes
end

record Workspace
enabled: boolean
text: string
line: integer -- 0-indexed
col: Range
decl_col: Range
end

record Def
enabled: boolean
text: string
Expand Down Expand Up @@ -129,6 +138,7 @@ local INLINE_TABLE_GIT_PATTERN = inline_table_str_pattern("git")
local INLINE_TABLE_PKG_PATTERN = inline_table_str_pattern("package")
local INLINE_TABLE_FEAT_PATTERN = inline_table_str_array_pattern("features")
local INLINE_TABLE_DEF_PATTERN = inline_table_bool_pattern("default[_-]features")
local INLINE_TABLE_WORKSPACE_PATTERN = inline_table_bool_pattern("workspace")

function M.parse_crate_features(text: string): {Feature}
local feats: {Feature} = {}
Expand Down Expand Up @@ -163,6 +173,9 @@ function Crate.new(obj: Crate): Crate
if obj.def then
obj.def.enabled = obj.def.text ~= "false"
end
if obj.workspace then
obj.workspace.enabled = obj.workspace.text ~= "false"
end

return setmetatable(obj, { __index = Crate })
end
Expand Down Expand Up @@ -197,6 +210,10 @@ function Crate:is_def_enabled(): boolean
return not self.def or self.def.enabled
end

function Crate:is_workspace(): boolean
return not self.workspace or self.workspace.enabled
end

function Crate:package(): string
return self.pkg and self.pkg.text or self.explicit_name
end
Expand Down Expand Up @@ -320,8 +337,8 @@ function M.parse_crate_table_feat(line: string, line_nr: integer): Crate.Feat
return nil
end

function M.parse_crate_table_def(line: string, line_nr: integer): Crate.Def
local bool_s, text, bool_e = line:match("^%s*default[_-]features%s*=%s*()([^%s]*)()%s*$")
local function parse_crate_table_bool(line: string, line_nr: integer, pattern: string): table|nil
local bool_s, text, bool_e = line:match(pattern)
if text then
return {
text = text,
Expand All @@ -334,6 +351,16 @@ function M.parse_crate_table_def(line: string, line_nr: integer): Crate.Def
return nil
end

function M.parse_crate_table_def(line: string, line_nr: integer): Crate.Def
local pat = "^%s*default[_-]features%s*=%s*()([^%s]*)()%s*$"
return parse_crate_table_bool(line, line_nr, pat) as Crate.Def
end

function M.parse_crate_table_workspace(line: string, line_nr: integer): Crate.Def
local pat = "^%s*workspace%s*=%s*()([^%s]*)()%s*$"
return parse_crate_table_bool(line, line_nr, pat) as Crate.Def
end

local function parse_inline_table_str(crate: Crate, line: string, line_nr: integer, entry: string, pattern: string)
local name_s, name, name_e, decl_s, quote_s, str_s, text, str_e, quote_e, decl_e = line:match(pattern)
if name then
Expand All @@ -351,6 +378,22 @@ local function parse_inline_table_str(crate: Crate, line: string, line_nr: integ
end
end

local function parse_inline_table_bool(crate: Crate, line: string, line_nr: integer, entry: string, pattern: string)
local name_s, name, name_e, decl_s, quote_s, str_s, text, str_e, quote_e, decl_e = line:match(pattern)
if name then
crate.explicit_name = name
crate.explicit_name_col = Range.new(name_s as integer - 1, name_e as integer - 1)
do
(crate as {string:any})[entry] = {
text = text,
line = line_nr,
col = Range.new(str_s as integer - 1, str_e as integer - 1),
decl_col = Range.new(decl_s as integer - 1, decl_e as integer - 1),
}
end
end
end

function M.parse_crate(line: string, line_nr: integer): Crate
-- plain version
do
Expand Down
1 change: 1 addition & 0 deletions teal/crates/types.tl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local record M
"registry"
"path"
"git"
"workspace"
end

record Diagnostic
Expand Down

0 comments on commit f5da000

Please sign in to comment.