Skip to content

[Puml Parser] Support free functions in class diagram - #511

Merged
hoe-jo merged 1 commit into
eclipse-score:mainfrom
melodyoncode:melody_puml_parse_free_function
Oct 13, 2026
Merged

hoe-jo merged 1 commit into
eclipse-score:mainfrom
melodyoncode:melody_puml_parse_free_function

Conversation

@melodyoncode

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread plantuml/parser/docs/class-diagram.md Outdated
namespace algorithm {
entity Placeholder <<function>> {
+ clamp(value, min, max)
+ max<T> max(a, b)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

max max(a, b)fails to parse (grammar isname(params): Ret, no leading return type). Use + max(a, b).

Comment thread plantuml/parser/docs/class-diagram.md Outdated
Comment on lines +39 to +41
This resolves to the free functions `amp.algorithm.clamp`. Visibility markers
such as `+` are accepted for plantUML compatibility and do not affect
free-function semantics.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"plantUML" → "PlantUML"; also lists only clamp, add max

type_kind = {
"abstract" ~ "class"
| "class"
| "entity"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"entity"has no word boundary.entity1 --> Fooandentity_manager --> Foo now fail to parse (parsed fine on main, even afterclass entity_manager). Same flaw already exists for class/struct/interface, but this widens it. Add !(ASCII_ALPHANUMERIC | "_") after the keyword, ideally for all of type_kind.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch.
While checking the grammar, I also found the same declaration-without-body pattern for object and enum; I will apply the same boundary there to keep the top-level declaration rules consistent.

Comment on lines +763 to +773
"entity" => {
let def = self.parse_type_def_into::<ClassDef>(pair)?;
Ok(Element::EntityDef(EntityDef {
name: def.name,
namespace: def.namespace,
package: def.package,
stereotypes: def.stereotypes,
methods: def.methods,
source_location,
}))
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

template params, extends/implements, attributes and type aliases on an entity are dropped silently. entity E <>andentity E extends Base <> both parse with no diagnostic. Reject or document.

@melodyoncode melodyoncode Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've documented this limitation in the class-diagram support guide. I’m keeping the current behavior unchanged rather than adding rejection logic in this change.
After the abstract of class/interface/struct/..., maybe rejecting these constructs can be handled as a follow-up.

.any(|stereotype| stereotype.eq_ignore_ascii_case("function"))
}

fn process_free_function_entity(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

only scope.id is used, so entity amp.algorithm.Fn <>at root givesenclosing_namespace_id: None. Classes use the qualified name for the namespace.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

supported and add the following integration test

entity amp.algorithm.Fn <<function>> {
    + run()
}

@melodyoncode
melodyoncode force-pushed the melody_puml_parse_free_function branch from 3570a78 to 49fa9c0 Compare October 9, 2026 05:14
@hoe-jo
hoe-jo self-requested a review October 12, 2026 11:03
@hoe-jo
hoe-jo added this pull request to the merge queue Oct 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Oct 12, 2026
@hoe-jo
hoe-jo force-pushed the melody_puml_parse_free_function branch from 49fa9c0 to 498aa5d Compare October 12, 2026 13:53
@hoe-jo
hoe-jo enabled auto-merge October 12, 2026 13:53
auto-merge was automatically disabled October 13, 2026 01:27

Head branch was pushed to by a user without write access

@melodyoncode
melodyoncode force-pushed the melody_puml_parse_free_function branch from 498aa5d to 13825d8 Compare October 13, 2026 01:27
@hoe-jo
hoe-jo added this pull request to the merge queue Oct 13, 2026
Merged via the queue into eclipse-score:main with commit 5021deb Oct 13, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants