Skip to content
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

Implement fluent parser & start migration #1408

Merged
merged 1 commit into from
Oct 9, 2024
Merged

Implement fluent parser & start migration #1408

merged 1 commit into from
Oct 9, 2024

Conversation

Pablete1234
Copy link
Member

For a long while, PGM has had an explosion of parsing methods to support the different ways in which we can parse. Overloads upon overloads for parsing a node, an element, an attribute, required or with a default, maybe with a validation in there too.

That doesn't create the cleanest programming model, and it's why i want to move away from it. Welcome fluent parsing api:

// Before (yes, all diff 10  overloads exist for filters):
var a1 = parseProperty(el, "filter"); // Defaults to null, non-obvious
var b1 = parseProperty(el, "filter", StaticFilter.ALLOW); // Defaults to ALLOW
var c1 = parseProperty(el, "filter", DynamicFilterValidation.ANY); // Defaults to null, non-obvious
var d1 = parseProperty(el, "filter", StaticFilter.ALLOW, DynamicFilterValidation.ANY);

var a2 = parseProperty(Node.fromChildOrAttr(el, "filter", "trigger"));
var b2 = parseProperty(Node.fromChildOrAttr(el, "filter", "trigger"), StaticFilter.ALLOW);
var c2 = parseProperty(Node.fromChildOrAttr(el, "filter", "trigger"), DynamicFilterValidation.ANY);
var d2 = parseProperty(Node.fromChildOrAttr(el, "filter", "trigger"), StaticFilter.ALLOW, DynamicFilterValidation.ANY);

var a3 = parseRequiredProperty(el, "filter");
var b3 = parseRequiredProperty(el, "filter", DynamicFilterValidation.ANY);

// After
var a1 = parser.filter(el, "filter").orNull();
var b1 = parser.filter(el, "filter").orAllow();
var c1 = parser.filter(el, "filter").dynamic().orNull();
var d1 = parser.filter(el, "filter").dynamic().orAllow();

var a2 = parser.filter(el, "filter", "trigger").orNull();
var b2 = parser.filter(el, "filter", "trigger").orAllow();
var c2 = parser.filter(el, "filter", "trigger").dynamic().orNull();
var d2 = parser.filter(el, "filter", "trigger").dynamic().orAllow();

var a3 = parser.filter(el, "filter").required();
var b3 = parser.filter(el, "filter").dynamic().required();

This is just a specific example for filters (listing all 10 former methods) but the new api also comes with more methods like optional(defaultValue) of which orAllow is just an overload specifically for filters. The beauty is we can compose these calls without having an explosion in method overloads.

@Pablete1234 Pablete1234 added the refactor Code needs to be redesigned label Oct 9, 2024
@Pablete1234 Pablete1234 merged commit 7aa3109 into dev Oct 9, 2024
2 checks passed
@Pablete1234 Pablete1234 deleted the fluent-parser branch October 9, 2024 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code needs to be redesigned
Development

Successfully merging this pull request may close these issues.

2 participants