private void ParseValues(UssToken token) { if (token.IsIgnoreable) { return; } if (token.type == UssTokenType.SemiColon) { if (valueState != ValueParsingState.End) { throw new UssUnexpectedTokenException(token); } state = ParsingState.Root; return; } if (valueState == ValueParsingState.Key) { if (token.type != UssTokenType.ValueRef) { throw new UssUnexpectedTokenException(token, UssTokenType.ValueRef); } valueKey = token.body.Substring(1); valueState = ValueParsingState.Colon; } else if (valueState == ValueParsingState.Colon) { if (token.type == UssTokenType.LeftBracket) { state = ParsingState.Properties; nodeType = CurrentNodeType.Bundle; } else if (token.type == UssTokenType.Colon) { valueState = ValueParsingState.Value; } else { throw new UssUnexpectedTokenException(token); } } else if (valueState == ValueParsingState.Value) { if (token.IsValue == false) { throw new UssUnexpectedTokenException(token); } values.Add(valueKey, UssValue.Create(token)); valueState = ValueParsingState.End; } }
private void ParseConditions(UssToken token) { if (token.IsIgnoreable) { return; } if (token.type == UssTokenType.LeftBracket) { state = ParsingState.Properties; nodeType = CurrentNodeType.Style; return; } // Every types of token can be accepted here // since name of the Unity's gameobject can contain almost characters. // (ex: Zu!ZU##!) var rawCondition = token.body; var styleCondition = new UssStyleCondition(); // CLASS if (rawCondition[0] == '.') { styleCondition.target = UssStyleTarget.Class; styleCondition.name = rawCondition.Substring(1); } // NAME else if (rawCondition[0] == '#') { styleCondition.target = UssStyleTarget.Name; styleCondition.name = rawCondition.Substring(1); } else { styleCondition.target = UssStyleTarget.Component; styleCondition.name = rawCondition; } conditions.Add(styleCondition); }
private void ParseConditions(UssToken token) { if (token.IsIgnoreable) { return; } if (token.type == UssTokenType.LeftBracket) { state = ParsingState.Properties; nodeType = CurrentNodeType.Style; return; } if (token.type == UssTokenType.RightArrow) { if (conditions.Count == 0) { throw new UssUnexpectedTokenException(token); } nextConditionType = UssStyleConditionType.DirectDescendant; return; } if (token.type == UssTokenType.Colon) { if (conditions.Count == 0) { throw new UssUnexpectedTokenException(token); } if (GetNextToken(true).type != UssTokenType.Id) { throw new UssUnexpectedTokenException(GetNextToken(), UssTokenType.Id); } conditions.Last().targetState = GetNextToken().body; WasteNextToken(); return; } // Every types of token can be accepted here // since name of the Unity's gameobject can contain almost characters. // (ex: Zu!ZU##!) var rawCondition = token.body; var styleCondition = new UssStyleCondition(); if (rawCondition[0] == '*') { styleCondition.target = UssSelectorType.All; styleCondition.name = "*"; } // CLASS else if (rawCondition[0] == '.') { styleCondition.target = UssSelectorType.Class; styleCondition.name = rawCondition.Substring(1); } // NAME else if (rawCondition[0] == '#') { styleCondition.target = UssSelectorType.Name; styleCondition.name = rawCondition.Substring(1); } else { styleCondition.target = UssSelectorType.Component; styleCondition.name = rawCondition; } styleCondition.type = nextConditionType; conditions.Add(styleCondition); nextConditionType = UssStyleConditionType.None; }