About to write another extension of Ant hook scripts and discovered that the file format I needed was too complex. So, in this post I present another implementation in Groovy.
Update: changed the URL of this blog post.
In two prior posts I presented a very simple metadata file storage approach. Pretty much using the INI file format as an external “heredoc”. I now call this an INIX format. Btw, this file extension is already being used by the Adobe InDesign product.
In the example below, the section is uniquely identified with a path, and the query string supplies parameters to any client accessing the data.
[>hook/root/compile?when=after,skip=false] println " hook: root,{target=${event.target.name},when=post,event=$event}" [<]
The terminal tag could have also been written as: [<hook/root/compile]
The change from the previous INIX format is in the section header format. It is now more like a URL: [>path#fragment-id?query-string]
The query string is not following the full URL spec, it uses ‘&’ to separate entries. Also, commas are used as in Groovy Object Notation (GRON).
Example
In a blog post, “Ant hooks using Groovy, INIX, and XMLTask“, I show how an inix file can be used to store multiple Groovy scripts to be used as Ant hooks.
Implementation
Source code available at Github: https://gist.github.com/josefbetancourt/7701645
[/expand]
Test class
Note that there are not enough tests and the implementation code has not been reviewed.
[/expand]
The test data is:
[/expand]
Grammar
A possible grammar follows, but has not been ‘checked’ by attempted use of a parser generator like Antlr.
section : '[>' path ('#' fragment)? ('?' args)? ']' data '[<' path? ']'; path : NAME ('/' NAME)*; fragment : NAME; args : (NAME=NAME (',' NAME=NAME)*)?; data : (ANYTHING CRLF)*; NAME : ('a'..'z' | 'A'..'Z')('a' .. 'z' | 'A'..'Z'|'0'..'9'|'_');
- Now that the query string is being used, we can add “import” of sections. A section ID beginning with ‘@’, will reuse the contents of another section. Any content in the destination section will be appended to the imported content of the source section. Import here does not mean a namespace concern as in Java imports.
- Allow multiple params per param key: ?measure=21,measure=34,measure=90. Or better yet, just allow array in arg string: measure=[21,34,90],color=red
Further Reading
2 thoughts on “Groovy implementation of INIX file format”