use of org.apache.sysml.parser.BooleanIdentifier in project incubator-systemml by apache.
the class CommonSyntacticValidator method getConstIdFromString.
protected ConstIdentifier getConstIdFromString(String varValue, Token start) {
int linePosition = start.getLine();
int charPosition = start.getCharPositionInLine();
// Compare to "True/TRUE"
if (varValue.equals(trueStringLiteral()))
return new BooleanIdentifier(true, currentFile, linePosition, charPosition, linePosition, charPosition);
// Compare to "False/FALSE"
if (varValue.equals(falseStringLiteral()))
return new BooleanIdentifier(false, currentFile, linePosition, charPosition, linePosition, charPosition);
// Also the alternative of Ints.tryParse and falling back to double would not be lossless in all cases.
try {
long lval = Long.parseLong(varValue);
return new IntIdentifier(lval, currentFile, linePosition, charPosition, linePosition, charPosition);
} catch (Exception ex) {
//continue
}
// NOTE: we use exception handling instead of Doubles.tryParse for backwards compatibility with guava <14.0
try {
double dval = Double.parseDouble(varValue);
return new DoubleIdentifier(dval, currentFile, linePosition, charPosition, linePosition, charPosition);
} catch (Exception ex) {
//continue
}
// Otherwise it is a string literal (optionally enclosed within single or double quotes)
String val = "";
String text = varValue;
if ((text.startsWith("\"") && text.endsWith("\"")) || (text.startsWith("\'") && text.endsWith("\'"))) {
if (text.length() > 2) {
val = extractStringInQuotes(text, true);
}
} else {
// the commandline parameters can be passed without any quotes
val = extractStringInQuotes(text, false);
}
return new StringIdentifier(val, currentFile, linePosition, charPosition, linePosition, charPosition);
}
use of org.apache.sysml.parser.BooleanIdentifier in project incubator-systemml by apache.
the class CommonSyntacticValidator method booleanIdentifierHelper.
protected void booleanIdentifierHelper(ParserRuleContext ctx, boolean val, ExpressionInfo info) {
int linePosition = ctx.start.getLine();
int charPosition = ctx.start.getCharPositionInLine();
info.expr = new BooleanIdentifier(val, currentFile, linePosition, charPosition, linePosition, charPosition);
setFileLineColumn(info.expr, ctx);
}
Aggregations