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 bool ParseProperties(UssToken token) { if (token.IsIgnoreable) { return(false); } if (propertyState == PropertyParsingState.Key && token.type == UssTokenType.RightBracket) { state = ParsingState.Root; return(true); } if (propertyState == PropertyParsingState.Key) { if (token.type == UssTokenType.ValueRef) { bundles.Add(token.body.Substring(1)); if (GetNextToken().type == UssTokenType.SemiColon) { WasteNextToken(); } else { throw new UssUnexpectedTokenException(GetNextToken(), UssTokenType.SemiColon); } } else if (token.type == UssTokenType.Id) { propertyValues = new List <UssValue>(); propertyKey = token.body; propertyState = PropertyParsingState.Colon; } else { throw new InvalidOperationException("Invalid token `" + token.body + "`. (expected Id)"); } } else if (propertyState == PropertyParsingState.Colon) { if (token.type != UssTokenType.Colon) { throw new InvalidOperationException("Invalid token `" + token.body + "`. (expected Colon)"); } propertyState = PropertyParsingState.Value; } else { if (token.IsValue) { propertyValues.Add(UssValue.Create(token)); } else if (token.type == UssTokenType.SemiColon) { properties.Add(new UssStyleProperty() { key = propertyKey, values = propertyValues.ToArray() }); propertyState = PropertyParsingState.Key; } else { throw new InvalidOperationException("Invalid token `" + token.body + "`. (expected Value)"); } } return(false); }