private void SpriteSheetParseLoop(SpriteSheetNode rootNode) { while (tokenStream.HasMoreTokens && !AdvanceIfTokenType(StyleTokenType.BracesClose)) { StyleToken typeToken = tokenStream.Current; string optionName = AssertTokenTypeAndAdvance(StyleTokenType.Identifier).ToLower(); bool typeFound = false; for (int index = 0; index < s_SpriteSheetOptionNames.Length; index++) { string name = s_SpriteSheetOptionNames[index].Item1; if (name == optionName) { AssertTokenTypeAndAdvance(StyleTokenType.EqualSign); StyleToken variableToken = tokenStream.Current; PropertyNode propertyNode = StyleASTNodeFactory.PropertyNode(s_SpriteSheetOptionNames[index].Item2); propertyNode.AddChildNode(ParsePropertyValue()); propertyNode.WithLocation(variableToken); rootNode.AddChildNode(propertyNode); typeFound = true; break; } } if (!typeFound) { throw new ParseException(typeToken, $"{optionName} is not a supported spritesheet option. Valid values are: {FormatOptionList(s_SpriteSheetOptionNames)}\n"); } AssertTokenTypeAndAdvance(StyleTokenType.EndStatement); } }
private void ParseProperty(StyleNodeContainer styleRootNode, bool parsingKeyframes = false) { StyleToken propertyNodeToken = tokenStream.Current; string propertyName; if (AdvanceIfTokenType(StyleTokenType.Cursor)) { propertyName = propertyNodeToken.value; } else if (AdvanceIfTokenType(StyleTokenType.Run)) { styleRootNode.AddChildNode(ParseRunNode(RunCommandType.Enter, RunAction.Run)); return; } else if (AdvanceIfTokenType(StyleTokenType.Pause)) { styleRootNode.AddChildNode(ParseRunNode(RunCommandType.Enter, RunAction.Pause)); return; } else if (AdvanceIfTokenType(StyleTokenType.Stop)) { styleRootNode.AddChildNode(ParseRunNode(RunCommandType.Enter, RunAction.Stop)); return; } else if (AdvanceIfTokenType(StyleTokenType.BracketOpen)) { if (TryParseCommand(styleRootNode)) { return; } throw new ParseException(tokenStream.Current, "Not sure what you tried here but at this point only [enter] and [exit] run animation would be legal."); } else { propertyName = AssertTokenTypeAndAdvance(StyleTokenType.Identifier); if (propertyName == "material" || propertyName == "Material") { if (tokenStream.Current == StyleTokenType.Colon) { tokenStream.Advance(); string materialName = AssertTokenTypeAndAdvance(StyleTokenType.Identifier); AssertTokenTypeAndAdvance(StyleTokenType.Dot); string materialPropertyName = AssertTokenTypeAndAdvance(StyleTokenType.Identifier); AssertTokenTypeAndAdvance(StyleTokenType.EqualSign); TextUtil.StringBuilder.Clear(); while (tokenStream.HasMoreTokens && tokenStream.Current != StyleTokenType.EndStatement) { TextUtil.StringBuilder.Append(tokenStream.Current.value); tokenStream.Advance(); } tokenStream.Advance(); MaterialPropertyNode materialPropertyNode = new MaterialPropertyNode { materialName = materialName, identifier = materialPropertyName, value = TextUtil.StringBuilder.ToString() }; TextUtil.StringBuilder.Clear(); materialPropertyNode.WithLocation(propertyNodeToken); styleRootNode.AddChildNode(materialPropertyNode); return; } } } AssertTokenTypeAndAdvance(StyleTokenType.EqualSign); PropertyNode propertyNode = StyleASTNodeFactory.PropertyNode(propertyName); propertyNode.WithLocation(propertyNodeToken); while (tokenStream.HasMoreTokens && !AdvanceIfTokenType(StyleTokenType.EndStatement)) { propertyNode.AddChildNode(ParsePropertyValue()); // we just ignore the comma for now AdvanceIfTokenType(StyleTokenType.Comma); } styleRootNode.AddChildNode(propertyNode); }