Improve syntax of generated Turtle files
mchlrch opened this issue · 2 comments
Improve the syntax of the generated .ttl
files.
Original issue: #138
I suspect that the irregular punctuation leads to the mentioned parsing issues.
Here's the turtle spec: https://www.w3.org/TR/turtle/#sec-grammar
The grammar of ttl has a lot of those separators like ';' in it, maybe even a postfix like '.' for the statement:
predicateObjectList ::= verb objectList (';' (verb objectList)?)*
statement ::= directive | triples '.'
When generating a segment, you are never sure whether to put a seperator. There are two approaches to fix this: lookahead or postprocessing. Lookahead is a bit annoying since you have to implement the specific logic for every feature (btw: this is unavoidable when implementing xtext formatting 2). Postprocessing on the other hand only comes with the cost of processing power - during generation phase one generates marker into the file. As soon as we are done generating, we can call the stateful context per file and execute the postprocessing, which just replaces the markers with the separator or postfix token (since these contexts are able to make the decision which one to chose).
Solution: Introducing IJoinContext, which implements postprocessing. TTL files look neat. This also replaces GlueingContext and stuff like extension 'jsonListSeparator' Therefore the generated syntax of the Json files also has improved. This solution also looks also sustainable for future changes.
For examples see *.ttl and *.json files here: how generated ttl and json files changed in this feature branch
Nice and tidy solution with the JoinContext, I like it.
Closing this.