@@ -5,17 +5,17 @@ import queueMicrotask from 'queue-microtask';
55const { xsd } = namespaces ;
66
77// Regular expression and replacement string to escape N3 strings
8- var escapeSequence = / \\ u ( [ a - f A - F 0 - 9 ] { 4 } ) | \\ U ( [ a - f A - F 0 - 9 ] { 8 } ) | \\ ( [ ^ ] ) / g;
9- var escapeReplacements = {
8+ const escapeSequence = / \\ u ( [ a - f A - F 0 - 9 ] { 4 } ) | \\ U ( [ a - f A - F 0 - 9 ] { 8 } ) | \\ ( [ ^ ] ) / g;
9+ const escapeReplacements = {
1010 '\\' : '\\' , "'" : "'" , '"' : '"' ,
1111 'n' : '\n' , 'r' : '\r' , 't' : '\t' , 'f' : '\f' , 'b' : '\b' ,
1212 '_' : '_' , '~' : '~' , '.' : '.' , '-' : '-' , '!' : '!' , '$' : '$' , '&' : '&' ,
1313 '(' : '(' , ')' : ')' , '*' : '*' , '+' : '+' , ',' : ',' , ';' : ';' , '=' : '=' ,
1414 '/' : '/' , '?' : '?' , '#' : '#' , '@' : '@' , '%' : '%' ,
1515} ;
16- var illegalIriChars = / [ \x00 - \x20 < > \\ " \{ \} \| \^ \` ] / ;
16+ const illegalIriChars = / [ \x00 - \x20 < > \\ " \{ \} \| \^ \` ] / ;
1717
18- var lineModeRegExps = {
18+ const lineModeRegExps = {
1919 _iri : true ,
2020 _unescapedIri : true ,
2121 _simpleQuotedString : true ,
@@ -26,7 +26,7 @@ var lineModeRegExps = {
2626 _whitespace : true ,
2727 _endOfFile : true ,
2828} ;
29- var invalidRegExp = / $ 0 ^ / ;
29+ const invalidRegExp = / $ 0 ^ / ;
3030
3131// ## Constructor
3232export default class N3Lexer {
@@ -57,7 +57,7 @@ export default class N3Lexer {
5757 if ( this . _lineMode = ! ! options . lineMode ) {
5858 this . _n3Mode = false ;
5959 // Don't tokenize special literals
60- for ( var key in this ) {
60+ for ( const key in this ) {
6161 if ( ! ( key in lineModeRegExps ) && this [ key ] instanceof RegExp )
6262 this [ key ] = invalidRegExp ;
6363 }
@@ -77,10 +77,11 @@ export default class N3Lexer {
7777 // ### `_tokenizeToEnd` tokenizes as for as possible, emitting tokens through the callback
7878 _tokenizeToEnd ( callback , inputFinished ) {
7979 // Continue parsing as far as possible; the loop will return eventually
80- var input = this . _input , outputComments = this . _comments ;
80+ let input = this . _input ;
81+ const outputComments = this . _comments ;
8182 while ( true ) {
8283 // Count and skip whitespace lines
83- var whiteSpaceMatch , comment ;
84+ let whiteSpaceMatch , comment ;
8485 while ( whiteSpaceMatch = this . _newline . exec ( input ) ) {
8586 // Try to find a comment
8687 if ( outputComments && ( comment = this . _comment . exec ( whiteSpaceMatch [ 0 ] ) ) )
@@ -106,8 +107,9 @@ export default class N3Lexer {
106107 }
107108
108109 // Look for specific token types based on the first character
109- var line = this . _line , type = '' , value = '' , prefix = '' ,
110- firstChar = input [ 0 ] , match = null , matchLength = 0 , inconclusive = false ;
110+ const line = this . _line , firstChar = input [ 0 ] ;
111+ let type = '' , value = '' , prefix = '' ,
112+ match = null , matchLength = 0 , inconclusive = false ;
111113 switch ( firstChar ) {
112114 case '^' :
113115 // We need at least 3 tokens lookahead to distinguish ^^<IRI> and ^^pre:fixed
@@ -343,7 +345,7 @@ export default class N3Lexer {
343345 }
344346
345347 // Emit the parsed token
346- var token = { line : line , type : type , value : value , prefix : prefix } ;
348+ const token = { line : line , type : type , value : value , prefix : prefix } ;
347349 callback ( null , token ) ;
348350 this . previousToken = token ;
349351 this . _previousMarker = type ;
@@ -418,7 +420,7 @@ export default class N3Lexer {
418420 // ### `_syntaxError` creates a syntax error for the given issue
419421 _syntaxError ( issue ) {
420422 this . _input = null ;
421- var err = new Error ( 'Unexpected "' + issue + '" on line ' + this . _line + '.' ) ;
423+ const err = new Error ( 'Unexpected "' + issue + '" on line ' + this . _line + '.' ) ;
422424 err . context = {
423425 token : undefined ,
424426 line : this . _line ,
@@ -442,8 +444,9 @@ export default class N3Lexer {
442444 queueMicrotask ( ( ) => this . _tokenizeToEnd ( callback , true ) ) ;
443445 // If no callback was passed, tokenize synchronously and return
444446 else {
445- var tokens = [ ] , error ;
446- this . _tokenizeToEnd ( ( e , t ) => { e ? ( error = e ) : tokens . push ( t ) ; } , true ) ;
447+ const tokens = [ ] ;
448+ let error ;
449+ this . _tokenizeToEnd ( ( e , t ) => e ? ( error = e ) : tokens . push ( t ) , true ) ;
447450 if ( error ) throw error ;
448451 return tokens ;
449452 }
0 commit comments