Example #1
0
        private IBfsArray ConvertArrayExtension(PegNode node)
        {
            EBinaryFileSchemaParser type = GetNodeId(node);

            if (type != EBinaryFileSchemaParser.arrayknown && type != EBinaryFileSchemaParser.arrayunknown)
                throw new AstConvertException("Must be an array extension! : " + GetNodeText(node));

            //Known sized array extensions
            if (type == EBinaryFileSchemaParser.arrayknown)
            {
                BfsKnownArray knownarray = new BfsKnownArray();
                StoreSourceRange(node, knownarray);
                knownarray.Expression = ConvertExpression(node.child_);

                return knownarray;
            }
            //Unknown sized
            else
            {
                BfsUnknownArray unknownarray = new BfsUnknownArray();
                StoreSourceRange(node, unknownarray);
                unknownarray.UntilSourceRange = GetSourceRange(node.child_);
                for (PegNode stopcasenode = node.child_.next_; stopcasenode != null; stopcasenode = stopcasenode.next_)
                {
                    IBfsStopCase stopcase = null;

                    if (GetNodeId(stopcasenode) == EBinaryFileSchemaParser.stopcase)
                    {
                        switch( GetNodeId(stopcasenode.child_) )
                        {
                            case EBinaryFileSchemaParser.p_string:
                                BfsStopCaseString stopstring = new BfsStopCaseString();
                                stopstring.StopString = GetNodeText(stopcasenode.child_);
                                stopcase = stopstring;
                                break;
                            case EBinaryFileSchemaParser.EOF:
                                stopcase = new BfsStopCaseEndOfFile();
                                break;
                            case EBinaryFileSchemaParser.hex:
                                BfsStopCaseHex stophex = new BfsStopCaseHex();
                                stophex.HexString = GetNodeText(stopcasenode.child_);
                                stopcase = stophex;
                                break;
                            default:
                                throw new Exception("Unknown stopcase type : " + GetNodeId(stopcasenode.child_));
                        }
                        stopcase.Inclusion = BfsInclusionEnum.Skipped;
                        stopcase.SourceRange = GetSourceRange(stopcasenode.child_);

                        //Inclusion and consumption
                        for (PegNode bnode = stopcasenode.child_.next_; bnode != null; bnode = bnode.next_)
                        {
                            if (GetNodeId(bnode) == EBinaryFileSchemaParser.inclusion)
                            {
                                stopcase.InclusionSourceRange = GetSourceRange(bnode);

                                if (GetNodeText(bnode) == "included")
                                    stopcase.Inclusion = BfsInclusionEnum.Included;
                                else if (GetNodeText(bnode) == "excluded")
                                    stopcase.Inclusion = BfsInclusionEnum.Excluded;
                                else if (GetNodeText(bnode) == "skipped")
                                    stopcase.Inclusion = BfsInclusionEnum.Skipped;
                            }
                        }
                        unknownarray.StopCases.Add(stopcase);
                    }
                    else if (GetNodeId(stopcasenode) == EBinaryFileSchemaParser.or_keyword)
                        unknownarray.OrWords.Add(GetSourceRange(stopcasenode));
                }

                return unknownarray;
            }
        }