-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: deps_version_parser.lua #47
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
在调整架构, 等待一起合入 |
lvyuemeng
reviewed
Dec 16, 2024
@@ -1,5 +1,5 @@ | |||
-- 解析单个版本字符串到版本对象 | |||
function parse_single_version(version_str) | |||
function parse_single_version_range(version_str) | |||
local version = {} | |||
if version_str == "any" or version_str == "*" then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local Version = {}
Version.__index = Version
function Version:new(str)
local self = setmetatable({},Version}
self:parse(str)
return self
end
function Version:parse(str)
local pattern = (...)
local major,minor,patch,prerelease,build = str:match(pattern)
self.major = tonumber(major) or 0
self.minor = tonumber(minor) or 0
self.patch = tonumber(patch) or 0
self.prerelease = prerelease or ""
self.build = build or ""
end
function Version:compare(other)
if self.major ~= other.major then
return self.major - other.major
end
if self.minor ~= other.minor then
return self.minor - other.minor
end
if self.patch ~= other.patch then
return self.patch - other.patch
end
if self.prerelease ~= other.prerelease then
if self.prerelease == "" then
return 1
elseif other.prerelease == "" then
return -1
else
return self.prerelease < other.prerelease and 1 or -1
end
end
return 0
end
function Version:__lt(other)
return self:compare(other) < 0
end
function Version:__le(other)
return self:compare(other) <= 0
end
function Version:__eq(other)
return self:compare(other) == 0
end
function Version:__gt(other)
return self:compare(other) > 0
end
function Version:__ge(other)
return self:compare(other) >= 0
end
lvyuemeng
reviewed
Dec 16, 2024
@@ -51,10 +51,10 @@ function parse_single_version(version_str) | |||
end | |||
|
|||
-- 解析复合版本字符串到版本对象 | |||
function parse_version(version_str) | |||
function parse_version_ranges(version_str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local Constraint = {}
Constraint.__index = Constraint
function Constraint:new(str)
local self = setmetatable({},Constraint)
self:parse(str)
return self
end
function Constraint:parse(str)
local pattern = (...)
local op,version_str = str:match(pattern)
self.op = op
self.version = Version:new(version_str)
end
function Constraint:include(version)
if self.operator == "*" then
return true -- "*" means any version
elseif self.operator == "<=" then
return version <= self.version
elseif self.operator == "<" then
return version < self.version
elseif self.operator == ">=" then
return version >= self.version
elseif self.operator == ">" then
return version > self.version
elseif self.operator == "=" then
return version == self.version
else
return false
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local Constraints = {}
Constraints.__index = Constraints
function Constraints:new(str)
local self = setmetatable({},Constraints)
self:parse(str)
return self
end
function Constraints:parse(str)
self.constraints = {}
for part in str:gmatch(...) do
table.insert(self.constraints,Constraint:new(part))
end
end
function Constraints:include(version)
for _,constraint in ipairs(self.constraints) do
if not constraint:include(verison) then
return false
end
end
return true
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
这样大概可以了? #45