@@ -17,31 +17,40 @@ var escapeReplacements = {
1717} ;
1818var illegalIriChars = / [ \x00 - \x20 < > \\ " \{ \} \| \^ \` ] / ;
1919
20+ var lineModeRegExps = {
21+ _iri : true ,
22+ _unescapedIri : true ,
23+ _unescapedQuote : true ,
24+ _singleQuote : true ,
25+ _langcode : true ,
26+ _blank : true ,
27+ _newline : true ,
28+ _comment : true ,
29+ _whitespace : true ,
30+ _endOfFile : true ,
31+ } ;
32+ var invalidRegExp = / $ 0 ^ / ;
33+
2034// ## Constructor
2135function N3Lexer ( options ) {
2236 if ( ! ( this instanceof N3Lexer ) )
2337 return new N3Lexer ( options ) ;
2438 options = options || { } ;
2539
2640 // In line mode (N-Triples or N-Quads), only simple features may be parsed
27- if ( options . lineMode ) {
41+ if ( this . _lineMode = ! ! options . lineMode ) {
42+ this . _n3Mode = false ;
2843 // Don't tokenize special literals
29- this . _tripleApos = this . _tripleQuote = this . _number = this . _boolean = / $ 0 ^ / ;
30- // Swap the tokenize method for a restricted version
31- var self = this ;
32- this . _tokenize = this . tokenize ;
33- this . tokenize = function ( input , callback ) {
34- this . _tokenize ( input , function ( error , token ) {
35- if ( ! error && / ^ (?: I R I | b l a n k | l i t e r a l | l a n g c o d e | t y p e I R I | \. | e o f ) $ / . test ( token . type ) )
36- callback && callback ( error , token ) ;
37- else
38- callback && callback ( error || self . _syntaxError ( token . type , callback = null ) ) ;
39- } ) ;
40- } ;
44+ for ( var key in this ) {
45+ if ( ! ( key in lineModeRegExps ) && this [ key ] instanceof RegExp )
46+ this [ key ] = invalidRegExp ;
47+ }
48+ }
49+ // When not in line mode, enable N3 functionality by default
50+ else {
51+ this . _n3Mode = options . n3 !== false ;
4152 }
42- // Enable N3 functionality by default
43- this . _n3Mode = options . n3 !== false ;
44- // Disable comment tokens by default
53+ // Don't output comment tokens by default
4554 this . _comments = ! ! options . comments ;
4655}
4756
@@ -302,9 +311,10 @@ N3Lexer.prototype = {
302311 case ')' :
303312 case '{' :
304313 case '}' :
305- // The next token is punctuation
306- matchLength = 1 ;
307- type = firstChar ;
314+ if ( ! this . _lineMode ) {
315+ matchLength = 1 ;
316+ type = firstChar ;
317+ }
308318 break ;
309319
310320 default :
0 commit comments