MCPcopy Create free account
hub / github.com/PCGen/pcgen / parseToken

Method parseToken

code/src/java/plugin/lsttokens/DefineLst.java:47–114  ·  view source on GitHub ↗
(LoadContext context, CDOMObject obj, String value)

Source from the content-addressed store, hash-verified

45 }
46
47 @Override
48 public ParseResult parseToken(LoadContext context, CDOMObject obj, String value)
49 {
50 if (obj instanceof Ungranted)
51 {
52 return new ParseResult.Fail(
53 "Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName());
54 }
55 ParsingSeparator sep = new ParsingSeparator(value, '|');
56 sep.addGroupingPair('[', ']');
57 sep.addGroupingPair('(', ')');
58
59 if (!sep.hasNext())
60 {
61 return new ParseResult.Fail(getTokenName() + " may not be empty");
62 }
63 String firstItem = sep.next();
64
65 if (firstItem.startsWith("UNLOCK."))
66 {
67 return new ParseResult.Fail(
68 "DEFINE:UNLOCK. has been deprecated, " + "please use DEFINESTAT:STAT| or DEFINESTAT:UNLOCK|");
69 }
70 if (!sep.hasNext())
71 {
72 return new ParseResult.Fail(
73 getTokenName() + " varName|varFormula" + "or LOCK.<stat>|value syntax requires an argument");
74 }
75 if (firstItem.isEmpty())
76 {
77 return new ParseResult.Fail("Empty Variable Name found in " + getTokenName() + ": " + value);
78 }
79 try
80 {
81 Formula f = FormulaFactory.getFormulaFor(sep.next());
82 if (!f.isValid())
83 {
84 return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + f.toString());
85 }
86 if ((!f.isStatic() || f.resolveStatic().intValue() != 0) && !(firstItem.startsWith("MAXLEVELSTAT=")))
87 {
88 Logging.deprecationPrint(
89 "DEFINE with a non zero value has been deprecated, "
90 + "please use a DEFINE of 0 and an appropriate bonus. Tag was DEFINE:" + value + " in " + obj,
91 context);
92 }
93 if (sep.hasNext())
94 {
95 return new ParseResult.Fail(
96 getTokenName() + ' ' + firstItem + " syntax requires only one argument: " + value);
97 }
98 if (value.startsWith("LOCK."))
99 {
100 return new ParseResult.Fail(
101 "DEFINE:LOCK. has been deprecated, " + "please use DEFINESTAT:LOCL| or DEFINESTAT:NONSTAT|");
102 }
103 else
104 {

Callers

nothing calls this directly

Calls 15

getTokenNameMethod · 0.95
addGroupingPairMethod · 0.95
hasNextMethod · 0.95
nextMethod · 0.95
getFormulaForMethod · 0.95
isValidMethod · 0.95
isStaticMethod · 0.95
resolveStaticMethod · 0.95
deprecationPrintMethod · 0.95
getConstantMethod · 0.95
getSimpleNameMethod · 0.80
intValueMethod · 0.80

Tested by

no test coverage detected