Skip to content

Commit 9672f89

Browse files
committed
Scientific notation support (OE13)
RSSW-344
1 parent c1ddaa4 commit 9672f89

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

proparse/src/main/java/org/prorefactor/proparse/Lexer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Locale;
2727
import java.util.Map;
2828
import java.util.Set;
29+
import java.util.regex.Pattern;
2930

3031
import javax.annotation.CheckForNull;
3132
import javax.annotation.Nonnull;
@@ -62,7 +63,7 @@
6263
*/
6364
public class Lexer implements IPreprocessor {
6465
private static final Logger LOGGER = LoggerFactory.getLogger(Lexer.class);
65-
66+
private static final Pattern SCIENTIFIC_NOTATION = Pattern.compile("\\d+(\\.\\d+)?e[+-]\\d+");
6667
private static final int SKIP_CHAR = -100;
6768
private static final int PROPARSE_DIRECTIVE = -101;
6869
private static final int INCLUDE_DIRECTIVE = -102;
@@ -771,6 +772,8 @@ private ProToken digitStart(boolean hex) {
771772
stop = true;
772773
}
773774
}
775+
if (SCIENTIFIC_NOTATION.matcher(currText).matches())
776+
ttype = ABLNodeType.NUMBER;
774777

775778
return makeToken(ttype);
776779
}

proparse/src/test/java/org/prorefactor/proparse/ABLLexerTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ public void setUp() throws IOException {
5252
session = new RefactorSession(new UnitTestProparseSettings(), new SportsSchema());
5353
}
5454

55+
@Test
56+
public void testScientificNotation01() {
57+
final var source = "6.02214076 6.02214076e+23 1.456e-3 4.246e+4 6779.0 23766e-1 .23e-1 ";
58+
var lexer = new ABLLexer(session, ByteSource.wrap(source.getBytes()), true);
59+
60+
assertNextTokenTypeWS(lexer, ABLNodeType.NUMBER, "6.02214076");
61+
assertNextTokenTypeWS(lexer, ABLNodeType.NUMBER, "6.02214076e+23");
62+
assertNextTokenTypeWS(lexer, ABLNodeType.NUMBER, "1.456e-3");
63+
assertNextTokenTypeWS(lexer, ABLNodeType.NUMBER, "4.246e+4");
64+
assertNextTokenTypeWS(lexer, ABLNodeType.NUMBER, "6779.0");
65+
assertNextTokenTypeWS(lexer, ABLNodeType.NUMBER, "23766e-1");
66+
assertNextTokenTypeWS(lexer, ABLNodeType.FILENAME, ".23e-1");
67+
}
68+
5569
@Test
5670
public void testDecimalNumber01() {
5771
final String source = "rct1:height = 0.1\n rct1:row ";

0 commit comments

Comments
 (0)