@@ -345,162 +345,164 @@ for(let i = 0; i < 26; i++)
345
345
description = descRaw . map ( el => el . textContent . trim ( ) ) . join ( "\n" ) . replace ( '``' , '' ) ;
346
346
}
347
347
348
- const syntaxLine = token . querySelector ( 'tbody p.SyntaxLine' ) ;
349
-
350
- let wholeSyntaxLine = ( syntaxLine ?. textContent ?? '' ) . replace ( ',[,' , '[,' ) . replace ( / + / g, ' ' ) . replace ( / + / g, ' ' ) . trim ( ) ;
351
- if ( comment ) {
352
- if ( / ^ \( .* \) $ / . test ( comment ) ) {
353
- wholeSyntaxLine = wholeSyntaxLine . replace ( new RegExp ( escapeRegExp ( comment ) + '$' ) , '' ) ; // remove potential comment at the end
354
- comment = comment . substring ( 1 , comment . length - 1 ) ;
355
- } else if ( wholeSyntaxLine . endsWith ( comment ) ) {
356
- comment = undefined ;
348
+ const syntaxLines = token . querySelectorAll ( 'tbody p.SyntaxLine' ) ;
349
+ for ( const syntaxLine of syntaxLines )
350
+ {
351
+ let wholeSyntaxLine = ( syntaxLine ?. textContent ?? '' ) . replace ( ',[,' , '[,' ) . replace ( / + / g, ' ' ) . replace ( / + / g, ' ' ) . trim ( ) ;
352
+ if ( comment ) {
353
+ if ( / ^ \( .* \) $ / . test ( comment ) ) {
354
+ wholeSyntaxLine = wholeSyntaxLine . replace ( new RegExp ( escapeRegExp ( comment ) + '$' ) , '' ) ; // remove potential comment at the end
355
+ comment = comment . substring ( 1 , comment . length - 1 ) ;
356
+ } else if ( wholeSyntaxLine . endsWith ( comment ) ) {
357
+ comment = undefined ;
358
+ }
357
359
}
358
- }
359
360
360
- let optionalSinceIdx = ( wholeSyntaxLine . startsWith ( `${ name } [` ) || wholeSyntaxLine . startsWith ( `${ name . trim ( ) } [` ) ) ? 0 : null ;
361
- let _argIdx = 0 ;
362
- let args = [ ...syntaxLine . childNodes ]
363
- . filter ( el => el . nodeType !== 8 /*COMMENT_NODE*/ && el . textContent !== '→' && el . textContent . trim ( ) . length &&
364
- ( ! el . classList ?. contains ( 'Function' ) || el . textContent === ',' || el . getAttribute ( "style" ) ?. includes ( 'font-weight: normal' ) ) )
365
- . filter ( ( el , idx ) => {
366
- const str = el . textContent . trim ( ) ;
367
- if ( str === '►' ) { return false ; }
368
- const strOrFirstPart = str . split ( ' ' ) [ 0 ] ;
369
- return ( idx > 0 ) || ( strOrFirstPart !== name . trim ( ) && ( strOrFirstPart + '(' ) !== name . trim ( ) ) ;
370
- } )
371
- . map ( ( el , idx , arr ) => {
372
- const argStr = el . textContent . trim ( ) . replace ( ',[,' , '[,' ) ;
373
- if ( optionalSinceIdx === null && / ^ \[ , ? $ / . test ( argStr ) ) {
374
- optionalSinceIdx = _argIdx
375
- if ( optionalSinceIdx === 0 && name . endsWith ( '(' ) ) {
376
- optionalSinceIdx = 1 ;
361
+ let optionalSinceIdx = ( wholeSyntaxLine . startsWith ( `${ name } [` ) || wholeSyntaxLine . startsWith ( `${ name . trim ( ) } [` ) ) ? 0 : null ;
362
+ let _argIdx = 0 ;
363
+ let args = [ ...syntaxLine . childNodes ]
364
+ . filter ( el => el . nodeType !== 8 /*COMMENT_NODE*/ && el . textContent !== '→' && el . textContent . trim ( ) . length &&
365
+ ( ! el . classList ?. contains ( 'Function' ) || el . textContent === ',' || el . getAttribute ( "style" ) ?. includes ( 'font-weight: normal' ) ) )
366
+ . filter ( ( el , idx ) => {
367
+ const str = el . textContent . trim ( ) ;
368
+ if ( str === '►' ) { return false ; }
369
+ const strOrFirstPart = str . split ( ' ' ) [ 0 ] ;
370
+ return ( idx > 0 ) || ( strOrFirstPart !== name . trim ( ) && ( strOrFirstPart + '(' ) !== name . trim ( ) ) ;
371
+ } )
372
+ . map ( ( el , idx , arr ) => {
373
+ const argStr = el . textContent . trim ( ) . replace ( ',[,' , '[,' ) ;
374
+ if ( optionalSinceIdx === null && / ^ \[ , ? $ / . test ( argStr ) ) {
375
+ optionalSinceIdx = _argIdx
376
+ if ( optionalSinceIdx === 0 && name . endsWith ( '(' ) ) {
377
+ optionalSinceIdx = 1 ;
378
+ }
379
+ // console.log(` optional args start now => ${optionalSinceIdx} ; ${wholeSyntaxLine}`)
377
380
}
378
- // console.log(` optional args start now => ${optionalSinceIdx} ; ${wholeSyntaxLine}`)
379
- }
380
- if ( el . textContent === ',' || el . classList ?. contains ( 'Variable' ) ) {
381
- _argIdx += 1 + ( argStr . replace ( / ( ^ , | , $ ) / g, '' ) . match ( / , / g) || [ ] ) . length
381
+ if ( el . textContent === ',' || el . classList ?. contains ( 'Variable' ) ) {
382
+ _argIdx += 1 + ( argStr . replace ( / ( ^ , | , $ ) / g, '' ) . match ( / , / g) || [ ] ) . length
383
+ }
384
+ return argStr ;
385
+ } )
386
+ . filter ( el => el && el . textContent !== ',' )
387
+ . map ( ( el ) => [ el . replace ( / ( ^ , * | [ \[ \] \( \) ] | , * $ ) / g, '' ) , '' , false ] )
388
+ . map ( ( el , idx , arr ) => [ el [ 0 ] , '' , optionalSinceIdx !== null && idx >= optionalSinceIdx ] )
389
+ . filter ( n => n && n [ 0 ] . length && ! / ^ [ \[ \] \( \) ] $ / . test ( n [ 0 ] ) ) ;
390
+
391
+ {
392
+ let newArgs = [ ] ;
393
+ for ( const [ idx , [ argName , argType , isOptional ] ] of Object . entries ( args ) ) {
394
+ if ( argName . includes ( ',' ) ) {
395
+ // console.warn(` arg ${idx} wasn't split correctly: "${argName}". args was: ${JSON.stringify(args)}`);
396
+ for ( const [ idx2 , arg ] of Object . entries ( argName . split ( ',' ) ) ) {
397
+ newArgs . push ( [ arg . replace ( / ^ \( / , '' ) . trim ( ) , argType , isOptional ] )
382
398
}
383
- return argStr ;
384
- } )
385
- . filter ( el => el && el . textContent !== ',' )
386
- . map ( ( el ) => [ el . replace ( / ( ^ , * | [ \[ \] \( \) ] | , * $ ) / g, '' ) , '' , false ] )
387
- . map ( ( el , idx , arr ) => [ el [ 0 ] , '' , optionalSinceIdx !== null && idx >= optionalSinceIdx ] )
388
- . filter ( n => n && n [ 0 ] . length && ! / ^ [ \[ \] \( \) ] $ / . test ( n [ 0 ] ) ) ;
389
-
390
- {
391
- let newArgs = [ ] ;
392
- for ( const [ idx , [ argName , argType , isOptional ] ] of Object . entries ( args ) ) {
393
- if ( argName . includes ( ',' ) ) {
394
- // console.warn(` arg ${idx} wasn't split correctly: "${argName}". args was: ${JSON.stringify(args)}`);
395
- for ( const [ idx2 , arg ] of Object . entries ( argName . split ( ',' ) ) ) {
396
- newArgs . push ( [ arg . replace ( / ^ \( / , '' ) . trim ( ) , argType , isOptional ] )
399
+ } else {
400
+ newArgs . push ( [ argName , argType , isOptional ] ) ;
397
401
}
398
- } else {
399
- newArgs . push ( [ argName , argType , isOptional ] ) ;
400
402
}
403
+ args = newArgs ;
401
404
}
402
- args = newArgs ;
403
- }
404
405
405
- // args misc. cleanup and type determination...
406
- args = args . filter ( el => el && el [ 0 ] . length ) ;
407
- for ( const [ idx , [ argName ] ] of Object . entries ( args ) ) {
408
- if ( argName === "Plot#type" ) {
409
- wholeSyntaxLine = wholeSyntaxLine . replace ( new RegExp ( '^' + escapeRegExp ( name ) ) , '' ) . trim ( ) ;
410
- args [ idx ] = [ 'type' , `${ name } token` , false ] ;
411
- }
412
- if ( / ^ l i s t n a m e \d / i. test ( argName ) ) {
413
- args [ idx ] [ 1 ] = 'listName'
414
- } else if ( argName . includes ( 'list' ) ) {
415
- args [ idx ] [ 1 ] = 'list'
416
- } else if ( argName . includes ( 'matrix' ) ) {
417
- args [ idx ] [ 1 ] = 'matrix'
418
- } else if ( argName . endsWith ( 'string' ) || argName . startsWith ( 'text' ) ) {
419
- args [ idx ] [ 1 ] = 'string'
420
- } else if ( argName === 'color#' ) {
421
- args [ idx ] [ 1 ] = 'colorNum'
422
- } else if ( / ^ ( l e n g t h | r o w s | c o l u m n s | l i n e s t y l e # ) $ / . test ( argName ) ) {
423
- args [ idx ] [ 1 ] = 'integer'
424
- } else if ( argName === 'expression' ) {
425
- args [ idx ] [ 1 ] = 'expression'
426
- } else if ( argName === 'complex value' ) {
427
- args [ idx ] [ 1 ] = 'complex'
428
- }
406
+ // args misc. cleanup and type determination...
407
+ args = args . filter ( el => el && el [ 0 ] . length ) ;
408
+ for ( const [ idx , [ argName ] ] of Object . entries ( args ) ) {
409
+ if ( argName === "Plot#type" ) {
410
+ wholeSyntaxLine = wholeSyntaxLine . replace ( new RegExp ( '^' + escapeRegExp ( name ) ) , '' ) . trim ( ) ;
411
+ args [ idx ] = [ 'type' , `${ name } token` , false ] ;
412
+ }
413
+ if ( / ^ l i s t n a m e \d / i. test ( argName ) ) {
414
+ args [ idx ] [ 1 ] = 'listName'
415
+ } else if ( argName . includes ( 'list' ) ) {
416
+ args [ idx ] [ 1 ] = 'list'
417
+ } else if ( argName . includes ( 'matrix' ) ) {
418
+ args [ idx ] [ 1 ] = 'matrix'
419
+ } else if ( argName . endsWith ( 'string' ) || argName . startsWith ( 'text' ) ) {
420
+ args [ idx ] [ 1 ] = 'string'
421
+ } else if ( argName === 'color#' ) {
422
+ args [ idx ] [ 1 ] = 'colorNum'
423
+ } else if ( / ^ ( l e n g t h | r o w s | c o l u m n s | l i n e s t y l e # ) $ / . test ( argName ) ) {
424
+ args [ idx ] [ 1 ] = 'integer'
425
+ } else if ( argName === 'expression' ) {
426
+ args [ idx ] [ 1 ] = 'expression'
427
+ } else if ( argName === 'complex value' ) {
428
+ args [ idx ] [ 1 ] = 'complex'
429
+ }
429
430
430
- // some overrides...
431
- if ( description . includes ( '`valueA` and `valueB`, which can be real numbers or lists' ) // gcd/lcm, expressions work fine
432
- || description . includes ( '`valueA` and `valueB` can be real numbers, expressions, or lists' ) ) {
433
- args [ idx ] [ 1 ] = 'real|expression|real[]'
434
- } else if ( description . includes ( 'of a real number, expression, or list' ) ) {
435
- args [ idx ] [ 1 ] = 'real|expression|real[]'
436
- } else if ( description . includes ( 'of a real number, expression, list, or matrix' ) ) {
437
- args [ idx ] [ 1 ] = 'real|expression|real[]|matrix'
438
- } else if ( description . includes ( 'of a complex number or list' ) ) {
439
- args [ idx ] [ 1 ] = 'complex|complex[]'
431
+ // some overrides...
432
+ if ( description . includes ( '`valueA` and `valueB`, which can be real numbers or lists' ) // gcd/lcm, expressions work fine
433
+ || description . includes ( '`valueA` and `valueB` can be real numbers, expressions, or lists' ) ) {
434
+ args [ idx ] [ 1 ] = 'real|expression|real[]'
435
+ } else if ( description . includes ( 'of a real number, expression, or list' ) ) {
436
+ args [ idx ] [ 1 ] = 'real|expression|real[]'
437
+ } else if ( description . includes ( 'of a real number, expression, list, or matrix' ) ) {
438
+ args [ idx ] [ 1 ] = 'real|expression|real[]|matrix'
439
+ } else if ( description . includes ( 'of a complex number or list' ) ) {
440
+ args [ idx ] [ 1 ] = 'complex|complex[]'
441
+ }
442
+ //console.log(idx, argName, arguments[idx][1])
440
443
}
441
- //console.log(idx, argName, arguments[idx][1])
442
- }
443
444
444
- // remove last arg if it's just a comment that got there somehow (not an actual arg)
445
- if ( comment && args . length && new RegExp ( '^\\(?' + comment + '$' ) . test ( args [ args . length - 1 ] [ 0 ] ) ) {
446
- args . pop ( ) ;
447
- }
445
+ // remove last arg if it's just a comment that got there somehow (not an actual arg)
446
+ if ( comment && args . length && new RegExp ( '^\\(?' + comment + '$' ) . test ( args [ args . length - 1 ] [ 0 ] ) ) {
447
+ args . pop ( ) ;
448
+ }
448
449
449
- const rawLocation = token . querySelector ( 'tbody p.MenuName > span' ) ?. parentElement ;
450
- const location = [ ...( rawLocation ?. children ?? [ ] ) ]
451
- . map ( el => el . textContent . trim ( ) )
452
- . filter ( el => el )
453
- . map ( el => menuReplacements [ el ] ?? el ) ;
454
- if ( location . length >= 2 ) {
455
- if ( name . includes ( '►' ) ) {
456
- const [ part1 , part2 ] = name . split ( '►' ) ;
457
- if ( location [ location . length - 1 ] === part2 && ( new RegExp ( '^([A-Z\d]:)?' + escapeRegExp ( part1 ) + '$' ) . test ( location [ location . length - 2 ] ) ) ) {
458
- location [ location . length - 2 ] += '►' + location . pop ( ) ;
450
+ const rawLocation = token . querySelector ( 'tbody p.MenuName > span' ) ?. parentElement ;
451
+ const location = [ ...( rawLocation ?. children ?? [ ] ) ]
452
+ . map ( el => el . textContent . trim ( ) )
453
+ . filter ( el => el )
454
+ . map ( el => menuReplacements [ el ] ?? el ) ;
455
+ if ( location . length >= 2 ) {
456
+ if ( name . includes ( '►' ) ) {
457
+ const [ part1 , part2 ] = name . split ( '►' ) ;
458
+ if ( location [ location . length - 1 ] === part2 && ( new RegExp ( '^([A-Z\d]:)?' + escapeRegExp ( part1 ) + '$' ) . test ( location [ location . length - 2 ] ) ) ) {
459
+ location [ location . length - 2 ] += '►' + location . pop ( ) ;
460
+ }
461
+ }
462
+ if ( / ^ [ A - Z \d ] : $ / . test ( location [ location . length - 2 ] ) ) {
463
+ location [ location . length - 2 ] += location . pop ( ) ;
459
464
}
460
465
}
461
- if ( / ^ [ A - Z \d ] : $ / . test ( location [ location . length - 2 ] ) ) {
462
- location [ location . length - 2 ] += location . pop ( ) ;
463
- }
464
- }
465
466
466
- let specificName = undefined ;
467
- if ( ! bytes ) {
468
- bytes = {
469
- 'If Then End' : name2bytes [ 'If ' ] ,
470
- 'If Then Else End' : name2bytes [ 'If ' ] ,
471
- } [ name ] ;
472
- specificName = name ;
467
+ let specificName = undefined ;
473
468
if ( ! bytes ) {
474
- throw `bytes not defined for token name: [${ name } ]` ;
469
+ bytes = {
470
+ 'If Then End' : name2bytes [ 'If ' ] ,
471
+ 'If Then Else End' : name2bytes [ 'If ' ] ,
472
+ } [ name ] ;
473
+ specificName = name ;
474
+ if ( ! bytes ) {
475
+ throw `bytes not defined for token name: [${ name } ]` ;
476
+ }
475
477
}
476
- }
477
478
478
- if ( tkXML [ bytes ] ) {
479
- const lastTkData = tkXML [ bytes ] [ tkXML [ bytes ] . length - 1 ] ;
480
- if ( lastTkData . enAccessible && tokenEntry . name !== lastTkData . enAccessible ) {
481
- tokenEntry . accessibleName = lastTkData . enAccessible ;
479
+ if ( tkXML [ bytes ] ) {
480
+ const lastTkData = tkXML [ bytes ] [ tkXML [ bytes ] . length - 1 ] ;
481
+ if ( lastTkData . enAccessible && tokenEntry . name !== lastTkData . enAccessible ) {
482
+ tokenEntry . accessibleName = lastTkData . enAccessible ;
483
+ }
484
+ if ( lastTkData . enVariants ) {
485
+ tokenEntry . nameVariants = lastTkData . enVariants ;
486
+ }
487
+ mergeSinceUntilFromTkXML ( tokenEntry , tkXML [ bytes ] , name ) ;
482
488
}
483
- if ( lastTkData . enVariants ) {
484
- tokenEntry . nameVariants = lastTkData . enVariants ;
489
+
490
+ if ( comment && comment . startsWith ( 'Alias' ) ) {
491
+ tokenEntry . isAlias = true ;
485
492
}
486
- mergeSinceUntilFromTkXML ( tokenEntry , tkXML [ bytes ] , name ) ;
487
- }
488
493
489
- if ( comment && comment . startsWith ( 'Alias' ) ) {
490
- tokenEntry . isAlias = true ;
494
+ ( json [ bytes ] ??= tokenEntry ) . syntaxes . push ( {
495
+ specificName : specificName ,
496
+ syntax : wholeSyntaxLine ,
497
+ comment : comment ,
498
+ arguments : args ,
499
+ description : description ,
500
+ inEditorOnly : ( token . querySelector ( 'tbody p.MenuName' ) ?. textContent ?? '' ) . includes ( '†' ) ,
501
+ location : location . length && location [ 0 ] . length ? location : [ `[${ name . replace ( / \( $ / , '' ) } ]` ] ,
502
+ specialCategory : specialCategory . length ? specialCategory : undefined ,
503
+ } ) ;
491
504
}
492
505
493
- ( json [ bytes ] ??= tokenEntry ) . syntaxes . push ( {
494
- specificName : specificName ,
495
- syntax : wholeSyntaxLine ,
496
- comment : comment ,
497
- arguments : args ,
498
- description : description ,
499
- inEditorOnly : ( token . querySelector ( 'tbody p.MenuName' ) ?. textContent ?? '' ) . includes ( '†' ) ,
500
- location : location . length && location [ 0 ] . length ? location : [ `[${ name . replace ( / \( $ / , '' ) } ]` ] ,
501
- specialCategory : specialCategory . length ? specialCategory : undefined ,
502
- } ) ;
503
-
504
506
if ( manualOverrides [ bytes ] ) {
505
507
for ( const [ what , override ] of Object . entries ( manualOverrides [ bytes ] ) ) {
506
508
if ( typeof ( json [ bytes ] [ what ] ) === 'undefined' ) {
0 commit comments