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

Method parseNonEmptyToken

code/src/java/plugin/lsttokens/SpellsLst.java:73–264  ·  view source on GitHub ↗

{@literal SPELLS: |[ ] | [, ] | [, ] |PRExxx |PRExxx CASTERLEVEL= Casterlevel of spells TIMES= Cast Times per day, -1=At Will } @param sourceLine Line from the LST

(LoadContext context, CDOMObject obj, String sourceLine)

Source from the content-addressed store, hash-verified

71 * @return spells list
72 */
73 @Override
74 protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String sourceLine)
75 {
76 if (obj instanceof Ungranted)
77 {
78 return new ParseResult.Fail(
79 "Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName());
80 }
81 if ((sourceLine == null) || sourceLine.isEmpty())
82 {
83 return new ParseResult.Fail("Argument in " + getTokenName() + " cannot be empty");
84 }
85 if (sourceLine.equals(Constants.LST_DOT_CLEAR_ALL))
86 {
87 context.getListContext().removeAllFromList(getTokenName(), obj, Spell.SPELLS);
88 return ParseResult.SUCCESS;
89 }
90 ParsingSeparator sep = new ParsingSeparator(sourceLine, '|');
91 sep.addGroupingPair('[', ']');
92 sep.addGroupingPair('(', ')');
93
94 String spellBook = sep.next();
95 if (spellBook.isEmpty())
96 {
97 return new ParseResult.Fail("SpellBook in " + getTokenName() + " cannot be empty");
98 }
99 // Formula casterLevel = null;
100 String casterLevel = null;
101 String times = null;
102 String timeunit = null;
103
104 if (!sep.hasNext())
105 {
106 return new ParseResult.Fail(getTokenName() + ": minimally requires a Spell Name");
107 }
108 String token = sep.next();
109
110 while (true)
111 {
112 if (token.startsWith("TIMES="))
113 {
114 if (times != null)
115 {
116 return new ParseResult.Fail(
117 "Found two TIMES entries in " + getTokenName() + ": invalid: " + sourceLine);
118 }
119 times = token.substring(6);
120 if (times.isEmpty())
121 {
122 return new ParseResult.Fail("Error in Times in " + getTokenName() + ": argument was empty");
123 }
124 if (!sep.hasNext())
125 {
126 return new ParseResult.Fail(
127 getTokenName() + ": minimally requires " + "a Spell Name (after TIMES=)");
128 }
129 token = sep.next();
130 }

Callers

nothing calls this directly

Calls 15

getTokenNameMethod · 0.95
addGroupingPairMethod · 0.95
nextMethod · 0.95
hasNextMethod · 0.95
putMethod · 0.95
getFormulaForMethod · 0.95
isValidMethod · 0.95
finishMethod · 0.95
getSimpleNameMethod · 0.80
getCDOMReferenceMethod · 0.80
getPrerequisiteMethod · 0.80

Tested by

no test coverage detected