//
// Created by intellij-pest on 2021-10-01
// version-dsl
// Author: okno
//

delimiter_start = _{ "{{" }
delimiter_end = _{ "}}" }
current_version = { "version" }
latest_version = { "latest" }
current_tag = { "version_tag" }
latest_tag = { "latest_tag" }

add = { "+" }

major = { "major" }
minor = { "minor" }
patch = { "patch" }

version_access_major = { dot ~ "major" }
version_access_minor = { dot ~ "minor" }
version_access_patch = { dot ~ "patch" }

amt = { NUMBER }
ops = { add ~ amt? ~ ( major | minor | patch ) }
ASCII_ALPHA_OR_HYPHEN = { ASCII_ALPHA | NUMBER | "-" }

pre_release_separator = _{ "-" }
build_metadata_separator = _{ "+" }
dot = _{ "." }

identifier = { ASCII_ALPHA_OR_HYPHEN+ }
identifiers = { identifier ~ (dot ~ identifier)* }
pre_release = { pre_release_separator ~ identifiers }
build_metadata = { build_metadata_separator ~ identifiers }

default_separator = _{"|"}
default_version = {  default_separator ~ identifiers }

package = { "package" }
version = { delimiter_start ~ (
        ((current_tag | current_version | latest_tag | latest_version) ~ default_version? ~ ops* ~ pre_release? ~ build_metadata?)
        | package
    ) ~ ( version_access_major | version_access_minor | version_access_patch )? ~ delimiter_end}
version_dsl = { SOI ~ ( version | (!delimiter_start ~ ANY) )* ~ EOI }
