Search in sources :

Example 1 with VariableContext

use of pcgen.rules.context.VariableContext in project pcgen by PCGen.

the class SourceFileLoader method defineBuiltinVariables.

private void defineBuiltinVariables(LoadContext context) {
    if (!ControlUtilities.hasControlToken(context, CControl.FACE)) {
        VariableContext varContext = context.getVariableContext();
        FormatManager<?> opManager = context.getReferenceContext().getFormatManager("ORDEREDPAIR");
        defineVariable(varContext, opManager, "Face");
    }
}
Also used : VariableContext(pcgen.rules.context.VariableContext)

Example 2 with VariableContext

use of pcgen.rules.context.VariableContext in project pcgen by PCGen.

the class InfoVarsLst method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject cdo, String value) {
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (pipeLoc == -1) {
        return new ParseResult.Fail(getTokenName() + " expecting '|', format is: InfoName|Info value was: " + value, context);
    }
    String key = value.substring(0, pipeLoc);
    //key length 0 caught by charAt(0) test above
    String[] val = value.substring(pipeLoc + 1).split("\\|");
    VariableContext varContext = context.getVariableContext();
    for (String name : val) {
        LegalScope scope = context.getActiveScope().getLegalScope();
        if (!varContext.isLegalVariableID(scope, name)) {
            return new ParseResult.Fail(getTokenName() + " found an error. " + name + " is not a legal variable name in scope " + scope.getName() + " in " + cdo.getClass().getSimpleName() + ' ' + cdo.getKeyName(), context);
        }
    }
    CaseInsensitiveString cis = new CaseInsensitiveString(key);
    context.getObjectContext().put(cdo, MapKey.INFOVARS, cis, val);
    return ParseResult.SUCCESS;
}
Also used : LegalScope(pcgen.base.formula.base.LegalScope) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString) VariableContext(pcgen.rules.context.VariableContext) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString)

Example 3 with VariableContext

use of pcgen.rules.context.VariableContext in project pcgen by PCGen.

the class LocalToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, DatasetVariable dv, String value) {
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (pipeLoc == -1) {
        return new ParseResult.Fail(getTokenName() + " expected 2 pipe delimited arguments, found no pipe: " + value);
    }
    if (pipeLoc != value.lastIndexOf(Constants.PIPE)) {
        return new ParseResult.Fail(getTokenName() + " expected only 2 pipe delimited arguments, found: " + value);
    }
    String fullscope = value.substring(0, pipeLoc);
    String fvName = value.substring(pipeLoc + 1);
    String format;
    String varName;
    int equalLoc = fvName.indexOf('=');
    if (equalLoc != fvName.lastIndexOf('=')) {
        return new ParseResult.Fail(getTokenName() + " expected only 2 equal delimited arguments, found: " + value);
    }
    if (equalLoc == -1) {
        //Defaults to NUMBER
        format = "NUMBER";
        varName = fvName;
    } else {
        format = fvName.substring(0, equalLoc);
        varName = fvName.substring(equalLoc + 1);
    }
    if (dv.getDisplayName() != null) {
        return new ParseResult.Fail(getTokenName() + " must be the first token on the line");
    }
    VariableContext varContext = context.getVariableContext();
    FormatManager<?> formatManager;
    try {
        formatManager = context.getReferenceContext().getFormatManager(format);
    } catch (IllegalArgumentException e) {
        return new ParseResult.Fail(getTokenName() + " does not support format " + format + ", found in " + value + " due to " + e.getMessage());
    }
    LegalScope lvs = varContext.getScope(fullscope);
    if (!DatasetVariable.isLegalName(varName)) {
        return new ParseResult.Fail(varName + " is not a valid variable name");
    }
    boolean legal = varContext.assertLegalVariableID(lvs, formatManager, varName);
    if (!legal) {
        Set<LegalScope> known = varContext.getKnownLegalScopes(varName);
        StringBuilder sb = new StringBuilder();
        for (LegalScope v : known) {
            sb.append(v.getName());
            sb.append(", ");
        }
        return new ParseResult.Fail(getTokenName() + " found a var defined in incompatible variable scopes: " + varName + " was requested in " + fullscope + " but was previously in " + sb.toString(), context);
    }
    dv.setName(varName);
    dv.setFormat(format);
    dv.setScopeName(fullscope);
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) LegalScope(pcgen.base.formula.base.LegalScope) VariableContext(pcgen.rules.context.VariableContext)

Example 4 with VariableContext

use of pcgen.rules.context.VariableContext in project pcgen by PCGen.

the class ChannelToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, DatasetVariable dv, String value) {
    int pipeLoc = value.indexOf(Constants.PIPE);
    if (pipeLoc == -1) {
        return new ParseResult.Fail(getTokenName() + " expected 2 pipe delimited arguments, found no pipe: " + value);
    }
    if (pipeLoc != value.lastIndexOf(Constants.PIPE)) {
        return new ParseResult.Fail(getTokenName() + " expected only 2 pipe delimited arguments, found: " + value);
    }
    String fullscope = value.substring(0, pipeLoc);
    String fvName = value.substring(pipeLoc + 1);
    String format;
    String varName;
    int equalLoc = fvName.indexOf('=');
    if (equalLoc != fvName.lastIndexOf('=')) {
        return new ParseResult.Fail(getTokenName() + " expected only 2 equal delimited arguments, found: " + value);
    }
    if (equalLoc == -1) {
        //Defaults to NUMBER
        format = "NUMBER";
        varName = fvName;
    } else {
        format = fvName.substring(0, equalLoc);
        varName = fvName.substring(equalLoc + 1);
    }
    if (dv.getDisplayName() != null) {
        return new ParseResult.Fail(getTokenName() + " must be the first token on the line");
    }
    VariableContext varContext = context.getVariableContext();
    FormatManager<?> formatManager;
    try {
        formatManager = context.getReferenceContext().getFormatManager(format);
    } catch (IllegalArgumentException e) {
        return new ParseResult.Fail(getTokenName() + " does not support format " + format + ", found in " + value + " due to " + e.getMessage());
    }
    LegalScope lvs;
    if ("GLOBAL".equals(fullscope)) {
        lvs = context.getActiveScope().getLegalScope();
    } else {
        lvs = varContext.getScope(fullscope);
    }
    if (!DatasetVariable.isLegalName(varName)) {
        return new ParseResult.Fail(varName + " is not a valid channel name");
    }
    String channelName = ChannelUtilities.createVarName(varName);
    boolean legal = varContext.assertLegalVariableID(lvs, formatManager, channelName);
    if (!legal) {
        Set<LegalScope> known = varContext.getKnownLegalScopes(varName);
        StringBuilder sb = new StringBuilder();
        for (LegalScope v : known) {
            sb.append(v.getName());
            sb.append(", ");
        }
        return new ParseResult.Fail(getTokenName() + " found a var defined in incompatible variable scopes: " + varName + " was requested in " + fullscope + " but was previously in " + sb.toString(), context);
    }
    dv.setName(channelName);
    dv.setFormat(format);
    dv.setScopeName(fullscope);
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) LegalScope(pcgen.base.formula.base.LegalScope) VariableContext(pcgen.rules.context.VariableContext)

Aggregations

VariableContext (pcgen.rules.context.VariableContext)4 LegalScope (pcgen.base.formula.base.LegalScope)3 ParseResult (pcgen.rules.persistence.token.ParseResult)2 CaseInsensitiveString (pcgen.base.lang.CaseInsensitiveString)1