diff --git a/base/binaryplatforms.jl b/base/binaryplatforms.jl index b374d57ce9731..e0ee107c4ec73 100644 --- a/base/binaryplatforms.jl +++ b/base/binaryplatforms.jl @@ -661,18 +661,12 @@ const libstdcxx_version_mapping = Dict{String,String}( "libstdcxx" => "-libstdcxx\\d+", ) -""" - parse(::Type{Platform}, triplet::AbstractString) - -Parses a string platform triplet back into a `Platform` object. -""" -function Base.parse(::Type{Platform}, triplet::String; validate_strict::Bool = false) +const triplet_regex = let # Helper function to collapse dictionary of mappings down into a regex of # named capture groups joined by "|" operators c(mapping) = string("(",join(["(?<$k>$v)" for (k, v) in mapping], "|"), ")") - # We're going to build a mondo regex here to parse everything: - triplet_regex = Regex(string( + Regex(string( "^", # First, the core triplet; arch/os/libc/call_abi c(arch_mapping), @@ -687,7 +681,14 @@ function Base.parse(::Type{Platform}, triplet::String; validate_strict::Bool = f "(?(?:-[^-]+\\+[^-]+)*)?", "\$", )) +end +""" + parse(::Type{Platform}, triplet::AbstractString) + +Parses a string platform triplet back into a `Platform` object. +""" +function Base.parse(::Type{Platform}, triplet::String; validate_strict::Bool = false) m = match(triplet_regex, triplet) if m !== nothing # Helper function to find the single named field within the giant regex