33
if (typeof exports == "object" && typeof module == "object")
34
mod(require("../../lib/codemirror"));
35
else if (typeof define == "function" && define.amd)
36
define(["../../lib/codemirror"], mod);
39
})(function(CodeMirror) {
42
CodeMirror.defineMode("ntriples", function() {
47
WRITING_BNODE_URI : 2,
52
WRITING_OBJ_BNODE : 7,
53
WRITING_OBJ_LITERAL : 8,
55
WRITING_LIT_TYPE : 10,
59
function transitState(currState, c) {
60
var currLocation = currState.location;
64
if (currLocation == Location.PRE_SUBJECT && c == '<') ret = Location.WRITING_SUB_URI;
65
else if(currLocation == Location.PRE_SUBJECT && c == '_') ret = Location.WRITING_BNODE_URI;
66
else if(currLocation == Location.PRE_PRED && c == '<') ret = Location.WRITING_PRED_URI;
67
else if(currLocation == Location.PRE_OBJ && c == '<') ret = Location.WRITING_OBJ_URI;
68
else if(currLocation == Location.PRE_OBJ && c == '_') ret = Location.WRITING_OBJ_BNODE;
69
else if(currLocation == Location.PRE_OBJ && c == '"') ret = Location.WRITING_OBJ_LITERAL;
72
else if(currLocation == Location.WRITING_SUB_URI && c == '>') ret = Location.PRE_PRED;
73
else if(currLocation == Location.WRITING_BNODE_URI && c == ' ') ret = Location.PRE_PRED;
74
else if(currLocation == Location.WRITING_PRED_URI && c == '>') ret = Location.PRE_OBJ;
75
else if(currLocation == Location.WRITING_OBJ_URI && c == '>') ret = Location.POST_OBJ;
76
else if(currLocation == Location.WRITING_OBJ_BNODE && c == ' ') ret = Location.POST_OBJ;
77
else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '"') ret = Location.POST_OBJ;
78
else if(currLocation == Location.WRITING_LIT_LANG && c == ' ') ret = Location.POST_OBJ;
79
else if(currLocation == Location.WRITING_LIT_TYPE && c == '>') ret = Location.POST_OBJ;
82
else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '@') ret = Location.WRITING_LIT_LANG;
83
else if(currLocation == Location.WRITING_OBJ_LITERAL && c == '^') ret = Location.WRITING_LIT_TYPE;
88
currLocation == Location.PRE_SUBJECT ||
89
currLocation == Location.PRE_PRED ||
90
currLocation == Location.PRE_OBJ ||
91
currLocation == Location.POST_OBJ
96
else if(currLocation == Location.POST_OBJ && c == '.') ret = Location.PRE_SUBJECT;
99
else ret = Location.ERROR;
101
currState.location=ret;
105
startState: function() {
107
location : Location.PRE_SUBJECT,
115
token: function(stream, state) {
116
var ch = stream.next();
118
transitState(state, ch);
120
stream.eatWhile( function(c) { if( c != '#' && c != '>' ) { parsedURI += c; return true; } return false;} );
121
state.uris.push(parsedURI);
122
if( stream.match('#', false) ) return 'variable';
124
transitState(state, '>');
128
var parsedAnchor = '';
129
stream.eatWhile(function(c) { if(c != '>' && c != ' ') { parsedAnchor+= c; return true; } return false;});
130
state.anchors.push(parsedAnchor);
134
transitState(state, '>');
138
transitState(state, ch);
139
var parsedBNode = '';
140
stream.eatWhile(function(c) { if( c != ' ' ) { parsedBNode += c; return true; } return false;});
141
state.bnodes.push(parsedBNode);
143
transitState(state, ' ');
147
transitState(state, ch);
148
stream.eatWhile( function(c) { return c != '"'; } );
150
if( stream.peek() != '@' && stream.peek() != '^' ) {
151
transitState(state, '"');
156
transitState(state, '@');
158
stream.eatWhile(function(c) { if( c != ' ' ) { parsedLang += c; return true; } return false;});
159
state.langs.push(parsedLang);
161
transitState(state, ' ');
166
transitState(state, '^');
168
stream.eatWhile(function(c) { if( c != '>' ) { parsedType += c; return true; } return false;} );
169
state.types.push(parsedType);
171
transitState(state, '>');
175
transitState(state, ch);
178
transitState(state, ch);
186
CodeMirror.defineMIME("application/n-triples", "ntriples");
190
CodeMirror.defineMIME("application/n-quads", "ntriples");
193
CodeMirror.defineMIME("text/n-triples", "ntriples");