public CodeBlock(Guid guid, CodeBlockType type, ProtoCore.Language langId, int cbID, SymbolTable symbols, ProcedureTable procTable, bool isBreakableBlock = false, ProtoCore.Core core = null) { this.guid = guid; blockType = type; parent = null; children = new List <CodeBlock>(); language = langId; instrStream = new InstructionStream(langId, core); symbolTable = symbols; procedureTable = procTable; isBreakable = isBreakableBlock; core.CompleteCodeBlockList.Add(this); this.codeBlockId = core.CompleteCodeBlockList.Count - 1; symbols.RuntimeIndex = this.codeBlockId; if (core.ProcNode != null) { core.ProcNode.ChildCodeBlocks.Add(codeBlockId); } }
private void ProcessCodeBlock(Match match, CodeBlockType blockType) { ProcessLiteral(match.Index); var code = match.Groups["code"]; var isEncode = match.Groups["encode"].Success; var startPos = code.Index; var endPos = code.Index + code.Length; // trim whitespaces at the start while (startPos < endPos && char.IsWhiteSpace(text[startPos])) { ++startPos; } // trim whitespaces at the end while (startPos < endPos && char.IsWhiteSpace(text[endPos - 1])) { --endPos; } var codeText = text.Substring(startPos, endPos - startPos).Replace("%\\>", "%>"); var location = CreateLocation(startPos, endPos); eventListener.OnCodeBlock(location, blockType, codeText, isEncode); if (blockType == CodeBlockType.Code) { ignoreNextSpaceString = true; } }
protected CodeContainerComposite(CodeBlockType nodeType, int contexts, CEmmitableCodeContainer parent) : base(nodeType, parent) { m_repository = new List <CEmmitableCodeContainer> [contexts]; for (int i = 0; i < contexts; i++) { m_repository[i] = new List <CEmmitableCodeContainer>(); } }
internal CodeBlockBuilder(CodeBlockType blockType, string content, int lineNumber, int column, VirtualPath virtualPath) { this._content = content; this._blockType = blockType; this._column = column; base.Line = lineNumber; base.VirtualPath = virtualPath; }
internal CodeBlockBuilder(CodeBlockType blockType, string content, int lineNumber, int column, VirtualPath virtualPath) { this._content = content; this._blockType = blockType; this._column = column; base.Line = lineNumber; base.VirtualPath = virtualPath; }
protected CComboContainer(CodeBlockType nodeType, CEmmitableCodeContainer parent, int numcontexts) : base(nodeType, parent) { m_repository = new List <CEmmitableCodeContainer> [numcontexts]; for (int i = 0; i < numcontexts; i++) { m_repository[i] = new List <CEmmitableCodeContainer>(); } }
internal CodeBlockBuilder(CodeBlockType blockType, string content, int lineNumber, string sourceFileName) { _content = content; _blockType = blockType; _line = lineNumber; _sourceFileName = sourceFileName; }
internal CodeBlockBuilder(CodeBlockType blockType, string content, int lineNumber, int column, VirtualPath virtualPath, bool encode) { _content = content; _blockType = blockType; _column = column; IsEncoded = encode; Line = lineNumber; VirtualPath = virtualPath; }
private static void Log(Status status, string message, CodeBlockType codeBlockType, ExceptionInfo exception) { Log(new LogEventInfo { Status = status, Message = message, CodeBlockType = codeBlockType, Exception = exception }); }
internal CodeBlockBuilder(CodeBlockType blockType, string content, int lineNumber, int column, VirtualPath virtualPath, bool encode) { _content = content; _blockType = blockType; _column = column; IsEncoded = encode; Line = lineNumber; VirtualPath = virtualPath; }
/// <summary> /// Clears generated blocks and reverts code iteration progress to initial state. /// Unformatted code will NOT be cleared (Use SetCode("") for that). /// </summary> public void Clear() { generatedBlocks.Clear(); index = 0; nextIndex = 1; currentBlockStart = 0; isEscapeSequence = false; currentType = CodeBlockType.Default; lineCount = 0; }
protected virtual void AddCodeBlock(Match match, CodeBlockType type, string text) { ProcessLiteral(); Group group = match.Groups["code"]; string s = group.Value.Replace(@"%\>", "%>"); int lineNumber = _lineNumber; if (type != CodeBlockType.Code) { int length = -1; for (int i = 0; (i < s.Length && Char.IsWhiteSpace(s[i])); ++i) { if ((s[i] == '\r' || s[i] == '\n') && (i == 0 || s[i - 1] != '\r')) { lineNumber++; length = i; } else if (s[i] == '\n') { length = i; } } if (length >= 0) { s = s.Substring(length + 1); } length = -1; for (int j = s.Length - 1; j >= 0 && Char.IsWhiteSpace(s[j]); j--) { if (s[j] == '\r' || s[j] == '\n') { length = j; } } if (length >= 0) { s = s.Substring(0, length); } if (IsWhiteSpaceString(s)) { throw Error.EmptyCodeRenderExpression(_virtualPath, text, _lineNumber + 1); } } Expressions.Add(new CodeBlockExpression(type, s)); }
public CodeBlock(CodeBlockType type, ProtoCore.Language langId, int codeBlockId, SymbolTable symbols, ProcedureTable procTable, bool isBreakableBlock = false, ProtoLanguage.CompileStateTracker compileState = null) { blockType = type; parent = null; children = new List <CodeBlock>(); language = langId; this.codeBlockId = codeBlockId; instrStream = new InstructionStream(langId, compileState); symbolTable = symbols; procedureTable = procTable; isBreakable = isBreakableBlock; }
public CodeBlock(CodeBlockType type, ProtoCore.Language langId, int codeBlockId, SymbolTable symbols, ProcedureTable procTable, bool isBreakableBlock = false, ProtoCore.Core core = null) { blockType = type; parent = null; children = new List<CodeBlock>(); language = langId; this.codeBlockId = codeBlockId; instrStream = new InstructionStream(langId, core); symbolTable = symbols; procedureTable = procTable; isBreakable = isBreakableBlock; }
/// <summary> Ends current block at current index and adds it to generatedBlocks. </summary> protected void EndBlock() { int blockLength = index - currentBlockStart; if (blockLength == 0) { return; } if (currentBlockStart < 0 || blockLength < 0 || index > length) { if (index < 0) { UnityEngine.Debug.LogError("EndBlock(" + currentType + ") - blockStart=" + currentBlockStart + ", blockLength=" + blockLength + ", index=" + index + ", length=" + length + " with generatedBlocks:\n" + generatedBlocks); return; } UnityEngine.Debug.LogError("EndBlock(" + currentType + ") - blockStart=" + currentBlockStart + ", blockLength=" + blockLength + ", index=" + index + ", length=" + length + " with generatedBlocks:\n" + generatedBlocks); while (index >= length) { index--; } if (index <= currentBlockStart) { return; } } #if DEV_MODE && DEBUG_ENABLED UnityEngine.Debug.Log("EndBlock(" + currentType + ") - blockStart=" + currentBlockStart + ", blockLength=" + blockLength + ", index=" + index + ", length=" + length + " with block: \"" + codeUnformatted.Substring(currentBlockStart, blockLength) + "\""); #endif generatedBlocks.Add(new CodeBlock(textUnformatted.Substring(currentBlockStart, blockLength), currentType)); currentBlockStart = index; currentType = CodeBlockType.Default; }
void IParserEventListener.OnCodeBlock(Location location, CodeBlockType blockType, string code, bool isEncode) { switch (blockType) { case CodeBlockType.Code: currentNode.AddChild(new AspxNode.CodeRender(code, location)); break; case CodeBlockType.Expression: currentNode.AddChild(new AspxNode.CodeRenderExpression(code, location)); break; case CodeBlockType.DataBinding: currentNode.AddChild(new AspxNode.DataBinding(code, location)); break; case CodeBlockType.EncodedExpression: currentNode.AddChild(new AspxNode.CodeRenderEncode(code, location)); break; default: throw new ArgumentOutOfRangeException(nameof(blockType), blockType, null); } }
public static void Pass(string message, CodeBlockType codeBlockType = CodeBlockType.None) { Log(Status.Pass, message, codeBlockType, null); }
public static void Warning(string message, CodeBlockType codeBlockType = CodeBlockType.None, ExceptionInfo exception = null) { Log(Status.Warning, message, codeBlockType, exception); }
internal CodeBlockBuilder(CodeBlockType blockType, string content, int lineNumber, int column, VirtualPath virtualPath) : this(blockType, content, lineNumber, column, virtualPath, false) { }
public CForStatement(CodeBlockType nodeType, int contexts, CEmmitableCodeContainer parent) : base(nodeType, contexts, parent) { }
public CCFunctionDefinition(CodeBlockType nodeType, int contexts, CEmmitableCodeContainer parent) : base(nodeType, contexts, parent) { }
public CodeBlockExpression(CodeBlockType type, string code) : base(TemplateExpressionType.CodeBlock) { _blockType = type; _code = code; }
public CFile(CodeBlockType nodeType, int contexts, CEmmitableCodeContainer parent) : base(nodeType, contexts, parent) { m_mainFunctionDefinition = new CMainFunctionDefinition(this); AddCode(m_mainFunctionDefinition, CFile.CB_FUNDEFS); }
public static void Info(string message, CodeBlockType codeBlockType = CodeBlockType.None) { Log(Status.Info, message, codeBlockType, null); }
internal CodeBlockBuilder(CodeBlockType blockType, string content, int lineNumber, int column, VirtualPath virtualPath) : this(blockType, content, lineNumber, column, virtualPath, false) { }
/* * Handle <%= ... %>, <%# ... %> and <% ... %> blocks */ private void ProcessCodeBlock(Match match, CodeBlockType blockType, string text) { // Take care of the previous literal string ProcessLiteral(); // Get the piece of code Group codeGroup = match.Groups["code"]; string code = codeGroup.Value; bool encode = match.Groups["encode"].Success; // Replace "%\>" with "%>" (ASURT 7175) code = code.Replace(@"%\>", "%>"); int lineNumber = _lineNumber; int column = -1; if (blockType != CodeBlockType.Code) { // It a <%= %>, <%# %> or <%: %> block. We need to do special handling of newline chars // If there are newlines in the beginning of the code string we need to get rid of them, // and adjust the line pragma accordingly. This is needed because some compilers (like VB) // don't support multiline expression (ASURT 13662) int newlineIndex = -1; for (int i = 0; i < code.Length && Char.IsWhiteSpace(code[i]); i++) { if (code[i] == '\r' || (code[i] == '\n' && (i == 0 || code[i - 1] != '\r'))) { lineNumber++; newlineIndex = i; } else if (code[i] == '\n') { newlineIndex = i; } } if (newlineIndex >= 0) { // If we found some newlines in the beginning, get rid of them. Note // that we preserve the spaces, to get correct column information code = code.Substring(newlineIndex + 1); // The code starts at column 1 (since we keep the spaces) column = 1; } // Same deal for the end of the string: look for the first newline // after the last non-blank chararacter newlineIndex = -1; for (int i = code.Length - 1; i >= 0 && Char.IsWhiteSpace(code[i]); i--) { if (code[i] == '\r' || code[i] == '\n') newlineIndex = i; } // And if we found one, remove it and everything after if (newlineIndex >= 0) code = code.Substring(0, newlineIndex); // Disallow empty expressions (ASURT 40124) // Do not treat as error in CBM. This is necessary so we still generate // code blocks for empty expressions. (VSWhidbey 406212) if (!IgnoreParseErrors && Util.IsWhiteSpaceString(code)) { ProcessError(SR.GetString(SR.Empty_expression)); return; } } if (column < 0) { // It a <% %> block. Newline chars are not a problem. // Look for the last newline before the code string int newlineIndex = text.LastIndexOfAny(s_newlineChars, codeGroup.Index-1); // Use it to calculate the column where the code starts, // which improves the debugging experience (VSWhidbey 87172) column = codeGroup.Index-newlineIndex; Debug.Assert(column > 0); } ControlBuilder builder = ((BuilderStackEntry) BuilderStack.Peek())._builder; ControlBuilder subBuilder; // First, give the PageParserFilter a chance to handle the code block if (!PageParserFilterProcessedCodeBlock(CodeConstructTypeFromCodeBlockType(blockType), code, lineNumber)) { // Make sure it's legal to have code in this page EnsureCodeAllowed(); // Add the code block to the top builder subBuilder = new CodeBlockBuilder(blockType, code, lineNumber, column, CurrentVirtualPath, encode); AppendSubBuilder(builder, subBuilder); // Optionally record code block position data ParseRecorders.RecordCodeBlock(subBuilder, match); } // Always ignore the spaces after a <% ... %> block if (blockType == CodeBlockType.Code) flags[ignoreNextSpaceString] = true; }
/// <summary> /// A CodeBlock represents a body of DS code /// </summary> /// <param name="guid"></param> /// <param name="type"></param> /// <param name="langId"></param> /// <param name="cbID"></param> /// <param name="symbols"></param> /// <param name="procTable"></param> /// <param name="isBreakableBlock"></param> /// <param name="core"></param> public CodeBlock(Guid guid, CodeBlockType type, ProtoCore.Language langId, int cbID, SymbolTable symbols, ProcedureTable procTable, bool isBreakableBlock = false, ProtoCore.Core core = null) { this.guid = guid; blockType = type; parent = null; children = new List<CodeBlock>(); language = langId; instrStream = new InstructionStream(langId, core); symbolTable = symbols; procedureTable = procTable; isBreakable = isBreakableBlock; core.CompleteCodeBlockList.Add(this); this.codeBlockId = core.CompleteCodeBlockList.Count - 1; symbols.RuntimeIndex = this.codeBlockId; if (core.ProcNode != null) { core.ProcNode.ChildCodeBlocks.Add(codeBlockId); } }
/// <summary> /// Moves to inspect the next character in the unformatted code /// and detects changes to the current CodeBlock. When a new code /// block is discovered, the previous one is added to the codeBlockGroup. </summary> /// <returns> False if end of code was reached, true if not. </returns> public virtual bool ReadNextCharForCodeBlock() { if (index >= length) { EndBlock(); return(false); } currentChar = textUnformatted[index]; int charCount; switch (currentType) { case CodeBlockType.CommentBlock: if (IsCommentBlockEnd()) { AddToIndex(2); EndBlock(); break; } charCount = IsLineEnd(); if (charCount != -1) { LineBreak(charCount); break; } NextIndex(); break; //both comment line and preprocessor directive //are effective until next line break case CodeBlockType.CommentLine: case CodeBlockType.PreprocessorDirective: charCount = IsLineEnd(); if (charCount != -1) { EndBlock(); LineBreak(charCount); break; } NextIndex(); break; case CodeBlockType.String: if (IsStringEnd()) { NextIndex(); EndBlock(); isEscapeSequence = false; break; } if (IsEscapeSequence()) { isEscapeSequence = true; NextIndex(); break; } isEscapeSequence = false; //if this happens the MonoScript should have a compile error //but still it could happen charCount = IsLineEnd(); if (charCount != -1) { EndBlock(); //reset the type since it's an error, to prevent possibly all the rest of the code being syntax highlighted as a string LineBreak(charCount); break; } NextIndex(); break; case CodeBlockType.Char: if (IsCharEnd()) { NextIndex(); EndBlock(); isEscapeSequence = false; break; } if (IsEscapeSequence()) { isEscapeSequence = true; NextIndex(); break; } isEscapeSequence = false; //if this happens it's an error //but still it could happen charCount = IsLineEnd(); if (charCount != -1) { LineBreak(charCount); break; } NextIndex(); break; case CodeBlockType.Type: //List, MyClass case CodeBlockType.Keyword: //ref, class, string... charCount = IsWhiteSpace(); if (charCount != -1) { EndBlock(); if (IsLineEnd() != -1) { LineBreak(charCount); } break; } if (IsSpecialCharacter()) { EndBlock(); NextIndex(); break; } NextIndex(); break; case CodeBlockType.Number: if (IsNumber()) { NextIndex(); break; } EndBlock(); currentType = CodeBlockType.Default; break; default: if (IsCommentBlockStart()) { EndBlock(); AddToIndex(2); currentType = CodeBlockType.CommentBlock; break; } if (IsCommentLineStart()) { EndBlock(); AddToIndex(2); currentType = CodeBlockType.CommentLine; break; } if (IsStringStart()) { EndBlock(); NextIndex(); currentType = CodeBlockType.String; break; } if (IsCharStart()) { EndBlock(); NextIndex(); currentType = CodeBlockType.Char; break; } if (IsPreprocessorDirectiveStart()) { EndBlock(); NextIndex(); currentType = CodeBlockType.PreprocessorDirective; break; } charCount = IsLineEnd(); if (charCount != -1) { LineBreak(charCount); break; } charCount = IsKeyword(); if (charCount != -1) { EndBlock(); AddToIndex(charCount); currentType = CodeBlockType.Keyword; EndBlock(); break; } charCount = IsType(); if (charCount != -1) { if (index + charCount > length) { UnityEngine.Debug.LogError("IsType returned charCount " + charCount + " but index " + index + " + charCount was more than length " + length); NextIndex(); break; } EndBlock(); AddToIndex(charCount); currentType = CodeBlockType.Type; EndBlock(); break; } if (IsNumber()) { EndBlock(); currentType = CodeBlockType.Number; NextIndex(); break; } NextIndex(); break; } return(true); }
public CodeBlock(string content, CodeBlockType type) { this.type = type; this.content = content; }
public CodeContainer(CodeBlockType nodeType, CEmmitableCodeContainer parent) : base(nodeType, parent) { }
// Map a CodeBlockType to the equivalent CodeConstructType private static CodeConstructType CodeConstructTypeFromCodeBlockType(CodeBlockType blockType) { switch (blockType) { case CodeBlockType.Code: return CodeConstructType.CodeSnippet; case CodeBlockType.Expression: return CodeConstructType.ExpressionSnippet; case CodeBlockType.EncodedExpression: return CodeConstructType.EncodedExpressionSnippet; case CodeBlockType.DataBinding: return CodeConstructType.DataBindingSnippet; default: Debug.Assert(false); return CodeConstructType.CodeSnippet; } }
public CodeBlock(Instruction first, Instruction last, CodeBlockType type = CodeBlockType.Unknown) { this.first = first; this.last = last; this.type = type; }
public CodeBlockExpression(CodeBlockType type, string code) : base(TemplateExpressionType.CodeBlock) { _blockType = type; _code = code; }
protected virtual void AddCodeBlock(Match match, CodeBlockType type, string text) { ProcessLiteral(); Group group = match.Groups["code"]; string s = group.Value.Replace(@"%\>", "%>"); int lineNumber = _lineNumber; if (type != CodeBlockType.Code) { int length = -1; for (int i = 0; (i < s.Length && Char.IsWhiteSpace(s[i])); ++i) { if ((s[i] == '\r' || s[i] == '\n') && (i == 0 || s[i - 1] != '\r')) { lineNumber++; length = i; } else if (s[i] == '\n') length = i; } if (length >= 0) s = s.Substring(length + 1); length = -1; for (int j = s.Length - 1; j >= 0 && Char.IsWhiteSpace(s[j]); j--) { if (s[j] == '\r' || s[j] == '\n') length = j; } if (length >= 0) s = s.Substring(0, length); if (IsWhiteSpaceString(s)) throw Error.EmptyCodeRenderExpression(_virtualPath, text, _lineNumber + 1); } Expressions.Add(new CodeBlockExpression(type, s)); }