Skip to content

Added example how to use custom function in logical parser - #52

Merged
gbenroscience merged 1 commit into
gbenroscience:masterfrom
judovana:customLogicalFunctionUsability
Dec 3, 2026
Merged

gbenroscience merged 1 commit into
gbenroscience:masterfrom
judovana:customLogicalFunctionUsability

Conversation

@judovana

@judovana judovana commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

I was experimenting a bit with custom functions in LogicalParser (with future hackish usage like [ isWindows(0) ==0 && jdkVersion(0) > 20] || isLinux(0) ==0 in mind) and although it do not work out of the box, it works good enough.

Added test showing how to use custom functions (well any functions) in logical parser.

@judovana

judovana commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

The jdk8 test failure do not look related:

2026-12-03T10:50:15.7914488Z [INFO] -------------------------------------------------------
2026-12-03T10:50:15.7915287Z [INFO]  T E S T S
2026-12-03T10:50:15.7915807Z [INFO] -------------------------------------------------------
2026-12-03T10:50:16.5569975Z [INFO] Running com.github.gbenroscience.util.FunctionScopeTest
2026-12-03T10:50:17.0795165Z [ERROR] Tests run: 32, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.495 s <<< FAILURE! -- in com.github.gbenroscience.util.FunctionScopeTest
2026-12-03T10:50:17.0823701Z [ERROR] com.github.gbenroscience.util.FunctionScopeTest.hotPathsAllocateNothing -- Time elapsed: 0.128 s <<< FAILURE!
2026-12-03T10:50:17.0825026Z org.opentest4j.AssertionFailedError: scoped solveGeneric allocated 16520 bytes vs 0 unscoped ==> expected: <true> but was: <false>
2026-12-03T10:50:17.0900625Z 	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
2026-12-03T10:50:17.0934573Z 	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
2026-12-03T10:50:17.0961284Z 	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
2026-12-03T10:50:17.0961966Z 	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
2026-12-03T10:50:17.0962574Z 	at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:214)
2026-12-03T10:50:17.0963545Z 	at com.github.gbenroscience.util.FunctionScopeTest.hotPathsAllocateNothing(FunctionScopeTest.java:624)
2026-12-03T10:50:17.0964284Z 	at java.lang.reflect.Method.invoke(Method.java:498)
2026-12-03T10:50:17.0964741Z 	at java.util.ArrayList.forEach(ArrayList.java:1259)
2026-12-03T10:50:17.0965178Z 	at java.util.ArrayList.forEach(ArrayList.java:1259)
2026-12-03T10:50:17.0965452Z 
2026-12-03T10:50:17.0965665Z [INFO] Running com.github.gbenroscience.parser.SetTest
2026-12-03T10:50:17.0966388Z [INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.006 s -- in com.github.gbenroscience.parser.SetTest
2026-12-03T10:50:17.0967290Z [INFO] Running com.github.gbenroscience.parser.logical.AlgebraExpressionParserTest
...
2026-12-03T10:51:15.1606223Z Sometimes, Lx, as number is not enough, and you need to calcualte it dynamically. To do so, you can use L{}
2026-12-03T10:51:15.1606538Z Inisde {} can be mathematical formula (including Ls, MN. or even nested {}, which will evaluate itself as number, which will be used as Lx. Eg:
2026-12-03T10:51:15.1606791Z 'avg(..L{MN/2}) < avg(L{MN/2}..)' will go to 'avg(..L1) < avg(L1..)' will go on 1 2 3 to 'avg(1,2 ) < avg(2,3) will go to 1.5<2.5 ... true'
2026-12-03T10:51:15.1606950Z For fun try eg: VALUES_PNG='1 2 3' on 'avg(..L{L{MN/2}}) < avg(L{L{MN/2}}..)'
2026-12-03T10:51:15.1607371Z This parser by default uses LogicalExpression interpreter, but should work directly on simple Logical or Math expressions. The LogicalExpression class canbe repalced if needed.
2026-12-03T10:51:15.1607500Z In verbose mode, the expanded expression is always printed
2026-12-03T10:51:15.1607772Z [INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.011 s -- in com.github.gbenroscience.math.MainTest
2026-12-03T10:51:15.1661049Z [INFO] 
2026-12-03T10:51:15.1687524Z [INFO] Results:
2026-12-03T10:51:15.1687823Z [INFO] 
2026-12-03T10:51:15.1688009Z [ERROR] Failures: 
2026-12-03T10:51:15.1689092Z [ERROR]   FunctionScopeTest.hotPathsAllocateNothing:624 scoped solveGeneric allocated 16520 bytes vs 0 unscoped ==> expected: <true> but was: <false>
2026-12-03T10:51:15.1689688Z [INFO] 
2026-12-03T10:51:15.1689926Z [ERROR] Tests run: 787, Failures: 1, Errors: 0, Skipped: 0

Was that test ever working on jdk8?

@gbenroscience
gbenroscience merged commit f2929c3 into gbenroscience:master Dec 3, 2026
19 of 20 checks passed
@gbenroscience

Copy link
Copy Markdown
Owner

The tests have passed. Thanks for your contribution

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