![JAR search and dependency download from the Maven repository](/logo.png)
com.creativewidgetworks.goldparser.simple2.rulehandlers.Negation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of goldengine Show documentation
Show all versions of goldengine Show documentation
Java implementation of Devin Cook's GOLD Parser engine
package com.creativewidgetworks.goldparser.simple2.rulehandlers;
import java.math.BigDecimal;
import com.creativewidgetworks.goldparser.engine.ParserException;
import com.creativewidgetworks.goldparser.engine.Reduction;
import com.creativewidgetworks.goldparser.parser.ProcessRule;
import com.creativewidgetworks.goldparser.parser.Variable;
import com.creativewidgetworks.goldparser.parser.GOLDParser;
import com.creativewidgetworks.goldparser.simple2.Simple2;
@ProcessRule(rule=" ::= - ")
/**
* Rule handler for the negation rule.
*
* @author Ralph Iden (http://www.creativewidgetworks.com)
* @version 5.0.0
*/
public class Negation extends Reduction {
private GOLDParser theParser;
private Reduction valueToNegate;
public Negation(GOLDParser parser) {
theParser = parser;
Reduction reduction = parser.getCurrentReduction();
if (reduction != null) {
if (reduction.size() == 2) {
valueToNegate = reduction.get(1).asReduction();
} else {
parser.raiseParserException(Simple2.formatMessage("error.param_count", "2", String.valueOf(reduction.size())));
}
} else {
parser.raiseParserException(Simple2.formatMessage("error.no_reduction"));
}
}
@Override
public Variable getValue() throws ParserException {
BigDecimal bd = valueToNegate.getValue().asNumber();
if (bd == null) {
theParser.raiseParserException(Simple2.formatMessage("error.negation_number_expected"));
}
return new Variable(bd.negate());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy