This is entirely possible but it is not at all trivial. We have been doing this 
for several years to add several extensions to the language. The extent of the 
necessary changes Will vary depending on what your extensions are intended to 
do.

To start with the grammar. You can find the input files in a Grammer/ 
sub-directory within the ARQ module.  master.jj is the main file and uses C 
style #ifdef to add/remove language features depending on the Target language. 
So the best approach is to modify master.jj and insert your own #ifdef sections 
with your grammar rules.

The grammar script pre-processes this file into the other *.jj files as 
#ifdef's are not valid in JavaCC inputs. You will need to modify the script to 
be able to generate your newly defined grammar.

What else you need to do will depend on the language features you are creating. 
If all the keywords you introduce are shorthand for existing language features 
then the grammar is the main piece you need.

However in order for your new parser to be used you will need to register it as 
a language. Doing this requires you to implement the SPARQLParserFactory 
interface which has
an accept(Syntax) and a create(Syntax) method. The former indicates whether 
your factory can parse a given syntax and the latter creates a parser for your 
language from which you can simply return the JavaCC generated 
SPARQLParserYourLang class. You'll probably want to define your own Syntax 
Constant so that you can create queries in your language by calling 
QueryFactory.create(query, YourSyntax), note that you will need to call 
SPARQLParserRegistry.addFactory(YourSyntax, YourParserFactory) for this to work.

If your language extensions require new operators then you have significantly 
more work on your hands. I can go into everything required for that as well if 
desired in a future email?

Another thing to consider is whether you want queries using your new language 
features to round trip i.e. string -> parsed query -> string? This can also 
require quite a bit of work depending upon how invasive your language features 
are. Again probably a separate email.

Good luck, please send further questions to the list as you have them and we 
will do our best to answer them

Rob

On 05/02/2018, 20:42, "Berkin Özdemir Bengisu" 
<[email protected]> wrote:

    Hello,
    
    I am using jena 3.6.0 and I would like to extend the sparql 1.1 grammar
    with some new keywords. Could you please help me what would be the best way
    to start with?
    
    - As I understood, the grammar is generated by javaCC but I was unable to
    find any documentation or any main classes that actually generate the
    grammar. Are grammar classes generated as an out source and then added to
    the project?
    
    I would be really glad if you could guide me on this.
    
    Best
    Berkin
    




Reply via email to