コード例 #1
0
ファイル: Converter_Block.cs プロジェクト: thulyacloud/go2cs
        public override void EnterBlock(GoParser.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++;
        }
コード例 #2
0
ファイル: Converter_Block.cs プロジェクト: thulyacloud/go2cs
        public override void ExitBlock(GoParser.BlockContext context)
        {
            IndentLevel--;

            GoParser.StatementListContext statementListContext = context.statementList();

            if (statementListContext.statement().Length > 0)
            {
                m_firstStatementIsReturn = statementListContext.statement(0).returnStmt() != null;
            }

            if (m_blockInnerSuffixInjection.Count > 0)
            {
                m_targetFile.Append(m_blockInnerSuffixInjection.Pop());
            }

            if (!EndsWithLineFeed(m_targetFile.ToString()))
            {
                m_targetFile.AppendLine();
            }

            m_targetFile.Append($"{Spacing()}}}");

            if (m_blockOuterSuffixInjection.Count > 0)
            {
                m_targetFile.Append(m_blockOuterSuffixInjection.Pop());
            }

            if (!m_firstTopLevelDeclaration && IndentLevel > 2)
            {
                m_targetFile.Append(CheckForCommentsRight(context));
            }

            PopBlock();
        }