Avoid getters for final fields

This commit is contained in:
serso 2016-01-24 21:11:04 +01:00
parent e751d2cbd4
commit 0e4960dc4e
30 changed files with 125 additions and 146 deletions

View File

@ -13,7 +13,7 @@ public class BracketedExpression implements Parser<ExpressionVariable> {
} }
public ExpressionVariable parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public ExpressionVariable parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.tryToParse(p, pos0, '('); ParserUtils.tryToParse(p, pos0, '(');
@ -21,7 +21,7 @@ public class BracketedExpression implements Parser<ExpressionVariable> {
try { try {
result = ExpressionParser.parser.parse(p, previousSumElement); result = ExpressionParser.parser.parse(p, previousSumElement);
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }

View File

@ -13,7 +13,7 @@ public class CommaAndExpression implements Parser<Generic> {
} }
public Generic parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { public Generic parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);

View File

@ -15,7 +15,7 @@ public class CommaAndVector implements Parser<JsclVector> {
@Nonnull @Nonnull
public JsclVector parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { public JsclVector parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);

View File

@ -14,7 +14,7 @@ public class CompoundIdentifier implements Parser<String> {
@Nonnull @Nonnull
public String parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { public String parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
@ -23,7 +23,7 @@ public class CompoundIdentifier implements Parser<String> {
String s = Identifier.parser.parse(p, previousSumElement); String s = Identifier.parser.parse(p, previousSumElement);
result.append(s); result.append(s);
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }
@ -49,7 +49,7 @@ class DotAndIdentifier implements Parser<String> {
} }
public String parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public String parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.tryToParse(p, pos0, '.'); ParserUtils.tryToParse(p, pos0, '.');
@ -57,7 +57,7 @@ class DotAndIdentifier implements Parser<String> {
try { try {
result = Identifier.parser.parse(p, previousSumElement); result = Identifier.parser.parse(p, previousSumElement);
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }

View File

@ -64,7 +64,7 @@ class Superscript implements Parser<Integer> {
} }
public Integer parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Integer parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.tryToParse(p, pos0, '{'); ParserUtils.tryToParse(p, pos0, '{');
@ -73,7 +73,7 @@ class Superscript implements Parser<Integer> {
try { try {
result = IntegerParser.parser.parse(p, previousSumElement); result = IntegerParser.parser.parse(p, previousSumElement);
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }

View File

@ -18,22 +18,22 @@ public class Digits implements Parser<String> {
// returns digit // returns digit
public String parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { public String parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);
if (p.getPosition().intValue() < p.getExpression().length() && nb.getAcceptableCharacters().contains(p.getExpression().charAt(p.getPosition().intValue()))) { if (p.position.intValue() < p.expression.length() && nb.getAcceptableCharacters().contains(p.expression.charAt(p.position.intValue()))) {
result.append(p.getExpression().charAt(p.getPosition().intValue())); result.append(p.expression.charAt(p.position.intValue()));
p.getPosition().increment(); p.position.increment();
} else { } else {
ParserUtils.throwParseException(p, pos0, Messages.msg_9); ParserUtils.throwParseException(p, pos0, Messages.msg_9);
} }
while (p.getPosition().intValue() < p.getExpression().length() && nb.getAcceptableCharacters().contains(p.getExpression().charAt(p.getPosition().intValue()))) { while (p.position.intValue() < p.expression.length() && nb.getAcceptableCharacters().contains(p.expression.charAt(p.position.intValue()))) {
result.append(p.getExpression().charAt(p.getPosition().intValue())); result.append(p.expression.charAt(p.position.intValue()));
p.getPosition().increment(); p.position.increment();
} }
return result.toString(); return result.toString();

View File

@ -39,7 +39,7 @@ class Singularity implements Parser<Double> {
@Nonnull @Nonnull
public Double parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Double parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
double result = 0d; double result = 0d;
@ -64,7 +64,7 @@ class FloatingPointLiteral implements Parser<Double> {
} }
public Double parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Double parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
final NumeralBase nb = NumeralBaseParser.parser.parse(p, previousSumElement); final NumeralBase nb = NumeralBaseParser.parser.parse(p, previousSumElement);
@ -88,7 +88,7 @@ class FloatingPointLiteral implements Parser<Double> {
point = true; point = true;
} catch (ParseException e) { } catch (ParseException e) {
if (!digits) { if (!digits) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }
} }
@ -101,7 +101,7 @@ class FloatingPointLiteral implements Parser<Double> {
result.append(digitsParser.parse(p, previousSumElement)); result.append(digitsParser.parse(p, previousSumElement));
} catch (ParseException e) { } catch (ParseException e) {
if (!digits) { if (!digits) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }
} }
@ -111,7 +111,7 @@ class FloatingPointLiteral implements Parser<Double> {
exponent = true; exponent = true;
} catch (ParseException e) { } catch (ParseException e) {
if (!point) { if (!point) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }
} }
@ -124,7 +124,7 @@ class FloatingPointLiteral implements Parser<Double> {
try { try {
return nb.toDouble(doubleString); return nb.toDouble(doubleString);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new ParseException(Messages.msg_8, p.getPosition().intValue(), p.getExpression(), doubleString); throw new ParseException(Messages.msg_8, p.position.intValue(), p.expression, doubleString);
} }
} }
} }
@ -138,7 +138,7 @@ class DecimalPoint implements Parser<Void> {
@Nullable @Nullable
public Void parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Void parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);
@ -157,15 +157,15 @@ class ExponentPart implements Parser<String> {
@Nonnull @Nonnull
public String parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public String parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);
if (p.getPosition().intValue() < p.getExpression().length() && (p.getExpression().charAt(p.getPosition().intValue()) == 'e' || p.getExpression().charAt(p.getPosition().intValue()) == 'E')) { if (p.position.intValue() < p.expression.length() && (p.expression.charAt(p.position.intValue()) == 'e' || p.expression.charAt(p.position.intValue()) == 'E')) {
char c = p.getExpression().charAt(p.getPosition().intValue()); char c = p.expression.charAt(p.position.intValue());
p.getPosition().increment(); p.position.increment();
result.append(c); result.append(c);
} else { } else {
ParserUtils.throwParseException(p, pos0, Messages.msg_10, 'e', 'E'); ParserUtils.throwParseException(p, pos0, Messages.msg_10, 'e', 'E');
@ -174,7 +174,7 @@ class ExponentPart implements Parser<String> {
try { try {
result.append(SignedInteger.parser.parse(p, previousSumElement)); result.append(SignedInteger.parser.parse(p, previousSumElement));
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }
@ -191,22 +191,22 @@ class SignedInteger implements Parser<String> {
@Nonnull @Nonnull
public String parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public String parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);
if (p.getPosition().intValue() < p.getExpression().length() && (p.getExpression().charAt(p.getPosition().intValue()) == '+' || p.getExpression().charAt(p.getPosition().intValue()) == '-')) { if (p.position.intValue() < p.expression.length() && (p.expression.charAt(p.position.intValue()) == '+' || p.expression.charAt(p.position.intValue()) == '-')) {
char c = p.getExpression().charAt(p.getPosition().intValue()); char c = p.expression.charAt(p.position.intValue());
p.getPosition().increment(); p.position.increment();
result.append(c); result.append(c);
} }
try { try {
result.append(IntegerParser.parser.parse(p, previousSumElement).intValue()); result.append(IntegerParser.parser.parse(p, previousSumElement).intValue());
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }

View File

@ -18,7 +18,7 @@ class ExponentParser implements Parser<Generic> {
} }
public Generic parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { public Generic parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
boolean sign = MinusParser.parser.parse(p, previousSumElement).isSign(); boolean sign = MinusParser.parser.parse(p, previousSumElement).isSign();

View File

@ -28,22 +28,22 @@ public class Identifier implements Parser<String> {
// returns getVariable/constant getName // returns getVariable/constant getName
@Nonnull @Nonnull
public String parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { public String parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);
if (p.getPosition().intValue() < p.getExpression().length() && isValidFirstCharacter(p.getExpression().charAt(p.getPosition().intValue()))) { if (p.position.intValue() < p.expression.length() && isValidFirstCharacter(p.expression.charAt(p.position.intValue()))) {
result.append(p.getExpression().charAt(p.getPosition().intValue())); result.append(p.expression.charAt(p.position.intValue()));
p.getPosition().increment(); p.position.increment();
} else { } else {
ParserUtils.throwParseException(p, pos0, Messages.msg_5); ParserUtils.throwParseException(p, pos0, Messages.msg_5);
} }
while (p.getPosition().intValue() < p.getExpression().length() && isValidNotFirstCharacter(p.getExpression(), p.getPosition())) { while (p.position.intValue() < p.expression.length() && isValidNotFirstCharacter(p.expression, p.position)) {
result.append(p.getExpression().charAt(p.getPosition().intValue())); result.append(p.expression.charAt(p.position.intValue()));
p.getPosition().increment(); p.position.increment();
} }
return result.toString(); return result.toString();

View File

@ -19,13 +19,13 @@ public class ImplicitFunctionParser implements Parser<Function> {
} }
public Function parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Function parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
Generic a[]; Generic a[];
final String name = ParserUtils.parseWithRollback(CompoundIdentifier.parser, pos0, previousSumElement, p); final String name = ParserUtils.parseWithRollback(CompoundIdentifier.parser, pos0, previousSumElement, p);
if (FunctionsRegistry.getInstance().getNames().contains(name) || OperatorsRegistry.getInstance().getNames().contains(name)) { if (FunctionsRegistry.getInstance().getNames().contains(name) || OperatorsRegistry.getInstance().getNames().contains(name)) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw new ParseException(Messages.msg_6, p.getPosition().intValue(), p.getExpression(), name); throw new ParseException(Messages.msg_6, p.position.intValue(), p.expression, name);
} }
final List<Generic> subscripts = new ArrayList<Generic>(); final List<Generic> subscripts = new ArrayList<Generic>();
@ -46,7 +46,7 @@ public class ImplicitFunctionParser implements Parser<Function> {
try { try {
a = ParameterListParser.parser1.parse(p, previousSumElement); a = ParameterListParser.parser1.parse(p, previousSumElement);
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }
@ -87,7 +87,7 @@ class SuperscriptList implements Parser<int[]> {
} }
public int[] parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public int[] parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.tryToParse(p, pos0, '{'); ParserUtils.tryToParse(p, pos0, '{');
@ -95,7 +95,7 @@ class SuperscriptList implements Parser<int[]> {
try { try {
result.add(IntegerParser.parser.parse(p, previousSumElement)); result.add(IntegerParser.parser.parse(p, previousSumElement));
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }
@ -123,7 +123,7 @@ class CommaAndInteger implements Parser<Integer> {
} }
public Integer parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Integer parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);

View File

@ -15,7 +15,7 @@ public class IntegerParser implements Parser<Integer> {
} }
public Integer parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { public Integer parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
/*int n; /*int n;
@ -40,18 +40,18 @@ public class IntegerParser implements Parser<Integer> {
final StringBuilder result = new StringBuilder(); final StringBuilder result = new StringBuilder();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);
if (p.getPosition().intValue() < p.getExpression().length() && nb.getAcceptableCharacters().contains(p.getExpression().charAt(p.getPosition().intValue()))) { if (p.position.intValue() < p.expression.length() && nb.getAcceptableCharacters().contains(p.expression.charAt(p.position.intValue()))) {
char c = p.getExpression().charAt(p.getPosition().intValue()); char c = p.expression.charAt(p.position.intValue());
p.getPosition().increment(); p.position.increment();
result.append(c); result.append(c);
} else { } else {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw new ParseException(Messages.msg_7, p.getPosition().intValue(), p.getExpression()); throw new ParseException(Messages.msg_7, p.position.intValue(), p.expression);
} }
while (p.getPosition().intValue() < p.getExpression().length() && nb.getAcceptableCharacters().contains(p.getExpression().charAt(p.getPosition().intValue()))) { while (p.position.intValue() < p.expression.length() && nb.getAcceptableCharacters().contains(p.expression.charAt(p.position.intValue()))) {
char c = p.getExpression().charAt(p.getPosition().intValue()); char c = p.expression.charAt(p.position.intValue());
p.getPosition().increment(); p.position.increment();
result.append(c); result.append(c);
} }
@ -59,7 +59,7 @@ public class IntegerParser implements Parser<Integer> {
try { try {
return nb.toInteger(number); return nb.toInteger(number);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new ParseException(Messages.msg_8, p.getPosition().intValue(), p.getExpression(), number); throw new ParseException(Messages.msg_8, p.position.intValue(), p.expression, number);
} }
} }
} }

View File

@ -16,7 +16,7 @@ public class JsclIntegerParser implements Parser<JsclInteger> {
} }
public JsclInteger parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { public JsclInteger parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
final NumeralBase nb = NumeralBaseParser.parser.parse(p, previousSumElement); final NumeralBase nb = NumeralBaseParser.parser.parse(p, previousSumElement);
@ -25,7 +25,7 @@ public class JsclIntegerParser implements Parser<JsclInteger> {
try { try {
result.append(new Digits(nb).parse(p, previousSumElement)); result.append(new Digits(nb).parse(p, previousSumElement));
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }
@ -33,7 +33,7 @@ public class JsclIntegerParser implements Parser<JsclInteger> {
try { try {
return nb.toJsclInteger(number); return nb.toJsclInteger(number);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new ParseException(Messages.msg_8, p.getPosition().intValue(), p.getExpression(), number); throw new ParseException(Messages.msg_8, p.position.intValue(), p.expression, number);
} }
} }
} }

View File

@ -17,7 +17,7 @@ public class MatrixParser implements Parser<Matrix> {
} }
public Matrix parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Matrix parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
final List<Generic> vectors = new ArrayList<Generic>(); final List<Generic> vectors = new ArrayList<Generic>();
@ -26,7 +26,7 @@ public class MatrixParser implements Parser<Matrix> {
try { try {
vectors.add(VectorParser.parser.parse(p, previousSumElement)); vectors.add(VectorParser.parser.parse(p, previousSumElement));
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }

View File

@ -21,16 +21,16 @@ class MinusParser implements Parser<MinusParser.Result> {
public Result parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) { public Result parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) {
final boolean result; final boolean result;
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);
if (p.getPosition().intValue() < p.getExpression().length() && p.getExpression().charAt(p.getPosition().intValue()) == '-') { if (p.position.intValue() < p.expression.length() && p.expression.charAt(p.position.intValue()) == '-') {
result = true; result = true;
p.getPosition().increment(); p.position.increment();
} else { } else {
result = false; result = false;
p.getPosition().setValue(pos0); p.position.setValue(pos0);
} }
return new Result(result); return new Result(result);

View File

@ -23,11 +23,11 @@ class MultiplyOrDivideFactor implements Parser<Generic> {
} }
public Generic parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Generic parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);
if (p.getPosition().intValue() < p.getExpression().length() && p.getExpression().charAt(p.getPosition().intValue()) == (multiplication ? '*' : '/')) { if (p.position.intValue() < p.expression.length() && p.expression.charAt(p.position.intValue()) == (multiplication ? '*' : '/')) {
p.getPosition().increment(); p.position.increment();
} else { } else {
ParserUtils.throwParseException(p, pos0, Messages.msg_10, '*', '/'); ParserUtils.throwParseException(p, pos0, Messages.msg_10, '*', '/');
} }

View File

@ -14,9 +14,9 @@ public class NumeralBaseParser implements Parser<NumeralBase> {
} }
public NumeralBase parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) { public NumeralBase parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
NumeralBase result = p.getMathContext().getNumeralBase(); NumeralBase result = p.context.getNumeralBase();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);

View File

@ -21,7 +21,7 @@ public class OperatorParser implements Parser<Operator> {
@Nonnull @Nonnull
public Operator parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Operator parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
final String operatorName = Identifier.parser.parse(p, previousSumElement); final String operatorName = Identifier.parser.parse(p, previousSumElement);
if (!valid(operatorName)) { if (!valid(operatorName)) {

View File

@ -22,7 +22,7 @@ public class ParameterListParser implements Parser<Generic[]> {
@Nonnull @Nonnull
public Generic[] parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Generic[] parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
final List<Generic> result = new ArrayList<Generic>(); final List<Generic> result = new ArrayList<Generic>();
@ -32,7 +32,7 @@ public class ParameterListParser implements Parser<Generic[]> {
result.add(ExpressionParser.parser.parse(p, previousSumElement)); result.add(ExpressionParser.parser.parse(p, previousSumElement));
} catch (ParseException e) { } catch (ParseException e) {
if (minNumberOfParameters > 0) { if (minNumberOfParameters > 0) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }
} }

View File

@ -6,7 +6,6 @@ import jscl.math.Generic;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@ -26,29 +25,29 @@ public interface Parser<T> {
*/ */
T parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException; T parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException;
static class Parameters { class Parameters {
@Nonnull @Nonnull
private final String expression; public final String expression;
@Nonnull @Nonnull
private final MutableInt position; public final MutableInt position;
@Nonnull @Nonnull
private final List<ParseException> exceptions = new ArrayList<ParseException>(); public final List<ParseException> exceptions = new ArrayList<ParseException>();
@Nonnull @Nonnull
private final MathContext mathContext; public final MathContext context;
/** /**
* @param expression expression to be parsed * @param expression expression to be parsed
* @param position current position of expression. Side effect: if parsing is successful this parameter should be increased on the number of parsed letters (incl whitespaces etc) * @param position current position of expression. Side effect: if parsing is successful this parameter should be increased on the number of parsed letters (incl whitespaces etc)
* @param mathContext math engine to be used in parsing * @param context math engine to be used in parsing
*/ */
Parameters(@Nonnull String expression, @Nonnull MutableInt position, @Nonnull MathContext mathContext) { Parameters(@Nonnull String expression, @Nonnull MutableInt position, @Nonnull MathContext context) {
this.expression = expression; this.expression = expression;
this.position = position; this.position = position;
this.mathContext = mathContext; this.context = context;
} }
@Nonnull @Nonnull
@ -56,30 +55,10 @@ public interface Parser<T> {
return new Parameters(expression, position, mathEngine); return new Parameters(expression, position, mathEngine);
} }
@Nonnull
public String getExpression() {
return expression;
}
@Nonnull
public MutableInt getPosition() {
return position;
}
public void addException(@Nonnull ParseException e) { public void addException(@Nonnull ParseException e) {
if (!exceptions.contains(e)) { if (!exceptions.contains(e)) {
exceptions.add(e); exceptions.add(e);
} }
} }
@Nonnull
public MathContext getMathContext() {
return mathContext;
}
@Nonnull
public List<ParseException> getExceptions() {
return Collections.unmodifiableList(exceptions);
}
} }
} }

View File

@ -21,8 +21,8 @@ public class ParserUtils {
} }
public static void skipWhitespaces(@Nonnull Parser.Parameters p) { public static void skipWhitespaces(@Nonnull Parser.Parameters p) {
final MutableInt position = p.getPosition(); final MutableInt position = p.position;
final String expression = p.getExpression(); final String expression = p.expression;
while (position.intValue() < expression.length() && Character.isWhitespace(expression.charAt(position.intValue()))) { while (position.intValue() < expression.length() && Character.isWhitespace(expression.charAt(position.intValue()))) {
position.increment(); position.increment();
@ -34,10 +34,10 @@ public class ParserUtils {
char ch) throws ParseException { char ch) throws ParseException {
skipWhitespaces(p); skipWhitespaces(p);
if (p.getPosition().intValue() < p.getExpression().length()) { if (p.position.intValue() < p.expression.length()) {
char actual = p.getExpression().charAt(p.getPosition().intValue()); char actual = p.expression.charAt(p.position.intValue());
if (actual == ch) { if (actual == ch) {
p.getPosition().increment(); p.position.increment();
} else { } else {
throwParseException(p, pos0, Messages.msg_12, ch); throwParseException(p, pos0, Messages.msg_12, ch);
} }
@ -51,9 +51,9 @@ public class ParserUtils {
@Nonnull String s) throws ParseException { @Nonnull String s) throws ParseException {
skipWhitespaces(p); skipWhitespaces(p);
if (p.getPosition().intValue() < p.getExpression().length()) { if (p.position.intValue() < p.expression.length()) {
if (p.getExpression().startsWith(s, p.getPosition().intValue())) { if (p.expression.startsWith(s, p.position.intValue())) {
p.getPosition().add(s.length()); p.position.add(s.length());
} else { } else {
throwParseException(p, pos0, Messages.msg_11, s); throwParseException(p, pos0, Messages.msg_11, s);
} }
@ -66,8 +66,8 @@ public class ParserUtils {
int pos0, int pos0,
@Nonnull String messageId, @Nonnull String messageId,
Object... parameters) throws ParseException { Object... parameters) throws ParseException {
final MutableInt position = p.getPosition(); final MutableInt position = p.position;
final ParseException parseException = new ParseException(messageId, position.intValue(), p.getExpression(), parameters); final ParseException parseException = new ParseException(messageId, position.intValue(), p.expression, parameters);
position.setValue(pos0); position.setValue(pos0);
throw parseException; throw parseException;
} }
@ -83,7 +83,7 @@ public class ParserUtils {
try { try {
result = parser.parse(p, previousSumParser); result = parser.parse(p, previousSumParser);
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(initialPosition); p.position.setValue(initialPosition);
throw e; throw e;
} }

View File

@ -18,14 +18,14 @@ class PlusOrMinusTerm implements Parser<Generic> {
} }
public Generic parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Generic parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);
boolean sign = false; boolean sign = false;
if (p.getPosition().intValue() < p.getExpression().length() && (p.getExpression().charAt(p.getPosition().intValue()) == '+' || p.getExpression().charAt(p.getPosition().intValue()) == '-')) { if (p.position.intValue() < p.expression.length() && (p.expression.charAt(p.position.intValue()) == '+' || p.expression.charAt(p.position.intValue()) == '-')) {
sign = p.getExpression().charAt(p.getPosition().intValue()) == '-'; sign = p.expression.charAt(p.position.intValue()) == '-';
p.getPosition().increment(); p.position.increment();
} else { } else {
ParserUtils.throwParseException(p, pos0, Messages.msg_10, '+', '-'); ParserUtils.throwParseException(p, pos0, Messages.msg_10, '+', '-');
} }

View File

@ -20,17 +20,17 @@ public class PostfixFunctionParser implements Parser<PostfixFunctionParser.Resul
@Nonnull @Nonnull
public Result parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Result parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
final boolean postfixFunction; final boolean postfixFunction;
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);
if (p.getPosition().intValue() < p.getExpression().length() && p.getExpression().startsWith(postfixFunctionName, p.getPosition().intValue())) { if (p.position.intValue() < p.expression.length() && p.expression.startsWith(postfixFunctionName, p.position.intValue())) {
p.getPosition().add(postfixFunctionName.length()); p.position.add(postfixFunctionName.length());
postfixFunction = true; postfixFunction = true;
} else { } else {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
postfixFunction = false; postfixFunction = false;
} }

View File

@ -44,9 +44,9 @@ public class PostfixFunctionsParser implements Parser<Generic> {
if (postfixFunction == null) { if (postfixFunction == null) {
if (TripleFactorial.NAME.equals(postfixResult.getPostfixFunctionName())) { if (TripleFactorial.NAME.equals(postfixResult.getPostfixFunctionName())) {
throw new ParseException(Messages.msg_18, parseParameters.getPosition().intValue(), parseParameters.getExpression()); throw new ParseException(Messages.msg_18, parseParameters.position.intValue(), parseParameters.expression);
} else { } else {
throw new ParseException(Messages.msg_4, parseParameters.getPosition().intValue(), parseParameters.getExpression(), postfixResult.getPostfixFunctionName()); throw new ParseException(Messages.msg_4, parseParameters.position.intValue(), parseParameters.expression, postfixResult.getPostfixFunctionName());
} }
} }

View File

@ -18,12 +18,12 @@ class PowerExponentParser implements Parser<Generic> {
} }
public Generic parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { public Generic parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
try { try {
PowerParser.parser.parse(p, previousSumElement); PowerParser.parser.parse(p, previousSumElement);
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }
@ -31,7 +31,7 @@ class PowerExponentParser implements Parser<Generic> {
try { try {
result = ExponentParser.parser.parse(p, previousSumElement); result = ExponentParser.parser.parse(p, previousSumElement);
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }

View File

@ -20,16 +20,16 @@ class PowerParser implements Parser<Void> {
@Nullable @Nullable
public Void parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Void parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);
if (p.getPosition().intValue() < p.getExpression().length() && p.getExpression().charAt(p.getPosition().intValue()) == '^') { if (p.position.intValue() < p.expression.length() && p.expression.charAt(p.position.intValue()) == '^') {
p.getPosition().increment(); p.position.increment();
} else { } else {
if (isDoubleStar(p.getExpression(), p.getPosition())) { if (isDoubleStar(p.expression, p.position)) {
p.getPosition().increment(); p.position.increment();
p.getPosition().increment(); p.position.increment();
} else { } else {
ParserUtils.throwParseException(p, pos0, Messages.msg_10, '^', "**"); ParserUtils.throwParseException(p, pos0, Messages.msg_10, '^', "**");
} }

View File

@ -14,21 +14,21 @@ public class PrimeCharacters implements Parser<Integer> {
public Integer parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { public Integer parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
int result = 0; int result = 0;
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);
if (p.getPosition().intValue() < p.getExpression().length() && p.getExpression().charAt(p.getPosition().intValue()) == '\'') { if (p.position.intValue() < p.expression.length() && p.expression.charAt(p.position.intValue()) == '\'') {
p.getPosition().increment(); p.position.increment();
result = 1; result = 1;
} else { } else {
ParserUtils.throwParseException(p, pos0, Messages.msg_12, '\''); ParserUtils.throwParseException(p, pos0, Messages.msg_12, '\'');
} }
while (p.getPosition().intValue() < p.getExpression().length() && p.getExpression().charAt(p.getPosition().intValue()) == '\'') { while (p.position.intValue() < p.expression.length() && p.expression.charAt(p.position.intValue()) == '\'') {
p.getPosition().increment(); p.position.increment();
result++; result++;
} }

View File

@ -14,7 +14,7 @@ public class RootParser implements Parser<Function> {
} }
public Function parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Function parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
final String name = Identifier.parser.parse(p, previousSumElement); final String name = Identifier.parser.parse(p, previousSumElement);
if (name.compareTo("root") != 0) { if (name.compareTo("root") != 0) {

View File

@ -13,7 +13,7 @@ public class Subscript implements Parser<Generic> {
} }
public Generic parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { public Generic parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.tryToParse(p, pos0, '['); ParserUtils.tryToParse(p, pos0, '[');
@ -21,7 +21,7 @@ public class Subscript implements Parser<Generic> {
try { try {
a = ExpressionParser.parser.parse(p, previousSumElement); a = ExpressionParser.parser.parse(p, previousSumElement);
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }

View File

@ -28,7 +28,7 @@ class UsualFunctionParser implements Parser<Function> {
} }
public Function parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public Function parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
final String name = Identifier.parser.parse(p, previousSumElement); final String name = Identifier.parser.parse(p, previousSumElement);

View File

@ -16,7 +16,7 @@ public class VectorParser implements Parser<JsclVector> {
} }
public JsclVector parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { public JsclVector parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException {
int pos0 = p.getPosition().intValue(); int pos0 = p.position.intValue();
ParserUtils.skipWhitespaces(p); ParserUtils.skipWhitespaces(p);
@ -26,7 +26,7 @@ public class VectorParser implements Parser<JsclVector> {
try { try {
result.add(ExpressionParser.parser.parse(p, previousSumElement)); result.add(ExpressionParser.parser.parse(p, previousSumElement));
} catch (ParseException e) { } catch (ParseException e) {
p.getPosition().setValue(pos0); p.position.setValue(pos0);
throw e; throw e;
} }