@@ -515,6 +515,14 @@ protected void parsePath() {
515
515
516
516
StringBuilder pathBuffer = new StringBuilder ();
517
517
518
+ enum LexState {
519
+ AFTER_CMD ,// Just after a command (i.e. a single alphabet)
520
+ NEUTRAL , // Neutral state, waiting for a number expression or a command
521
+ INTEGER , // On a sequence of digits possibly led by the '-' sign
522
+ DECIMAL , // On a digit sequence following the decimal point '.'
523
+ EXP_HEAD , // On the head of the exponent part of a scientific notation; the '-' sign or a digit
524
+ EXP_TAIL , // On the integer expression in the exponent part
525
+ }
518
526
/*
519
527
* The state of the lexer:
520
528
* -1: just after the command (i.e. a single alphabet)
@@ -524,66 +532,69 @@ protected void parsePath() {
524
532
* 3: on a digit or a sign in exponent in scientific notation, e.g. 3.14e-2)
525
533
* 4: on a digit sequence in exponent
526
534
*/
527
- int lexState = 0 ;
535
+ LexState lexState = LexState . NEUTRAL ;
528
536
529
537
for (int i = 0 ; i < pathDataChars .length ; i ++) {
530
538
char c = pathDataChars [i ];
531
539
532
540
// Put a separator after a command.
533
- if (lexState == - 1 ) {
541
+ if (lexState == LexState . AFTER_CMD ) {
534
542
pathBuffer .append ("|" );
535
- lexState = 0 ;
543
+ lexState = LexState . NEUTRAL ;
536
544
}
537
545
538
546
if (c >= '0' && c <= '9' ) {
539
- if (lexState == 0 || lexState == 3 ) {
540
- // If it is a head of a number representation, enter the 'inside' of the digit sequence.
541
- ++lexState ;
547
+ // If it is a head of a number representation, enter the 'inside' of the digit sequence.
548
+ if (lexState == LexState .NEUTRAL ) {
549
+ lexState = LexState .INTEGER ;
550
+ }
551
+ else if (lexState == LexState .EXP_HEAD ) {
552
+ lexState = LexState .EXP_TAIL ;
542
553
}
543
554
pathBuffer .append (c );
544
555
continue ;
545
556
}
546
557
547
558
if (c == '-' ) {
548
- if (lexState == 0 ) {
559
+ if (lexState == LexState . NEUTRAL ) {
549
560
// In neutral state, enter 'digit sequence'.
550
- lexState = 1 ;
561
+ lexState = LexState . INTEGER ;
551
562
}
552
- else if (lexState == 3 ) {
563
+ else if (lexState == LexState . EXP_HEAD ) {
553
564
// In the begining of an exponent, enter 'exponent digit sequence'.
554
- lexState = 4 ;
565
+ lexState = LexState . EXP_TAIL ;
555
566
}
556
567
else {
557
568
// Otherwise, begin a new number representation.
558
569
pathBuffer .append ("|" );
559
- lexState = 1 ;
570
+ lexState = LexState . INTEGER ;
560
571
}
561
572
pathBuffer .append ("-" );
562
573
continue ;
563
574
}
564
575
565
576
if (c == '.' ) {
566
- if (lexState >= 2 ) {
577
+ if (lexState == LexState . DECIMAL || lexState == LexState . EXP_HEAD || lexState == LexState . EXP_TAIL ) {
567
578
// Begin a new decimal number unless it is in a neutral state or after a digit sequence
568
579
pathBuffer .append ("|" );
569
580
}
570
581
pathBuffer .append ("." );
571
- lexState = 2 ;
582
+ lexState = LexState . DECIMAL ;
572
583
continue ;
573
584
}
574
585
575
586
if (c == 'e' || c == 'E' ) {
576
587
// Found 'e' or 'E', enter the 'exponent' state immediately.
577
588
pathBuffer .append ("e" );
578
- lexState = 3 ;
589
+ lexState = LexState . EXP_HEAD ;
579
590
continue ;
580
591
}
581
592
582
593
// The following are executed for non-numeral elements
583
594
584
- if (lexState != 0 ) {
595
+ if (lexState != LexState . NEUTRAL ) {
585
596
pathBuffer .append ("|" );
586
- lexState = 0 ;
597
+ lexState = LexState . NEUTRAL ;
587
598
}
588
599
589
600
if (c != ',' ) {
@@ -592,7 +603,7 @@ else if (lexState == 3) {
592
603
593
604
if ((c >= 'A' && c <= 'Z' ) || (c >= 'a' && c <= 'z' )) {
594
605
// Every alphabet character except for 'e' and 'E' are considered as a command.
595
- lexState = - 1 ;
606
+ lexState = LexState . AFTER_CMD ;
596
607
}
597
608
}
598
609
0 commit comments