Parser

What technology does the TurtleScript parser use?

The turtlescript parser is written using the ANTLR v3 compiler generator available from www.antlr.org.

Currently there is a Javascript target and a Java target. The Java target is intended primarily to test the ANTLR gramamr. There are plenty of libraries that parse Turtle in languages such as Java and Python.


What does the javascript generated by the Turtlescript grammar look like?

The Turtlescript parser currently generates a very simple Javascript format for evalutation purposes. This will mature and become better documented in future releases.


Do I need to include the Turtlescript parser to use Turtlescript?
No. You only need the Turtlescript parser if you want to manipulate and display Turtlescript from Javascript. Third party tools can still read Turtlescript on your page, though these are currently rare.
How do I include the Turtlescript parser in an HTML page?

Add the following lines to your html:

]]>

Add the lib directory to your application. Copy it from the example.

See the example for more details.


How do I invoke the Turtlescript parser from Javascript?

Call the following code after the page is loaded (for example in a JQuery $(document).ready() function):

var n3 = getTurtleText(); $().log(n3); var cstream = new org.antlr.runtime.ANTLRStringStream(n3); var lexer = new N3Lexer(cstream); var tstream = new org.antlr.runtime.CommonTokenStream(lexer); var parser = new N3Parser(tstream); parser.n3();

See example.js for more details.