1 /**********************************************************
2 * This script provides syntax highlighting support for
4 * Ntriples format specification:
5 * http://www.w3.org/TR/rdf-testcases/#ntriples
6 ***********************************************************/
9 The following expression defines the defined ASF grammar transitions.
13 ( writing_subject_uri | writing_bnode_uri )
15 -> writing_predicate_uri
17 -> writing_object_uri | writing_object_bnode |
19 writing_object_literal
20 -> writing_literal_lang | writing_literal_type
28 CodeMirror.defineMode("ntriples", function() {
33 WRITING_BNODE_URI : 2,
38 WRITING_OBJ_BNODE : 7,
39 WRITING_OBJ_LITERAL : 8,
41 WRITING_LIT_TYPE : 10,
45 function transitState(currState, c) {
46 var currLocation = currState.location;
50 if (currLocation == Location.PRE_SUBJECT && c == '<') ret = Location.WRITING_SUB_URI;
51 else if(currLocation == Location.PRE_SUBJECT && c == '_') ret = Location.WRITING_BNODE_URI;
52 else if(currLocation == Location.PRE_PRED && c == '<') ret = Location.WRITING_PRED_URI;
53 else if(currLocation == Location.PRE_OBJ && c == '<') ret = Location.WRITING_OBJ_URI;
54 else if(currLocation == Location.PRE_OBJ && c == '_') ret = Location.WRITING_OBJ_BNODE;
55 else if(currLocation == Location.PRE_OBJ && c == '"') ret = Location.WRITING_OBJ_LITERAL;
58 else if(currLocation == Location.WRITING_SUB_URI && c == '>') ret = Location.PRE_PRED;
59 else if(currLocation == Location.WRITING_BNODE_URI && c == ' ') ret = Location.PRE_PRED;
60 else if(currLocation == Location.WRITING_PRED_URI && c == '>') ret = Location.PRE_OBJ;
61 else if(currLocation == Location.WRITING_OBJ_URI && c == '>') ret = Location.POST_OBJ;
62 else if(currLocation == Location.WRITING_OBJ_BNODE && c == ' ') ret = Location.POST_OBJ;
63 else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '"') ret = Location.POST_OBJ;
64 else if(currLocation == Location.WRITING_LIT_LANG && c == ' ') ret = Location.POST_OBJ;
65 else if(currLocation == Location.WRITING_LIT_TYPE && c == '>') ret = Location.POST_OBJ;
67 // Closing typed and language literal.
68 else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '@') ret = Location.WRITING_LIT_LANG;
69 else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '^') ret = Location.WRITING_LIT_TYPE;
74 currLocation == Location.PRE_SUBJECT ||
75 currLocation == Location.PRE_PRED ||
76 currLocation == Location.PRE_OBJ ||
77 currLocation == Location.POST_OBJ
82 else if(currLocation == Location.POST_OBJ && c == '.') ret = Location.PRE_SUBJECT;
85 else ret = Location.ERROR;
87 currState.location=ret;
91 startState: function() {
93 location : Location.PRE_SUBJECT,
101 token: function(stream, state) {
102 var ch = stream.next();
104 transitState(state, ch);
106 stream.eatWhile( function(c) { if( c != '#' && c != '>' ) { parsedURI += c; return true; } return false;} );
107 state.uris.push(parsedURI);
108 if( stream.match('#', false) ) return 'variable';
110 transitState(state, '>');
114 var parsedAnchor = '';
115 stream.eatWhile(function(c) { if(c != '>' && c != ' ') { parsedAnchor+= c; return true; } return false;});
116 state.anchors.push(parsedAnchor);
120 transitState(state, '>');
124 transitState(state, ch);
125 var parsedBNode = '';
126 stream.eatWhile(function(c) { if( c != ' ' ) { parsedBNode += c; return true; } return false;});
127 state.bnodes.push(parsedBNode);
129 transitState(state, ' ');
133 transitState(state, ch);
134 stream.eatWhile( function(c) { return c != '"'; } );
136 if( stream.peek() != '@' && stream.peek() != '^' ) {
137 transitState(state, '"');
142 transitState(state, '@');
144 stream.eatWhile(function(c) { if( c != ' ' ) { parsedLang += c; return true; } return false;});
145 state.langs.push(parsedLang);
147 transitState(state, ' ');
152 transitState(state, '^');
154 stream.eatWhile(function(c) { if( c != '>' ) { parsedType += c; return true; } return false;} );
155 state.types.push(parsedType);
157 transitState(state, '>');
161 transitState(state, ch);
164 transitState(state, ch);
170 CodeMirror.defineMIME("text/n-triples", "ntriples");