Search in sources :

Example 1 with LegalScope

use of pcgen.base.formula.base.LegalScope in project pcgen by PCGen.

the class SourceFileLoader method defineVariable.

private void defineVariable(VariableContext varContext, FormatManager<?> formatManager, String varName) {
    LegalScope varScope = varContext.getScope("Global");
    varContext.assertLegalVariableID(varScope, formatManager, varName);
}
Also used : LegalScope(pcgen.base.formula.base.LegalScope)

Example 2 with LegalScope

use of pcgen.base.formula.base.LegalScope in project pcgen by PCGen.

the class LoadContextInst method dropIntoContext.

private LoadContext dropIntoContext(LegalScope lvs) {
    LegalScope parent = lvs.getParentScope();
    if (parent == null) {
        //is Global
        return this;
    }
    LoadContext parentLC = dropIntoContext(parent);
    SimpleScopeInstance localInst = new SimpleScopeInstance(parentLC.getActiveScope(), lvs, new DummyVarScoped(lvs));
    return new DerivedLoadContext(parentLC, localInst);
}
Also used : SimpleScopeInstance(pcgen.base.formula.inst.SimpleScopeInstance) LegalScope(pcgen.base.formula.base.LegalScope)

Example 3 with LegalScope

use of pcgen.base.formula.base.LegalScope in project pcgen by PCGen.

the class DropIntoContext method allowFromScopeName.

private FormatManager<?> allowFromScopeName(SemanticsVisitor visitor, FormulaSemantics semantics, String legalScopeName, Node node) {
    FormulaManager fm = semantics.get(FormulaSemantics.FMANAGER);
    ScopeInstanceFactory siFactory = fm.getScopeInstanceFactory();
    LegalScope legalScope = siFactory.getScope(legalScopeName);
    if (legalScope == null) {
        semantics.setInvalid("Parse Error: Invalid Scope Name: " + legalScopeName + " is not a valid scope name");
        return null;
    }
    //Rest of Equation
    semantics = semantics.getWith(FormulaSemantics.FMANAGER, fm);
    semantics = semantics.getWith(FormulaSemantics.SCOPE, legalScope);
    FormatManager<?> format = (FormatManager<?>) node.jjtAccept(visitor, semantics);
    return format;
}
Also used : FormulaManager(pcgen.base.formula.base.FormulaManager) LegalScope(pcgen.base.formula.base.LegalScope) FormatManager(pcgen.base.util.FormatManager) ScopeInstanceFactory(pcgen.base.formula.inst.ScopeInstanceFactory)

Example 4 with LegalScope

use of pcgen.base.formula.base.LegalScope in project pcgen by PCGen.

the class InputFunction method allowArgs.

@Override
public final FormatManager<?> allowArgs(SemanticsVisitor visitor, Node[] args, FormulaSemantics semantics) {
    int argCount = args.length;
    if (argCount != 1) {
        semantics.setInvalid("Function " + getFunctionName() + " received incorrect # of arguments, expected: 1 got " + args.length + ' ' + Arrays.asList(args));
        return null;
    }
    //String node (name)
    Node inputNode = args[0];
    if (inputNode.getId() != FormulaParserTreeConstants.JJTQUOTSTRING) {
        semantics.setInvalid("Parse Error: Invalid Value: " + ((SimpleNode) inputNode).getText() + " found in " + inputNode.getClass().getName() + " found in location requiring a literal" + " String (cannot be evaluated)");
        return null;
    }
    String inputName = ((SimpleNode) inputNode).getText();
    String varName = ChannelUtilities.createVarName(inputName);
    VariableLibrary varLib = semantics.get(FormulaSemantics.FMANAGER).getFactory();
    LegalScope scope = semantics.get(FormulaSemantics.SCOPE);
    FormatManager<?> formatManager = varLib.getVariableFormat(scope, varName);
    if (formatManager == null) {
        semantics.setInvalid("Input Channel: " + varName + " was not found");
        return null;
    }
    return formatManager;
}
Also used : LegalScope(pcgen.base.formula.base.LegalScope) SimpleNode(pcgen.base.formula.parse.SimpleNode) Node(pcgen.base.formula.parse.Node) ASTQuotString(pcgen.base.formula.parse.ASTQuotString) SimpleNode(pcgen.base.formula.parse.SimpleNode) VariableLibrary(pcgen.base.formula.base.VariableLibrary)

Example 5 with LegalScope

use of pcgen.base.formula.base.LegalScope in project pcgen by PCGen.

the class FaceToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Race race, String value) {
    if (ControlUtilities.hasControlToken(context, CControl.FACE)) {
        return new ParseResult.Fail("FACE: LST Token is disabled when FACE: control is used", context);
    }
    if (value.indexOf(',') == -1) {
        value = value + ',' + 0;
    }
    FormatManager<OrderedPair> formatManager = (FormatManager<OrderedPair>) context.getReferenceContext().getFormatManager("ORDEREDPAIR");
    ScopeInstance scopeInst = context.getActiveScope();
    LegalScope scope = scopeInst.getLegalScope();
    PCGenModifier<OrderedPair> modifier;
    try {
        modifier = context.getVariableContext().getModifier(MOD_IDENTIFICATION, value, MOD_PRIORITY, scope, formatManager);
    } catch (IllegalArgumentException iae) {
        return new ParseResult.Fail(getTokenName() + " Modifier " + MOD_IDENTIFICATION + " had value " + value + " but it was not valid: " + iae.getMessage(), context);
    }
    OrderedPair pair = modifier.process(null);
    if (pair.getPreciseX().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but first item cannot be negative", context);
    }
    if (pair.getPreciseY().doubleValue() < 0.0) {
        return new ParseResult.Fail(getTokenName() + " had value " + value + " but second item cannot be negative", context);
    }
    if (!context.getVariableContext().isLegalVariableID(scope, VAR_NAME)) {
        return new ParseResult.Fail(getTokenName() + " internal error: found invalid var name: " + VAR_NAME + ", Modified on " + race.getClass().getSimpleName() + ' ' + race.getKeyName(), context);
    }
    VarModifier<OrderedPair> vm = new VarModifier<>(VAR_NAME, scope, modifier);
    context.getObjectContext().addToList(race, ListKey.MODIFY, vm);
    return ParseResult.SUCCESS;
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) ParseResult(pcgen.rules.persistence.token.ParseResult) LegalScope(pcgen.base.formula.base.LegalScope) VarModifier(pcgen.cdom.content.VarModifier) OrderedPair(pcgen.base.math.OrderedPair) FormatManager(pcgen.base.util.FormatManager)

Aggregations

LegalScope (pcgen.base.formula.base.LegalScope)20 ScopeInstance (pcgen.base.formula.base.ScopeInstance)8 ParseResult (pcgen.rules.persistence.token.ParseResult)8 VarModifier (pcgen.cdom.content.VarModifier)4 Test (org.junit.Test)3 VariableID (pcgen.base.formula.base.VariableID)3 VariableLibrary (pcgen.base.formula.base.VariableLibrary)3 SimpleNode (pcgen.base.formula.parse.SimpleNode)3 FormatManager (pcgen.base.util.FormatManager)3 Equipment (pcgen.core.Equipment)3 LoadContext (pcgen.rules.context.LoadContext)3 VariableContext (pcgen.rules.context.VariableContext)3 FormulaSemantics (pcgen.base.formula.base.FormulaSemantics)2 SimpleScopeInstance (pcgen.base.formula.inst.SimpleScopeInstance)2 ReconstructionVisitor (pcgen.base.formula.visitor.ReconstructionVisitor)2 SemanticsVisitor (pcgen.base.formula.visitor.SemanticsVisitor)2 OrderedPair (pcgen.base.math.OrderedPair)2 ParsingSeparator (pcgen.base.text.ParsingSeparator)2 Campaign (pcgen.core.Campaign)2 ConsolidatedListCommitStrategy (pcgen.rules.context.ConsolidatedListCommitStrategy)2