Beispiel #1
0
        void InterpretBlock(CleanupAstNodeStates cleanStates)
        {
            if (cleanStates[0].Token != TokenKind.OpenCurly)
                return;
            for (var advancePosition = 1; advancePosition < cleanStates.Count - 1; advancePosition++)
            {
                var currentNode = cleanStates.MappedNodes[advancePosition];
                var tokenKind = currentNode.GetTokenKind();
                switch (tokenKind)
                {
                    case TokenKind.TypeName:
                        cleanStates.ShiftVariableDeclaration(advancePosition);
                        break;

                    case TokenKind.Identifier:
                        cleanStates.ShiftInstructionDeclaration(advancePosition);
                        break;
                    case TokenKind.SharpDefine:
                        break;

                    case TokenKind.SharpImport:
                        cleanStates.ShiftSharpImports(advancePosition);
                        break;
                    case TokenKind.SharpProperty:
                    case TokenKind.CloseCurly:
                        break;
                    case TokenKind.None:
                        switch (currentNode.Rule)
                        {
                            case RuleKind.BlockCode:
                                var blockStates = currentNode.States;
                                InterpretBlock(blockStates);
                                break;
                        }
                        break;

                    case TokenKind.Break:
                        cleanStates.ShiftBreak(advancePosition);
                        break;
                    case TokenKind.Continue:
                        cleanStates.ShiftContinue(advancePosition);
                        break;

                    case TokenKind.If:
                    case TokenKind.For:
                    case TokenKind.While:
                        InterpretIf(cleanStates, advancePosition);
                        break;
                    case TokenKind.Switch:
                        InterpretIf(cleanStates, advancePosition);
                        break;
                    case TokenKind.Default:
                        InterpretCase(cleanStates, advancePosition);
                        break;
                    case TokenKind.Case:
                        InterpretCase(cleanStates, advancePosition);
                        break;
                    case TokenKind.Else:
                        InterpretElseWhile(cleanStates, advancePosition);
                        break;
                    case TokenKind.Static:
                        ShiftStaticDefinition(cleanStates, advancePosition);
                        break;
                    case TokenKind.Extern:
                        ShiftExternDefinition(cleanStates, advancePosition);
                        break;
                    case TokenKind.Return:
                        ShiftReturn(cleanStates, advancePosition);
                        break;
                    default:
                        throw new InvalidDataException("Input type not handled");
                }
            }
        }
Beispiel #2
0
 public override void OnVisitMatch(ParseNode node)
 {
     var cleanStates = new CleanupAstNodeStates(node.Parent.Children);
     var advance = cleanStates.MappedNodes.IndexOf(node);
     cleanStates.ShiftBreak(advance);
 }