Skip to content

Commit a191cd2

Browse files
committed
Harmonize period usage in comments.
Only end titles and successive sentences with a period.
1 parent 878c014 commit a191cd2

File tree

7 files changed

+166
-176
lines changed

7 files changed

+166
-176
lines changed

lib/N3Lexer.js

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function N3Lexer(options) {
4545

4646
N3Lexer.prototype = {
4747
// ## Regular expressions
48-
// It's slightly faster to have these as properties than as in-scope variables.
48+
// It's slightly faster to have these as properties than as in-scope variables
4949

5050
_iri: /^<((?:[^ <>{}\\]|\\[uU])+)>[ \t]*/, // IRI with escape sequences; needs sanity check after unescaping
5151
_unescapedIri: /^<([^\x00-\x20<>\\"\{\}\|\^\`]*)>[ \t]*/, // IRI without escape sequences; no unescaping
@@ -69,12 +69,12 @@ N3Lexer.prototype = {
6969

7070
// ## Private methods
7171

72-
// ### `_tokenizeToEnd` tokenizes as for as possible, emitting tokens through the callback.
72+
// ### `_tokenizeToEnd` tokenizes as for as possible, emitting tokens through the callback
7373
_tokenizeToEnd: function (callback, inputFinished) {
74-
// Continue parsing as far as possible; the loop will return eventually.
74+
// Continue parsing as far as possible; the loop will return eventually
7575
var input = this._input, outputComments = this._comments;
7676
while (true) {
77-
// Count and skip whitespace lines.
77+
// Count and skip whitespace lines
7878
var whiteSpaceMatch, comment;
7979
while (whiteSpaceMatch = this._newline.exec(input)) {
8080
// Try to find a comment
@@ -84,13 +84,13 @@ N3Lexer.prototype = {
8484
input = input.substr(whiteSpaceMatch[0].length, input.length);
8585
this._line++;
8686
}
87-
// Skip whitespace on current line.
87+
// Skip whitespace on current line
8888
if (whiteSpaceMatch = this._whitespace.exec(input))
8989
input = input.substr(whiteSpaceMatch[0].length, input.length);
9090

91-
// Stop for now if we're at the end.
91+
// Stop for now if we're at the end
9292
if (this._endOfFile.test(input)) {
93-
// If the input is finished, emit EOF.
93+
// If the input is finished, emit EOF
9494
if (inputFinished) {
9595
// Try to find a final comment
9696
if (outputComments && (comment = this._comment.exec(input)))
@@ -100,45 +100,45 @@ N3Lexer.prototype = {
100100
return this._input = input;
101101
}
102102

103-
// Look for specific token types based on the first character.
103+
// Look for specific token types based on the first character
104104
var line = this._line, type = '', value = '', prefix = '',
105105
firstChar = input[0], match = null, matchLength = 0, unescaped, inconclusive = false;
106106
switch (firstChar) {
107107
case '^':
108108
// We need at least 3 tokens lookahead to distinguish ^^<IRI> and ^^pre:fixed
109109
if (input.length < 3)
110110
break;
111-
// Try to match a type.
111+
// Try to match a type
112112
else if (input[1] === '^') {
113113
this._prevTokenType = '^^';
114-
// Move to type IRI or prefixed name.
114+
// Move to type IRI or prefixed name
115115
input = input.substr(2);
116116
if (input[0] !== '<') {
117117
inconclusive = true;
118118
break;
119119
}
120120
}
121-
// If no type, it must be a path expression.
121+
// If no type, it must be a path expression
122122
else {
123123
if (this._n3Mode) {
124124
matchLength = 1;
125125
type = '^';
126126
}
127127
break;
128128
}
129-
// Fall through in case the type is an IRI.
129+
// Fall through in case the type is an IRI
130130
case '<':
131-
// Try to find a full IRI without escape sequences.
131+
// Try to find a full IRI without escape sequences
132132
if (match = this._unescapedIri.exec(input))
133133
type = 'IRI', value = match[1];
134-
// Try to find a full IRI with escape sequences.
134+
// Try to find a full IRI with escape sequences
135135
else if (match = this._iri.exec(input)) {
136136
unescaped = this._unescape(match[1]);
137137
if (unescaped === null || illegalIriChars.test(unescaped))
138138
return reportSyntaxError(this);
139139
type = 'IRI', value = unescaped;
140140
}
141-
// Try to find a backwards implication arrow.
141+
// Try to find a backwards implication arrow
142142
else if (this._n3Mode && input.length > 1 && input[1] === '=')
143143
type = 'inverse', matchLength = 2, value = 'http://www.w3.org/2000/10/swap/log#implies';
144144
break;
@@ -154,20 +154,20 @@ N3Lexer.prototype = {
154154

155155
case '"':
156156
case "'":
157-
// Try to find a non-empty double-quoted literal without escape sequences.
157+
// Try to find a non-empty double-quoted literal without escape sequences
158158
if (match = this._unescapedString.exec(input))
159159
type = 'literal', value = match[0];
160-
// Try to find any other literal wrapped in a pair of single or double quotes.
160+
// Try to find any other literal wrapped in a pair of single or double quotes
161161
else if (match = this._singleQuotedString.exec(input)) {
162162
unescaped = this._unescape(match[0]);
163163
if (unescaped === null)
164164
return reportSyntaxError(this);
165165
type = 'literal', value = unescaped.replace(/^'|'$/g, '"');
166166
}
167-
// Try to find a literal wrapped in three pairs of single or double quotes.
167+
// Try to find a literal wrapped in three pairs of single or double quotes
168168
else if (match = this._tripleQuotedString.exec(input)) {
169169
unescaped = match[1] || match[2];
170-
// Count the newlines and advance line counter.
170+
// Count the newlines and advance line counter
171171
this._line += unescaped.split(/\r\n|\r|\n/).length - 1;
172172
unescaped = this._unescape(unescaped);
173173
if (unescaped === null)
@@ -183,22 +183,22 @@ N3Lexer.prototype = {
183183
break;
184184

185185
case '@':
186-
// Try to find a language code.
186+
// Try to find a language code
187187
if (this._prevTokenType === 'literal' && (match = this._langcode.exec(input)))
188188
type = 'langcode', value = match[1];
189-
// Try to find a keyword.
189+
// Try to find a keyword
190190
else if (match = this._keyword.exec(input))
191191
type = match[0];
192192
break;
193193

194194
case '.':
195-
// Try to find a dot as punctuation.
195+
// Try to find a dot as punctuation
196196
if (input.length === 1 ? inputFinished : (input[1] < '0' || input[1] > '9')) {
197197
type = '.';
198198
matchLength = 1;
199199
break;
200200
}
201-
// Fall through to numerical case (could be a decimal dot).
201+
// Fall through to numerical case (could be a decimal dot)
202202

203203
case '0':
204204
case '1':
@@ -212,7 +212,7 @@ N3Lexer.prototype = {
212212
case '9':
213213
case '+':
214214
case '-':
215-
// Try to find a number.
215+
// Try to find a number
216216
if (match = this._number.exec(input)) {
217217
type = 'literal';
218218
value = '"' + match[0] + '"^^http://www.w3.org/2001/XMLSchema#' +
@@ -226,7 +226,7 @@ N3Lexer.prototype = {
226226
case 'P':
227227
case 'G':
228228
case 'g':
229-
// Try to find a SPARQL-style keyword.
229+
// Try to find a SPARQL-style keyword
230230
if (match = this._sparqlKeyword.exec(input))
231231
type = match[0].toUpperCase();
232232
else
@@ -235,23 +235,23 @@ N3Lexer.prototype = {
235235

236236
case 'f':
237237
case 't':
238-
// Try to match a boolean.
238+
// Try to match a boolean
239239
if (match = this._boolean.exec(input))
240240
type = 'literal', value = '"' + match[0] + '"^^http://www.w3.org/2001/XMLSchema#boolean';
241241
else
242242
inconclusive = true;
243243
break;
244244

245245
case 'a':
246-
// Try to find an abbreviated predicate.
246+
// Try to find an abbreviated predicate
247247
if (match = this._shortPredicates.exec(input))
248248
type = 'abbreviation', value = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
249249
else
250250
inconclusive = true;
251251
break;
252252

253253
case '=':
254-
// Try to find an implication arrow or equals sign.
254+
// Try to find an implication arrow or equals sign
255255
if (this._n3Mode && input.length > 1) {
256256
type = 'abbreviation';
257257
if (input[1] !== '>')
@@ -281,9 +281,9 @@ N3Lexer.prototype = {
281281
inconclusive = true;
282282
}
283283

284-
// Some first characters do not allow an immediate decision, so inspect more.
284+
// Some first characters do not allow an immediate decision, so inspect more
285285
if (inconclusive) {
286-
// Try to find a prefix.
286+
// Try to find a prefix
287287
if ((this._prevTokenType === '@prefix' || this._prevTokenType === 'PREFIX') &&
288288
(match = this._prefix.exec(input)))
289289
type = 'prefix', value = match[1] || '';
@@ -295,7 +295,7 @@ N3Lexer.prototype = {
295295
type = 'prefixed', prefix = match[1] || '', value = this._unescape(match[2]);
296296
}
297297

298-
// A type token is special: it can only be emitted after an IRI or prefixed name is read.
298+
// A type token is special: it can only be emitted after an IRI or prefixed name is read
299299
if (this._prevTokenType === '^^') {
300300
switch (type) {
301301
case 'prefixed': type = 'type'; break;
@@ -315,19 +315,19 @@ N3Lexer.prototype = {
315315
return this._input = input;
316316
}
317317

318-
// Emit the parsed token.
318+
// Emit the parsed token
319319
callback(null, { line: line, type: type, value: value, prefix: prefix });
320320
this._prevTokenType = type;
321321

322-
// Advance to next part to tokenize.
322+
// Advance to next part to tokenize
323323
input = input.substr(matchLength || match[0].length, input.length);
324324
}
325325

326326
// Signals the syntax error through the callback
327327
function reportSyntaxError(self) { callback(self._syntaxError(/^\S*/.exec(input)[0])); }
328328
},
329329

330-
// ### `_unescape` replaces N3 escape codes by their corresponding characters.
330+
// ### `_unescape` replaces N3 escape codes by their corresponding characters
331331
_unescape: function (item) {
332332
try {
333333
return item.replace(escapeSequence, function (sequence, unicode4, unicode8, escapedChar) {
@@ -369,7 +369,7 @@ N3Lexer.prototype = {
369369
var self = this;
370370
this._line = 1;
371371

372-
// If the input is a string, continuously emit tokens through the callback until the end.
372+
// If the input is a string, continuously emit tokens through the callback until the end
373373
if (typeof input === 'string') {
374374
this._input = input;
375375
// If a callback was passed, asynchronously call it
@@ -383,7 +383,7 @@ N3Lexer.prototype = {
383383
return tokens;
384384
}
385385
}
386-
// Otherwise, the input must be a stream.
386+
// Otherwise, the input must be a stream
387387
else {
388388
this._input = '';
389389
if (typeof input.setEncoding === 'function')
@@ -405,6 +405,4 @@ N3Lexer.prototype = {
405405
};
406406

407407
// ## Exports
408-
409-
// Export the `N3Lexer` class as a whole.
410408
module.exports = N3Lexer;

0 commit comments

Comments
 (0)