@@ -2,35 +2,24 @@ const utils = require('../utils')
2
2
const { hedStringIsAGroup, removeGroupParentheses } = require ( '../utils/hed' )
3
3
const { generateIssue } = require ( '../common/issues/issues' )
4
4
5
- const {
6
- ParsedHedTag,
7
- ParsedHed2Tag,
8
- ParsedHed3Tag,
9
- ParsedHedGroup,
10
- ParsedHedString,
11
- } = require ( './types/parsedHed' )
5
+ const { ParsedHedTag, ParsedHed2Tag, ParsedHed3Tag, ParsedHedGroup, ParsedHedString } = require ( './types/parsedHed' )
12
6
13
7
const openingGroupCharacter = '('
14
8
const closingGroupCharacter = ')'
15
9
const delimiters = new Set ( [ ',' ] )
16
10
17
11
/**
18
- * Split a full HED string into tags.
12
+ * Split a HED string into tags.
19
13
*
20
- * @param {string } hedString The full HED string.
14
+ * @param {string } hedString The HED string to be split .
21
15
* @param {Schemas } hedSchemas The collection of HED schemas.
22
- * @param {int } groupStartingIndex The start index of the group in the full HED string.
23
- * @returns {[ParsedHedTag[], object <string, Issue[]>] } An array of HED tags (top-level relative to the passed string) and any issues found.
16
+ * @param {int } groupStartingIndex The start index of the containing group in the full HED string.
17
+ * @returns {[ParsedHedTag[], Object <string, Issue[]>] } An array of HED tags (top-level relative to the passed string) and any issues found.
24
18
*/
25
- const splitHedString = function (
26
- hedString ,
27
- hedSchemas ,
28
- groupStartingIndex = 0 ,
29
- ) {
30
- const doubleQuoteCharacter = '"'
19
+ const splitHedString = function ( hedString , hedSchemas , groupStartingIndex = 0 ) {
31
20
const colonCharacter = ':'
32
21
const slashCharacter = '/'
33
- const invalidCharacters = [ '{' , '}' , '[' , ']' , '~' ]
22
+ const invalidCharacters = [ '{' , '}' , '[' , ']' , '~' , '"' ]
34
23
35
24
const hedTags = [ ]
36
25
const conversionIssues = [ ]
@@ -89,10 +78,7 @@ const splitHedString = function (
89
78
resetStartingIndex = false
90
79
}
91
80
const character = hedString . charAt ( i )
92
- if ( character === doubleQuoteCharacter ) {
93
- // Skip double quotes
94
- continue
95
- } else if ( character === openingGroupCharacter ) {
81
+ if ( character === openingGroupCharacter ) {
96
82
// Count group characters
97
83
groupDepth ++
98
84
} else if ( character === closingGroupCharacter ) {
@@ -141,14 +127,9 @@ const splitHedString = function (
141
127
* @param {Schemas } hedSchemas The collection of HED schemas.
142
128
* @param {ParsedHedString } parsedString The object to store parsed output in.
143
129
* @param {boolean } isTopLevel Whether these tag groups are at the top level.
144
- * @return {object <string, Issue[]>[] } The array of issues.
130
+ * @return {Object <string, Issue[]>[] } The array of issues.
145
131
*/
146
- const findTagGroups = function (
147
- groupTagsList ,
148
- hedSchemas ,
149
- parsedString ,
150
- isTopLevel ,
151
- ) {
132
+ const findTagGroups = function ( groupTagsList , hedSchemas , parsedString , isTopLevel ) {
152
133
const issues = [ ]
153
134
const copiedGroupTagsList = groupTagsList . slice ( )
154
135
copiedGroupTagsList . forEach ( ( tagOrGroup , index ) => {
@@ -160,12 +141,7 @@ const findTagGroups = function (
160
141
hedSchemas ,
161
142
tagOrGroup . originalBounds [ 0 ] + 1 ,
162
143
)
163
- const nestedIssues = findTagGroups (
164
- nestedGroupTagList ,
165
- hedSchemas ,
166
- parsedString ,
167
- false ,
168
- )
144
+ const nestedIssues = findTagGroups ( nestedGroupTagList , hedSchemas , parsedString , false )
169
145
groupTagsList [ index ] = new ParsedHedGroup (
170
146
tagOrGroup . originalTag ,
171
147
nestedGroupTagList ,
@@ -246,14 +222,8 @@ const substituteCharacters = function (hedString) {
246
222
*/
247
223
const countTagGroupParentheses = function ( hedString ) {
248
224
const issues = [ ]
249
- const numberOfOpeningParentheses = utils . string . getCharacterCount (
250
- hedString ,
251
- openingGroupCharacter ,
252
- )
253
- const numberOfClosingParentheses = utils . string . getCharacterCount (
254
- hedString ,
255
- closingGroupCharacter ,
256
- )
225
+ const numberOfOpeningParentheses = utils . string . getCharacterCount ( hedString , openingGroupCharacter )
226
+ const numberOfClosingParentheses = utils . string . getCharacterCount ( hedString , closingGroupCharacter )
257
227
if ( numberOfOpeningParentheses !== numberOfClosingParentheses ) {
258
228
issues . push (
259
229
generateIssue ( 'parentheses' , {
@@ -268,16 +238,10 @@ const countTagGroupParentheses = function (hedString) {
268
238
/**
269
239
* Check if a comma is missing after an opening parenthesis.
270
240
*/
271
- const isCommaMissingAfterClosingParenthesis = function (
272
- lastNonEmptyCharacter ,
273
- currentCharacter ,
274
- ) {
241
+ const isCommaMissingAfterClosingParenthesis = function ( lastNonEmptyCharacter , currentCharacter ) {
275
242
return (
276
243
lastNonEmptyCharacter === closingGroupCharacter &&
277
- ! (
278
- delimiters . has ( currentCharacter ) ||
279
- currentCharacter === closingGroupCharacter
280
- )
244
+ ! ( delimiters . has ( currentCharacter ) || currentCharacter === closingGroupCharacter )
281
245
)
282
246
}
283
247
@@ -314,12 +278,7 @@ const findDelimiterIssuesInHedString = function (hedString) {
314
278
} else {
315
279
issues . push ( generateIssue ( 'invalidTag' , { tag : currentTag } ) )
316
280
}
317
- } else if (
318
- isCommaMissingAfterClosingParenthesis (
319
- lastNonEmptyValidCharacter ,
320
- currentCharacter ,
321
- )
322
- ) {
281
+ } else if ( isCommaMissingAfterClosingParenthesis ( lastNonEmptyValidCharacter , currentCharacter ) ) {
323
282
issues . push (
324
283
generateIssue ( 'commaMissing' , {
325
284
tag : currentTag . slice ( 0 , - 1 ) ,
@@ -346,7 +305,7 @@ const findDelimiterIssuesInHedString = function (hedString) {
346
305
* Validate the full unparsed HED string.
347
306
*
348
307
* @param {string } hedString The unparsed HED string.
349
- * @return {object <string, Issue[]> } String substitution issues and other issues.
308
+ * @return {Object <string, Issue[]> } String substitution issues and other issues.
350
309
*/
351
310
const validateFullUnparsedHedString = function ( hedString ) {
352
311
const [ fixedHedString , substitutionIssues ] = substituteCharacters ( hedString )
@@ -364,38 +323,27 @@ const validateFullUnparsedHedString = function (hedString) {
364
323
const mergeParsingIssues = function ( previousIssues , currentIssues ) {
365
324
for ( const key of Object . keys ( currentIssues ) ) {
366
325
previousIssues [ key ] =
367
- previousIssues [ key ] !== undefined
368
- ? previousIssues [ key ] . concat ( currentIssues [ key ] )
369
- : currentIssues [ key ]
326
+ previousIssues [ key ] !== undefined ? previousIssues [ key ] . concat ( currentIssues [ key ] ) : currentIssues [ key ]
370
327
}
371
328
}
372
329
373
330
/**
374
- * Parse a full HED string into a object of tag types.
331
+ * Parse a full HED string into an object of tag types.
375
332
*
376
333
* @param {string } hedString The full HED string to parse.
377
334
* @param {Schemas } hedSchemas The collection of HED schemas.
378
- * @returns {[ParsedHedString|null, object <string, Issue[]>] } The parsed HED tag data and an object containing lists of parsing issues.
335
+ * @returns {[ParsedHedString|null, Object <string, Issue[]>] } The parsed HED tag data and an object containing lists of parsing issues.
379
336
*/
380
337
const parseHedString = function ( hedString , hedSchemas ) {
381
338
const fullStringIssues = validateFullUnparsedHedString ( hedString )
382
339
if ( fullStringIssues . delimiter . length > 0 ) {
383
340
fullStringIssues . syntax = [ ]
384
341
return [ null , fullStringIssues ]
385
342
}
386
- const parsedString = new ParsedHedString ( hedString )
387
343
const [ hedTagList , splitIssues ] = splitHedString ( hedString , hedSchemas )
388
- parsedString . topLevelTags = findTopLevelTags (
389
- hedTagList ,
390
- hedSchemas ,
391
- parsedString ,
392
- )
393
- const tagGroupIssues = findTagGroups (
394
- hedTagList ,
395
- hedSchemas ,
396
- parsedString ,
397
- true ,
398
- )
344
+ const parsedString = new ParsedHedString ( hedString )
345
+ parsedString . topLevelTags = findTopLevelTags ( hedTagList , hedSchemas , parsedString )
346
+ const tagGroupIssues = findTagGroups ( hedTagList , hedSchemas , parsedString , true )
399
347
const parsingIssues = Object . assign ( fullStringIssues , splitIssues )
400
348
for ( const tagGroup of tagGroupIssues ) {
401
349
mergeParsingIssues ( parsingIssues , tagGroup )
@@ -408,7 +356,7 @@ const parseHedString = function (hedString, hedSchemas) {
408
356
*
409
357
* @param {string[] } hedStrings A set of HED strings.
410
358
* @param {Schemas } hedSchemas The collection of HED schemas.
411
- * @return {[ParsedHedString[], object <string, Issue[]>] } The parsed HED strings and any issues found.
359
+ * @return {[ParsedHedString[], Object <string, Issue[]>] } The parsed HED strings and any issues found.
412
360
*/
413
361
const parseHedStrings = function ( hedStrings , hedSchemas ) {
414
362
return hedStrings
0 commit comments