@@ -41,9 +41,10 @@ function lex (argument) {
41
41
}
42
42
// Iterate through the argument string, buffering
43
43
// non-space characters and building tokens.
44
+ var characterBuffer
45
+ var startedBuffering
46
+ resetBuffer ( )
44
47
var tokens = [ ]
45
- var characterBuffer = ''
46
- var startedBuffering = null
47
48
var length = argument . length
48
49
for ( var offset = 0 ; offset < length ; offset ++ ) {
49
50
var character = argument [ offset ]
@@ -74,6 +75,11 @@ function lex (argument) {
74
75
} )
75
76
return tokens
76
77
78
+ function resetBuffer ( ) {
79
+ characterBuffer = ''
80
+ startedBuffering = null
81
+ }
82
+
77
83
function pushBuffered ( ) {
78
84
if ( characterBuffer ) {
79
85
// Create a token for the buffered characters.
@@ -83,9 +89,7 @@ function lex (argument) {
83
89
start : startedBuffering ,
84
90
end : startedBuffering + characterBuffer . length
85
91
} )
86
- // Reset the buffer.
87
- characterBuffer = ''
88
- startedBuffering = null
92
+ resetBuffer ( )
89
93
}
90
94
}
91
95
}
@@ -94,11 +98,11 @@ function tokenTypeForString (string, start) {
94
98
if ( ids . indexOf ( string ) !== - 1 ) {
95
99
return 'LICENSE'
96
100
} else if ( string === 'AND' ) {
97
- return string
101
+ return 'AND'
98
102
} else if ( string === 'OR' ) {
99
- return string
103
+ return 'OR'
100
104
} else if ( string === 'WITH' ) {
101
- return string
105
+ return 'WITH'
102
106
} else if ( exceptions . indexOf ( string ) !== - 1 ) {
103
107
return 'EXCEPTION'
104
108
} else if ( LICENSEREF . test ( string ) ) {
@@ -109,10 +113,10 @@ function tokenTypeForString (string, start) {
109
113
return 'OPEN'
110
114
} else if ( string === ')' ) {
111
115
return 'CLOSE'
112
- } else if ( string === ':' ) {
113
- return 'COLON'
114
116
} else if ( string === '+' ) {
115
117
return 'PLUS'
118
+ } else if ( string === ':' ) {
119
+ return 'COLON'
116
120
} else {
117
121
throw new Error ( 'Invalid input at offset ' + start )
118
122
}
0 commit comments