private static void FillTargetAndMethod(IBuffer buffer, OneToSetMap <string, FileID> eventHandlerToScriptTarget) { var lexer = new YamlLexer(buffer, false, false); lexer.Start(); TokenNodeType currentToken; FileID currentTarget = null; string currentMethod = null; while ((currentToken = lexer.TokenType) != null) { if (currentToken == YamlTokenType.NS_PLAIN_ONE_LINE_IN) { var text = buffer.GetText(new TextRange(lexer.TokenStart, lexer.TokenEnd)); lexer.Advance(); SkipWhitespace(lexer); currentToken = lexer.TokenType; if (currentToken == YamlTokenType.COLON) { if (text.Equals("m_Target")) { if (currentMethod != null && currentTarget != null) { eventHandlerToScriptTarget.Add(currentMethod, currentTarget); } lexer.Advance(); currentTarget = GetFileId(buffer, lexer); } else if (text.Equals("m_MethodName")) { Assertion.Assert(currentTarget != null, "currentTarget != null"); lexer.Advance(); currentMethod = GetPrimitiveValue(buffer, lexer); } } } lexer.Advance(); } if (currentMethod != null && currentTarget != null) { eventHandlerToScriptTarget.Add(currentMethod, currentTarget); } }
public static FileID GetFileId(IBuffer buffer) { var lexer = new YamlLexer(buffer, false, false); lexer.Start(); if (lexer.TokenType == YamlTokenType.INDENT) { lexer.Advance(); } SkipWhitespaceAndNewLine(lexer); if (lexer.TokenType == YamlTokenType.LBRACE) { lexer.Advance(); return(GetFileIdInner(buffer, lexer)); } return(null); }
public static void ExtractSimpleAndReferenceValues(IBuffer buffer, Dictionary <string, string> simpleValues, Dictionary <string, FileID> referenceValues) { // special field for accessing anchor id simpleValues["&anchor"] = GetAnchorFromBuffer(buffer); var lexer = new YamlLexer(buffer, true, false); lexer.Start(); TokenNodeType currentToken; bool noColon = true; while ((currentToken = lexer.TokenType) != null) { if (noColon) { if (currentToken == YamlTokenType.COLON) { noColon = false; } if (currentToken == YamlTokenType.NS_PLAIN_ONE_LINE_OUT) { var key = buffer.GetText(new TextRange(lexer.TokenStart, lexer.TokenEnd)); // special filed for checking stripped documents if (key.Equals("stripped")) { simpleValues["stripped"] = "1"; } } } if (currentToken == YamlTokenType.INDENT) { lexer.Advance(); currentToken = lexer.TokenType; if (currentToken == YamlTokenType.NS_PLAIN_ONE_LINE_IN) { var key = buffer.GetText(new TextRange(lexer.TokenStart, lexer.TokenEnd)); lexer.Advance(); SkipWhitespace(lexer); currentToken = lexer.TokenType; if (currentToken == YamlTokenType.COLON) { lexer.Advance(); SkipWhitespace(lexer); currentToken = lexer.TokenType; if (currentToken == YamlTokenType.LBRACE) { lexer.Advance(); var result = GetFileIdInner(buffer, lexer); if (result != null) { referenceValues[key] = result; } } else if (YamlTokenType.CHAMELEON_BLOCK_MAPPING_ENTRY_CONTENT_WITH_ANY_INDENT.Equals(currentToken)) { // sometimes, FileId is multiline var result = GetFileId(ProjectedBuffer.Create(buffer, new TextRange(lexer.TokenStart, lexer.TokenEnd))); if (result != null) { referenceValues[key] = result; } } else { var result = GetPrimitiveValue(buffer, lexer); if (result != null) { simpleValues[key] = result; } } } } else { FindNextIndent(lexer); } } else { lexer.Advance(); } } }
public void AddPrefabModification(IBuffer buffer) { var anchor = UnitySceneDataUtil.GetAnchorFromBuffer(buffer); if (anchor == null) { return; } var lexer = new YamlLexer(buffer, false, false); lexer.Start(); TokenNodeType currentToken; var transformParentId = FileID.Null; while ((currentToken = lexer.TokenType) != null) { if (currentToken == YamlTokenType.INDENT) { var indentSize = lexer.TokenEnd - lexer.TokenStart; lexer.Advance(); currentToken = lexer.TokenType; if (currentToken == YamlTokenType.NS_PLAIN_ONE_LINE_IN) { var text = buffer.GetText(new TextRange(lexer.TokenStart, lexer.TokenEnd)); if (text.Equals(UnityYamlConstants.TransformParentProperty)) { lexer.Advance(); UnitySceneDataUtil.SkipWhitespace(lexer); currentToken = lexer.TokenType; if (currentToken == YamlTokenType.COLON) { lexer.Advance(); var result = UnitySceneDataUtil.GetFileId(buffer, lexer); if (result != null) { transformParentId = result; } } } else if (text.Equals(UnityYamlConstants.ModificationsProperty)) { var names = new Dictionary <FileID, string>(); var rootIndexes = new Dictionary <FileID, int?>(); GetModifications(buffer, lexer, indentSize, names, rootIndexes); var id = new FileID(null, anchor); Elements.Add(id, new ModificationHierarchyElement(id, null, null, false, transformParentId, rootIndexes, names)); return; } } } else { lexer.Advance(); } } }