CPS-376 Spike: Investigate introducing ANTRL to resolve CpsPaths
CPS-376: Spike: Investigate introducing ANTRL to resolve CpsPathsClosed
Reference Material
https://github.com/antlr/antlr4/blob/master/doc/getting-started.md
https://pragprog.com/titles/tpantlr2/the-definitive-antlr-4-reference/#resources
IntelliJ Ant plugin
https://github.com/antlr/intellij-plugin-v4 useful for testing and troubleshooting while developing grammar
PoC Code
https://gerrit.onap.org/r/c/cps/+/121503 (production ready!)
Findings
Antlr4 can replace regex with less and more readable code
Replacement of regex for
CpsPathQuery
fully replaced by fully compatible object generated using Antlr4 this commit: https://gerrit.onap.org/r/c/cps/+/121503Needed to add explicit error rule for handling unexpected tokens (otherwise Antlr would ignore them):
ErrorCharacter : . ;
Current CPS code using regex is inconsistent and needless limited for single leave condition
Current CPS code was lacking @ token for attribute names in some test cases (fixed in https://gerrit.onap.org/r/c/cps/+/121503)
CpsPathQuerySpec
did not cover all necessary possibilities (as used in some DB integration tests) This has now been addressedCpsDataPersistenceQueryDataNodeSpec
contains some grammar tests that should be (are already) inCpsPathQuerySpec
IntelliJ plugin very useful for quick testing and troubleshooting of grammar
Not sure of best way to refresh generated code (in IntelliJ)
mvn clean install
in cps-path-parser seems the surest way
Xpath31 grammar
The grammar defined in predefined xpath grammer: https://github.com/antlr/grammars-v4/tree/master/xpath/xpath31
To-Do
Check and Improve error handling
Re-use CpsPath Exception (wrap IllegalState exception)
Clean up, simplify rules and remove redundant legacy limitations
Better names (check name-casing conventions Antrl)
Consider using predefined xpath grammer: https://github.com/antlr/grammars-v4/tree/master/xpath/xpath31
Even just study it or extract small parts to get correct definition of valid container-names etc.