Skip to content

Commit

Permalink
Merge pull request #219 from psrenergy/gb/fix-pmd-parser-for-new-tags
Browse files Browse the repository at this point in the history
Add new metadata tags to pmd
  • Loading branch information
guilhermebodin authored Jun 5, 2024
2 parents 3732632 + 6b28eec commit e84b3fd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "PSRClassesInterface"
uuid = "1eab49e5-27d8-4905-b9f6-327b6ea666c4"
version = "0.15.0"
version = "0.16.0"

[deps]
DBInterface = "a10d1c49-ce27-4219-8d33-6db1a4562965"
Expand Down
22 changes: 18 additions & 4 deletions src/PMD/parser/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ function _apply_tag!(
parser,
"Unhandled '$tag' tag for '$(attribute)' within '$(collection)' definition",
)
elseif tag == "@addyear_modification"
_warning(
parser,
"Unhandled '$tag' tag for '$(attribute)' within '$(collection)' definition",
)
elseif tag == "@addyear_chronological"
_warning(
parser,
"Unhandled '$tag' tag for '$(attribute)' within '$(collection)' definition",
)
else
_syntax_error(
parser,
Expand Down Expand Up @@ -612,7 +622,7 @@ function _parse_attribute!(
state::S,
) where {S <: Union{PMD_DEF_MODEL, PMD_DEF_CLASS, PMD_MERGE_CLASS}}
m = match(
r"(PARM|VECTOR|VETOR)\s+(INTEGER|REAL|DATE|STRING)\s+(\S+)(\s+DIM\((\S+(,\S+)*)\))?(\s+INDEX\s+(\S+))?(\s+(\@\S+))?",
r"(PARM|VECTOR|VETOR)\s+(INTEGER|REAL|DATE|STRING)\s+(\S+)(\s+DIM\((\S+(,\S+)*)\))?(\s+INDEX\s+(\S+))?((\s+(\@\S+))+)?",
line,
)

Expand All @@ -622,7 +632,7 @@ function _parse_attribute!(
name = m[3]
dims = m[5]
index = m[8]
tag = m[10]
tags = m[9]

if haskey(parser.data_struct[state.collection], name)
if PMD._is_vector(kind) != parser.data_struct[state.collection][name].is_vector
Expand Down Expand Up @@ -665,8 +675,12 @@ function _parse_attribute!(
(index === nothing) ? "" : index,
)

if tag !== nothing
_apply_tag!(parser, state.collection, name, tag)
if tags !== nothing
for tag in split(strip(tags), " ")
if !isempty(tag)
_apply_tag!(parser, state.collection, name, tag)
end
end
end

return true
Expand Down
3 changes: 2 additions & 1 deletion test/data/pmd/source3.pmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DEFINE_CLASS PSRBus
END_CLASS

DEFINE_CLASS PSRElement
VETOR DATE Data @addyear_modification
PARM INTEGER NumberUnits
PARM INTEGER Code @id
END_CLASS
Expand All @@ -28,7 +29,7 @@ DEFINE_CLASS PSRGeneratorUnit
PARM REFERENCE Bus PSRBus
VECTOR REFERENCE Buses PSRBus
VECTOR REFERENCE Element PSRElement
VETOR DATE Date @chronological
VETOR DATE Date @chronological @addyear_chronological
END_CLASS

DEFINE_MODEL PSRTest
Expand Down
2 changes: 2 additions & 0 deletions test/pmd_parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ function test_pmd_source_3()
PSRI.PMD.Attribute("name", false, String, 0, ""),
"Code" =>
PSRI.PMD.Attribute("Code", false, Int32, 0, ""),
"Data" =>
PSRI.PMD.Attribute("Data", true, Dates.Date, 0, ""),
"code" =>
PSRI.PMD.Attribute("code", false, Int32, 0, ""),
"NumberUnits" => PSRI.PMD.Attribute(
Expand Down

2 comments on commit e84b3fd

@guilhermebodin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/108343

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.16.0 -m "<description of version>" e84b3fd23fc4cc5e8237ee92d6a63fda7d671d33
git push origin v0.16.0

Please sign in to comment.