Esempio n. 1
0
        protected virtual void ParseNode(ParserContext context)
        {
            var token = context.PeekNextToken();

            if (token.Type == VRML97TokenType.EOF)
            {
                return;
            }
            switch (token.Text)
            {
            case "Script":
                ParseScriptNode(context);
                break;

            default:
                var nodeTypeId = ParseNodeTypeId(context);
                var node       = context.CreateNode(nodeTypeId, context.NodeName);
                context.NodeName = null;
                context.PushFieldContainer(node);
                if (context.ReadNextToken().Type != VRML97TokenType.OpenBrace)
                {
                    throw new InvalidVRMLSyntaxException("Open brace expected");
                }
                ParseNodeBody(context);
                if (context.ReadNextToken().Type != VRML97TokenType.CloseBrace)
                {
                    throw new InvalidVRMLSyntaxException();
                }
                context.PopFieldContainer();
                context.AcceptChild(node);
                break;
            }
        }
Esempio n. 2
0
        public void visit(SFBool field)
        {
            string value = context.ReadNextToken().Text;

            switch (value)
            {
            case "TRUE":
                field.Value = true;
                break;

            case "FALSE":
                field.Value = false;
                break;
            }
        }
Esempio n. 3
0
        protected virtual void ParseScriptNode(ParserContext context)
        {
            var keyword = context.ReadNextToken();

            if (keyword.Text != "Script")
            {
                throw new InvalidVRMLSyntaxException("Script expected");
            }
            context.ReadOpenBrace();
            ParseScriptBody(context);
            context.ReadCloseBrace();
        }
Esempio n. 4
0
        protected virtual void ParseProto(ParserContext context)
        {
            context.ReadKeyword("PROTO");

            var proto = new ProtoNode {
                name = ParseNodeNameId(context)
            };

            context.PushNodeContainer(proto.children);
            context.PushFieldContainer(proto);
            ParseInterfaceDeclarations(context);
            if (context.ReadNextToken().Type != VRML97TokenType.OpenBrace)
            {
                throw new InvalidVRMLSyntaxException();
            }
            ParseProtoBody(context);
            if (context.ReadNextToken().Type != VRML97TokenType.CloseBrace)
            {
                throw new InvalidVRMLSyntaxException();
            }
            context.PopFieldContainer();
            context.PopNodeContainer();
            context.RegisterPtototype(proto);
        }
Esempio n. 5
0
        protected virtual void ParseNodeBodyElement(ParserContext context)
        {
            var node = context.FieldContainer;

            if (node == null)
            {
                throw new Exception("Invalid context");
            }
            var token = context.PeekNextToken();

            switch (token.Text)
            {
            case "ROUTE":
                ParseRouteStatement(context);
                break;

            case "PROTO":
                ParseProto(context);
                break;
            }
            string fieldId = ParseFieldId(context);

            token = context.PeekNextToken();
            //TODO: get field type and parse depending on it.
            switch (token.Text)
            {
            case "IS":
                token = context.ReadNextToken();
                string interfaceFieldId = ParseFieldId(context);
                //TODO: Process inteface field linking
                break;

            default:
                var field = node.GetExposedField(fieldId);
                field.AcceptVisitor(_fieldParser);
                break;
            }
        }
Esempio n. 6
0
        private void ParseRestrictedInterfaceDeclaration(ParserContext context)
        {
            var node = context.FieldContainer as ProtoNode;

            if (node == null)
            {
                throw new Exception("Unexpected context");
            }
            var accessType = context.ReadNextToken().Text;

            switch (accessType)
            {
            case "eventIn":
                var fieldInType = ParseFieldType(context);
                var eventInId   = ParseEventInId(context);
                //TODO: process interface eventIn declaration.
                break;

            case "eventOut":
                var fieldOutType = ParseFieldType(context);
                var eventOutId   = ParseEventOutId(context);
                //TODO: process interface eventOut declaration.
                break;

            case "field":
                var fieldType = ParseFieldType(context);
                var fieldId   = ParseFieldId(context);
                var field     = context.CreateField(fieldType);
                node.AddField(fieldId, field);
                field.AcceptVisitor(_fieldParser);
                //TODO: process interface field declaration.
                break;

            default:
                throw new Exception("Unexpected context");
            }
        }
Esempio n. 7
0
        protected virtual void ParseScriptBodyElement(ParserContext context)
        {
            var         token   = context.PeekNextToken();
            VRML97Token tokenIs = null;
            string      fieldType;

            switch (token.Text)
            {
            case "eventIn":
                tokenIs = context.PeekNextToken(3);
                if (tokenIs.Text == "IS")
                {
                    token     = context.ReadNextToken();
                    fieldType = ParseFieldType(context);
                    string eventInId1 = ParseEventInId(context);
                    tokenIs = context.ReadNextToken();
                    string eventInId2 = ParseEventInId(context);
                    //TODO: process scipt eventIn element
                }
                else
                {
                    ParseRestrictedInterfaceDeclaration(context);
                }
                break;

            case "eventOut":
                tokenIs = context.PeekNextToken(3);
                if (tokenIs.Text == "IS")
                {
                    token     = context.ReadNextToken();
                    fieldType = ParseFieldType(context);
                    string eventOutId1 = ParseEventOutId(context);
                    tokenIs = context.ReadNextToken();
                    string eventOutId2 = ParseEventOutId(context);
                    //TODO: process scipt eventOut element
                }
                else
                {
                    ParseRestrictedInterfaceDeclaration(context);
                }
                break;

            case "field":
                tokenIs = context.PeekNextToken(3);
                if (tokenIs.Text == "IS")
                {
                    token     = context.ReadNextToken();
                    fieldType = ParseFieldType(context);
                    string fieldId1 = ParseFieldId(context);
                    tokenIs = context.ReadNextToken();
                    string fieldId2 = ParseFieldId(context);
                    //TODO: process scipt field element
                }
                else
                {
                    ParseRestrictedInterfaceDeclaration(context);
                }
                break;

            default:
                if (token.Type == VRML97TokenType.Word)
                {
                    ParseNodeBodyElement(context);
                }
                else
                {
                    throw new Exception("Unexpected context");
                }
                break;
            }
        }
Esempio n. 8
0
 protected virtual void ParseDefNodeStatement(ParserContext context)
 {
     context.ReadNextToken();
     context.NodeName = ParseNodeNameId(context);
     ParseNode(context);
 }
Esempio n. 9
0
        protected virtual void ParseProto(ParserContext context) {
            context.ReadKeyword("PROTO");

            var proto = new ProtoNode {
                name = ParseNodeNameId(context)
            };
            context.PushNodeContainer(proto.children);
            context.PushFieldContainer(proto);
            ParseInterfaceDeclarations(context);
            if (context.ReadNextToken().Type != VRML97TokenType.OpenBrace) {
                throw new InvalidVRMLSyntaxException();
            }
            ParseProtoBody(context);
            if (context.ReadNextToken().Type != VRML97TokenType.CloseBrace) {
                throw new InvalidVRMLSyntaxException();
            }
            context.PopFieldContainer();
            context.PopNodeContainer();
            context.RegisterPtototype(proto);
        }
Esempio n. 10
0
 private static string ParseId(ParserContext context) {
     return context.ReadNextToken().Text;
 }
Esempio n. 11
0
 protected virtual void ParseNodeBodyElement(ParserContext context) {
     var node = context.FieldContainer;
     if (node == null) {
         throw new Exception("Invalid context");
     }
     var token = context.PeekNextToken();
     switch (token.Text) {
         case "ROUTE":
             ParseRouteStatement(context);
             break;
         case "PROTO":
             ParseProto(context);
             break;
     }
     string fieldId = ParseFieldId(context);
     token = context.PeekNextToken();
     //TODO: get field type and parse depending on it.
     switch (token.Text) {
         case "IS":
             token = context.ReadNextToken();
             string interfaceFieldId = ParseFieldId(context);
             //TODO: Process inteface field linking
             break;
         default:
             var field = node.GetExposedField(fieldId);
             field.AcceptVisitor(_fieldParser);
             break;
     }
 }
Esempio n. 12
0
 protected virtual void ParseScriptBodyElement(ParserContext context) {
     var token = context.PeekNextToken();
     VRML97Token tokenIs = null;
     string fieldType;
     switch (token.Text) {
         case "eventIn":
             tokenIs = context.PeekNextToken(3);
             if (tokenIs.Text == "IS") {
                 token = context.ReadNextToken();
                 fieldType = ParseFieldType(context);
                 string eventInId1 = ParseEventInId(context);
                 tokenIs = context.ReadNextToken();
                 string eventInId2 = ParseEventInId(context);
                 //TODO: process scipt eventIn element
             } else {
                 ParseRestrictedInterfaceDeclaration(context);
             }
             break;
         case "eventOut":
             tokenIs = context.PeekNextToken(3);
             if (tokenIs.Text == "IS") {
                 token = context.ReadNextToken();
                 fieldType = ParseFieldType(context);
                 string eventOutId1 = ParseEventOutId(context);
                 tokenIs = context.ReadNextToken();
                 string eventOutId2 = ParseEventOutId(context);
                 //TODO: process scipt eventOut element
             } else {
                 ParseRestrictedInterfaceDeclaration(context);
             }
             break;
         case "field":
             tokenIs = context.PeekNextToken(3);
             if (tokenIs.Text == "IS") {
                 token = context.ReadNextToken();
                 fieldType = ParseFieldType(context);
                 string fieldId1 = ParseFieldId(context);
                 tokenIs = context.ReadNextToken();
                 string fieldId2 = ParseFieldId(context);
                 //TODO: process scipt field element
             } else {
                 ParseRestrictedInterfaceDeclaration(context);
             }
             break;
         default:
             if (token.Type == VRML97TokenType.Word) {
                 ParseNodeBodyElement(context);
             } else {
                 throw new Exception("Unexpected context");
             }
             break;
     }
 }
Esempio n. 13
0
 protected virtual void ParseNode(ParserContext context) {
     var token = context.PeekNextToken();
     if (token.Type == VRML97TokenType.EOF) return;
     switch (token.Text) {
         case "Script":
             ParseScriptNode(context);
             break;
         default:
             var nodeTypeId = ParseNodeTypeId(context);
             var node = context.CreateNode(nodeTypeId, context.NodeName);
             context.NodeName = null;
             context.PushFieldContainer(node);
             if (context.ReadNextToken().Type != VRML97TokenType.OpenBrace) {
                 throw new InvalidVRMLSyntaxException("Open brace expected");
             }
             ParseNodeBody(context);
             if (context.ReadNextToken().Type != VRML97TokenType.CloseBrace) {
                 throw new InvalidVRMLSyntaxException();
             }
             context.PopFieldContainer();
             context.AcceptChild(node);
             break;
     }
 }
Esempio n. 14
0
 protected virtual void ParseScriptNode(ParserContext context) {
     var keyword = context.ReadNextToken();
     if (keyword.Text != "Script") {
         throw new InvalidVRMLSyntaxException("Script expected");
     }
     context.ReadOpenBrace();
     ParseScriptBody(context);
     context.ReadCloseBrace();
 }
Esempio n. 15
0
 private void ParseRestrictedInterfaceDeclaration(ParserContext context) {
     var node = context.FieldContainer as ProtoNode;
     if (node == null) throw new Exception("Unexpected context");
     var accessType = context.ReadNextToken().Text;
     switch (accessType) {
         case "eventIn":
             var fieldInType = ParseFieldType(context);
             var eventInId = ParseEventInId(context);
             //TODO: process interface eventIn declaration.
             break;
         case "eventOut":
             var fieldOutType = ParseFieldType(context);
             var eventOutId = ParseEventOutId(context);
             //TODO: process interface eventOut declaration.
             break;
         case "field":
             var fieldType = ParseFieldType(context);
             var fieldId = ParseFieldId(context);
             var field = context.CreateField(fieldType);
             node.AddField(fieldId, field);
             field.AcceptVisitor(_fieldParser);
             //TODO: process interface field declaration.
             break;
         default:
             throw new Exception("Unexpected context");
     }
 }
Esempio n. 16
0
 private static string ParseId(ParserContext context)
 {
     return(context.ReadNextToken().Text);
 }
Esempio n. 17
0
 protected virtual void ParseDefNodeStatement(ParserContext context) {
     context.ReadNextToken();
     context.NodeName = ParseNodeNameId(context);
     ParseNode(context);
 }