zazuko / xrm

A friendly language for mappings to RDF
MIT License
1 stars 0 forks source link

Improve syntax of generated Turtle files #118

Closed mchlrch closed 2 years ago

mchlrch commented 2 years ago

Improve the syntax of the generated .ttl files.

Original issue: https://github.com/zazuko/xrm/issues/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

nnamtug commented 2 years ago

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

mchlrch commented 2 years ago

Nice and tidy solution with the JoinContext, I like it.

Closing this.