diff options
author | Valerio Virgillito | 2012-02-15 16:09:47 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-15 16:09:47 -0800 |
commit | d366c0bd1af6471511217ed574083e15059519b5 (patch) | |
tree | c8c9f9af761457e3c5f4c6774fb0fbba851df0c4 /imports/codemirror/mode/ntriples | |
parent | 997ce3fb65f27b3d6f331f63b5dc22d3c7fb8f1e (diff) | |
parent | b85bfb54aaca3ccca3c1ef09115de925cd67f4e9 (diff) | |
download | ninja-d366c0bd1af6471511217ed574083e15059519b5.tar.gz |
Merge branch 'refs/heads/integration'
Diffstat (limited to 'imports/codemirror/mode/ntriples')
-rwxr-xr-x | imports/codemirror/mode/ntriples/index.html | 32 | ||||
-rwxr-xr-x | imports/codemirror/mode/ntriples/ntriples.js | 172 |
2 files changed, 204 insertions, 0 deletions
diff --git a/imports/codemirror/mode/ntriples/index.html b/imports/codemirror/mode/ntriples/index.html new file mode 100755 index 00000000..08d33bab --- /dev/null +++ b/imports/codemirror/mode/ntriples/index.html | |||
@@ -0,0 +1,32 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CodeMirror: NTriples mode</title> | ||
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
6 | <script src="../../lib/codemirror.js"></script> | ||
7 | <script src="ntriples.js"></script> | ||
8 | <link rel="stylesheet" href="../../doc/docs.css"> | ||
9 | <style type="text/css"> | ||
10 | .CodeMirror { | ||
11 | border: 1px solid #eee; | ||
12 | } | ||
13 | </style> | ||
14 | </head> | ||
15 | <body> | ||
16 | <h1>CodeMirror: NTriples mode</h1> | ||
17 | <form> | ||
18 | <textarea id="ntriples" name="ntriples"> | ||
19 | <http://Sub1> <http://pred1> <http://obj> . | ||
20 | <http://Sub2> <http://pred2#an2> "literal 1" . | ||
21 | <http://Sub3#an3> <http://pred3> _:bnode3 . | ||
22 | _:bnode4 <http://pred4> "literal 2"@lang . | ||
23 | _:bnode5 <http://pred5> "literal 3"^^<http://type> . | ||
24 | </textarea> | ||
25 | </form> | ||
26 | |||
27 | <script> | ||
28 | var editor = CodeMirror.fromTextArea(document.getElementById("ntriples"), {}); | ||
29 | </script> | ||
30 | <p><strong>MIME types defined:</strong> <code>text/n-triples</code>.</p> | ||
31 | </body> | ||
32 | </html> | ||
diff --git a/imports/codemirror/mode/ntriples/ntriples.js b/imports/codemirror/mode/ntriples/ntriples.js new file mode 100755 index 00000000..3b6cb416 --- /dev/null +++ b/imports/codemirror/mode/ntriples/ntriples.js | |||
@@ -0,0 +1,172 @@ | |||
1 | /********************************************************** | ||
2 | * This script provides syntax highlighting support for | ||
3 | * the Ntriples format. | ||
4 | * Ntriples format specification: | ||
5 | * http://www.w3.org/TR/rdf-testcases/#ntriples | ||
6 | ***********************************************************/ | ||
7 | |||
8 | /* | ||
9 | The following expression defines the defined ASF grammar transitions. | ||
10 | |||
11 | pre_subject -> | ||
12 | { | ||
13 | ( writing_subject_uri | writing_bnode_uri ) | ||
14 | -> pre_predicate | ||
15 | -> writing_predicate_uri | ||
16 | -> pre_object | ||
17 | -> writing_object_uri | writing_object_bnode | | ||
18 | ( | ||
19 | writing_object_literal | ||
20 | -> writing_literal_lang | writing_literal_type | ||
21 | ) | ||
22 | -> post_object | ||
23 | -> BEGIN | ||
24 | } otherwise { | ||
25 | -> ERROR | ||
26 | } | ||
27 | */ | ||
28 | CodeMirror.defineMode("ntriples", function() { | ||
29 | |||
30 | Location = { | ||
31 | PRE_SUBJECT : 0, | ||
32 | WRITING_SUB_URI : 1, | ||
33 | WRITING_BNODE_URI : 2, | ||
34 | PRE_PRED : 3, | ||
35 | WRITING_PRED_URI : 4, | ||
36 | PRE_OBJ : 5, | ||
37 | WRITING_OBJ_URI : 6, | ||
38 | WRITING_OBJ_BNODE : 7, | ||
39 | WRITING_OBJ_LITERAL : 8, | ||
40 | WRITING_LIT_LANG : 9, | ||
41 | WRITING_LIT_TYPE : 10, | ||
42 | POST_OBJ : 11, | ||
43 | ERROR : 12 | ||
44 | }; | ||
45 | function transitState(currState, c) { | ||
46 | var currLocation = currState.location; | ||
47 | var ret; | ||
48 | |||
49 | // Opening. | ||
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; | ||
56 | |||
57 | // Closing. | ||
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; | ||
66 | |||
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; | ||
70 | |||
71 | // Spaces. | ||
72 | else if( c == ' ' && | ||
73 | ( | ||
74 | currLocation == Location.PRE_SUBJECT || | ||
75 | currLocation == Location.PRE_PRED || | ||
76 | currLocation == Location.PRE_OBJ || | ||
77 | currLocation == Location.POST_OBJ | ||
78 | ) | ||
79 | ) ret = currLocation; | ||
80 | |||
81 | // Reset. | ||
82 | else if(currLocation == Location.POST_OBJ && c == '.') ret = Location.PRE_SUBJECT; | ||
83 | |||
84 | // Error | ||
85 | else ret = Location.ERROR; | ||
86 | |||
87 | currState.location=ret; | ||
88 | } | ||
89 | |||
90 | untilSpace = function(c) { return c != ' '; }; | ||
91 | untilEndURI = function(c) { return c != '>'; }; | ||
92 | return { | ||
93 | startState: function() { | ||
94 | return { | ||
95 | location : Location.PRE_SUBJECT, | ||
96 | uris : [], | ||
97 | anchors : [], | ||
98 | bnodes : [], | ||
99 | langs : [], | ||
100 | types : [] | ||
101 | }; | ||
102 | }, | ||
103 | token: function(stream, state) { | ||
104 | var ch = stream.next(); | ||
105 | if(ch == '<') { | ||
106 | transitState(state, ch); | ||
107 | var parsedURI = ''; | ||
108 | stream.eatWhile( function(c) { if( c != '#' && c != '>' ) { parsedURI += c; return true; } return false;} ); | ||
109 | state.uris.push(parsedURI); | ||
110 | if( stream.match('#', false) ) return 'variable'; | ||
111 | stream.next(); | ||
112 | transitState(state, '>'); | ||
113 | return 'variable'; | ||
114 | } | ||
115 | if(ch == '#') { | ||
116 | var parsedAnchor = ''; | ||
117 | stream.eatWhile(function(c) { if(c != '>' && c != ' ') { parsedAnchor+= c; return true; } return false}); | ||
118 | state.anchors.push(parsedAnchor); | ||
119 | return 'variable-2'; | ||
120 | } | ||
121 | if(ch == '>') { | ||
122 | transitState(state, '>'); | ||
123 | return 'variable'; | ||
124 | } | ||
125 | if(ch == '_') { | ||
126 | transitState(state, ch); | ||
127 | var parsedBNode = ''; | ||
128 | stream.eatWhile(function(c) { if( c != ' ' ) { parsedBNode += c; return true; } return false;}); | ||
129 | state.bnodes.push(parsedBNode); | ||
130 | stream.next(); | ||
131 | transitState(state, ' '); | ||
132 | return 'builtin'; | ||
133 | } | ||
134 | if(ch == '"') { | ||
135 | transitState(state, ch); | ||
136 | stream.eatWhile( function(c) { return c != '"'; } ); | ||
137 | stream.next(); | ||
138 | if( stream.peek() != '@' && stream.peek() != '^' ) { | ||
139 | transitState(state, '"'); | ||
140 | } | ||
141 | return 'string'; | ||
142 | } | ||
143 | if( ch == '@' ) { | ||
144 | transitState(state, '@'); | ||
145 | var parsedLang = ''; | ||
146 | stream.eatWhile(function(c) { if( c != ' ' ) { parsedLang += c; return true; } return false;}); | ||
147 | state.langs.push(parsedLang); | ||
148 | stream.next(); | ||
149 | transitState(state, ' '); | ||
150 | return 'string-2'; | ||
151 | } | ||
152 | if( ch == '^' ) { | ||
153 | stream.next(); | ||
154 | transitState(state, '^'); | ||
155 | var parsedType = ''; | ||
156 | stream.eatWhile(function(c) { if( c != '>' ) { parsedType += c; return true; } return false;} ); | ||
157 | state.types.push(parsedType); | ||
158 | stream.next(); | ||
159 | transitState(state, '>'); | ||
160 | return 'variable'; | ||
161 | } | ||
162 | if( ch == ' ' ) { | ||
163 | transitState(state, ch); | ||
164 | } | ||
165 | if( ch == '.' ) { | ||
166 | transitState(state, ch); | ||
167 | } | ||
168 | } | ||
169 | }; | ||
170 | }); | ||
171 | |||
172 | CodeMirror.defineMIME("text/n-triples", "ntriples"); | ||