Exemplo 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;
            }
        }
Exemplo n.º 2
0
        protected virtual void ParseStatements(ParserContext context)
        {
            bool validToken;

            do
            {
                var token = context.PeekNextToken();
                switch (token.Text)
                {
                case "DEF":
                case "USE":
                case "PROTO":
                case "EXTERNPROTO":
                case "ROUTE":
                    validToken = true;
                    ParseStatement(context);
                    break;

                default:
                    if (token.Type == VRML97TokenType.Word)
                    {
                        ParseStatement(context);
                        validToken = true;
                    }
                    else
                    {
                        validToken = false;
                    }
                    break;
                }
            } while (validToken);
        }
Exemplo n.º 3
0
        protected virtual void ParseStatement(ParserContext context)
        {
            var token = context.PeekNextToken();

            switch (token.Text)
            {
            case "DEF":
            case "USE":
                ParseNodeStatement(context);
                break;

            case "PROTO":
            case "EXTERNPROTO":
                ParseProtoStatement(context);
                break;

            case "ROUTE":
                ParseRouteStatement(context);
                break;

            default:
                if (token.Type == VRML97TokenType.Word)
                {
                    ParseNodeStatement(context);
                }
                else
                {
                    throw new Exception("Unexpected context");
                }
                break;
            }
        }
Exemplo n.º 4
0
        public void visit(SFNode field)
        {
            VRML97Token token = context.PeekNextToken();

            switch (token.Text)
            {
            case "NULL":
                field.Node = null;
                break;

            default:
                context.PushNodeContainer(field);
                nodeStatementParser(context);
                context.PopNodeContainer();
                break;
            }
        }
Exemplo 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;
            }
        }
Exemplo n.º 6
0
        protected virtual void ParseRootNodeStatement(ParserContext context)
        {
            var token = context.PeekNextToken();

            switch (token.Text)
            {
            case "DEF":
                ParseDefNodeStatement(context);
                break;

            default:
                ParseNode(context);
                break;
            }
        }
Exemplo n.º 7
0
        protected virtual void ParseNodeBody(ParserContext context)
        {
            var validToken = true;

            do
            {
                var token = context.PeekNextToken();
                if (token.Type == VRML97TokenType.Word)
                {
                    ParseNodeBodyElement(context);
                }
                else
                {
                    validToken = false;
                }
            } while (validToken);
        }
Exemplo n.º 8
0
        protected virtual void ParseProtoStatement(ParserContext context)
        {
            var keyword = context.PeekNextToken();

            switch (keyword.Text)
            {
            case "PROTO":
                ParseProto(context);
                break;

            case "EXTERNPROTO":
                ParseExternProto(context);
                break;

            default:
                //todo: context.throw? with line number?
                throw new InvalidVRMLSyntaxException("PROTO or EXTERNPROTO expected");
            }
        }
Exemplo n.º 9
0
        public virtual void ParseProtoStatements(ParserContext context)
        {
            var validToken = true;

            do
            {
                var token = context.PeekNextToken();
                switch (token.Text)
                {
                case "PROTO":
                case "EXTERNPROTO":
                    ParseProtoStatement(context);
                    break;

                default:
                    validToken = false;
                    break;
                }
            } while (validToken);
        }
Exemplo n.º 10
0
        protected virtual void ParseNodeStatement(ParserContext context)
        {
            var token = context.PeekNextToken();

            switch (token.Text)
            {
            case "DEF":
                ParseDefNodeStatement(context);
                break;

            case "USE":
                var useStatement = UseStatement.Parse(context);
                var node         = context.FindNode(useStatement.NodeName);
                context.AcceptChild(node);
                break;

            default:
                ParseNode(context);
                break;
            }
        }
Exemplo n.º 11
0
 protected virtual void ParseStatement(ParserContext context) {
     var token = context.PeekNextToken();
     switch (token.Text) {
         case "DEF":
         case "USE":
             ParseNodeStatement(context);
             break;
         case "PROTO":
         case "EXTERNPROTO":
             ParseProtoStatement(context);
             break;
         case "ROUTE":
             ParseRouteStatement(context);
             break;
         default:
             if (token.Type == VRML97TokenType.Word) {
                 ParseNodeStatement(context);
             } else {
                 throw new Exception("Unexpected context");
             }
             break;
     }
 }
Exemplo n.º 12
0
 protected virtual void ParseStatements(ParserContext context) {
     bool validToken;
     do {
         var token = context.PeekNextToken();
         switch (token.Text) {
             case "DEF":
             case "USE":
             case "PROTO":
             case "EXTERNPROTO":
             case "ROUTE":
                 validToken = true;
                 ParseStatement(context);
                 break;
             default:
                 if (token.Type == VRML97TokenType.Word) {
                     ParseStatement(context);
                     validToken = true;
                 } else {
                     validToken = false;
                 }
                 break;
         }
     } while (validToken);
 }
Exemplo n.º 13
0
 protected virtual void ParseProtoStatement(ParserContext context) {
     var keyword = context.PeekNextToken();
     switch (keyword.Text) {
         case "PROTO":
             ParseProto(context);
             break;
         case "EXTERNPROTO":
             ParseExternProto(context);
             break;
         default:
             //todo: context.throw? with line number?
             throw new InvalidVRMLSyntaxException("PROTO or EXTERNPROTO expected");
     }
 }
Exemplo n.º 14
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;
            }
        }
Exemplo n.º 15
0
 public virtual void ParseProtoStatements(ParserContext context) {
     var validToken = true;
     do {
         var token = context.PeekNextToken();
         switch (token.Text) {
             case "PROTO":
             case "EXTERNPROTO":
                 ParseProtoStatement(context);
                 break;
             default:
                 validToken = false;
                 break;
         }
     } while (validToken);
 }
Exemplo n.º 16
0
 protected virtual void ParseNodeBody(ParserContext context) {
     var validToken = true;
     do {
         var token = context.PeekNextToken();
         if (token.Type == VRML97TokenType.Word) {
             ParseNodeBodyElement(context);
         } else {
             validToken = false;
         }
     } while (validToken);
 }
Exemplo n.º 17
0
 protected virtual void ParseRootNodeStatement(ParserContext context) {
     var token = context.PeekNextToken();
     switch (token.Text) {
         case "DEF":
             ParseDefNodeStatement(context);
             break;
         default:
             ParseNode(context);
             break;
     }
 }
Exemplo n.º 18
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;
     }
 }
Exemplo n.º 19
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;
     }
 }
Exemplo n.º 20
0
 protected virtual void ParseNodeStatement(ParserContext context) {
     var token = context.PeekNextToken();
     switch (token.Text) {
         case "DEF":
             ParseDefNodeStatement(context);
             break;
         case "USE":
             var useStatement = UseStatement.Parse(context);
             var node = context.FindNode(useStatement.NodeName);
             context.AcceptChild(node);
             break;
         default:
             ParseNode(context);
             break;
     }
 }
Exemplo n.º 21
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;
     }
 }