public override void EnterBlock(GolangParser.BlockContext context) { // block // : '{' statementList '}' // statementList // : (statement eos )* PushBlock(); if (m_blockOuterPrefixInjection.Count > 0) { m_targetFile.Append(m_blockOuterPrefixInjection.Pop()); } m_targetFile.Append($"{Spacing()}{{"); if (m_blockInnerPrefixInjection.Count > 0) { m_targetFile.Append(m_blockInnerPrefixInjection.Pop()); } m_targetFile.Append(RemoveFirstDuplicateLineFeed(CheckForCommentsLeft(context.statementList(), 1))); if (!WroteLineFeed) { m_targetFile.AppendLine(); } m_firstStatementIsReturn = false; IndentLevel++; }
public override void ExitBlock(GolangParser.BlockContext context) { IndentLevel--; GolangParser.StatementListContext statementListContext = context.statementList(); if (statementListContext.statement().Length > 0) { m_firstStatementIsReturn = statementListContext.statement(0).returnStmt() != null; } m_targetFile.Append($"{Spacing()}}}"); if (m_blockSuffixInjection.Count > 0) { m_targetFile.Append(m_blockSuffixInjection.Pop()); } if (!m_firstTopLevelDeclaration && IndentLevel > 2) { m_targetFile.Append(CheckForBodyCommentsRight(context)); } PopBlock(); }
public override Base VisitBlock([NotNull] GolangParser.BlockContext context) { var ret = new Block(); var temp = m_currentScope; m_currentScope = ret; var sl = context.statement_list().Accept(this) as StatementList; m_currentScope = temp; while (sl.NumChildren() > 0) { ret.AddChild(sl.GetChild <Statement>(0)); } return(ret); }
public override void EnterBlock(GolangParser.BlockContext context) { // block // : '{' statementList '}' // statementList // : (statement eos )* PushBlock(); if (m_blockPrefixInjection.Count > 0) { m_targetFile.Append(m_blockPrefixInjection.Pop()); } m_targetFile.Append($"{Spacing()}{{"); string comments = CheckForCommentsLeft(context.statementList(), preserveLineFeeds: true); if (!string.IsNullOrEmpty(comments?.Trim())) { m_targetFile.Append($"{(WroteLineFeed ? "" : Environment.NewLine)}{FixForwardSpacing(comments, 1)}"); if (!WroteLineFeed) { m_targetFile.AppendLine(); } } else { m_targetFile.AppendLine(); } m_firstStatementIsReturn = false; IndentLevel++; }