File tree Expand file tree Collapse file tree
src/main/java/net/marcellperger/mathexpr/parser Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import net .marcellperger .mathexpr .*;
44import net .marcellperger .mathexpr .util .Pair ;
55import net .marcellperger .mathexpr .util .Util ;
6+ import net .marcellperger .mathexpr .util .rs .Result ;
67import org .jetbrains .annotations .NotNull ;
78import org .jetbrains .annotations .Nullable ;
89import org .jetbrains .annotations .Range ;
@@ -62,6 +63,22 @@ public MathSymbol parseExpr() throws ExprParseException {
6263 }
6364 return new BasicDoubleSymbol (value );
6465 }
66+ public @ NotNull Result <MathSymbol , Throwable > parseDoubleLiteral_result () {
67+ discardWhitespace ();
68+ Matcher m = DOUBLE_RE .matcher (strFromHere ());
69+ if (!m .lookingAt ()) return Result .fromExc (new ExprParseException ("Invalid number" ));
70+ String s = m .group ();
71+ idx += s .length ();
72+ double value ;
73+ try {
74+ value = Double .parseDouble (s );
75+ } catch (NumberFormatException exc ) {
76+ // Technically this should never happen - assuming I've got that regex right
77+ throw new AssertionError (
78+ "There is a problem with the regex, this should've been rejected earlier" , exc );
79+ }
80+ return Result .newOk (new BasicDoubleSymbol (value ));
81+ }
6582
6683 public @ Nullable MathSymbol parseParensOrLiteral () throws ExprParseException {
6784 discardWhitespace ();
You can’t perform that action at this time.
0 commit comments