Exemplo n.º 1
0
        public void Test_3_5_9_HashedStrings_A()
        {
            // Scaled decimals
            Scanner lexer = this.GetLexer("#'Smalltalk'");
            object  obj   = lexer.GetToken();

            Assert.IsInstanceOfType(obj, typeof(HashedStringToken));
            HashedStringToken token = (HashedStringToken)obj;

            Assert.IsTrue(token.IsValid);
            Assert.IsNull(token.ScanError);
            Assert.AreEqual(0, token.StartPosition.Position);
            Assert.AreEqual(11, token.StopPosition.Position);
            Assert.AreEqual("Smalltalk", token.Value);

            // Should be the last one
            obj = lexer.GetToken();
            Assert.IsInstanceOfType(obj, typeof(EofToken));

            lexer = this.GetLexer("#'Über\n\tSmalltalk'");
            obj   = lexer.GetToken();
            Assert.IsInstanceOfType(obj, typeof(HashedStringToken));
            token = (HashedStringToken)obj;
            Assert.IsTrue(token.IsValid);
            Assert.IsNull(token.ScanError);
            Assert.AreEqual(0, token.StartPosition.Position);
            Assert.AreEqual(17, token.StopPosition.Position);
            Assert.AreEqual("Über\n\tSmalltalk", token.Value);

            // Should be the last one
            obj = lexer.GetToken();
            Assert.IsInstanceOfType(obj, typeof(EofToken));
        }
Exemplo n.º 2
0
        public void Test_3_5_9_HashedStrings_C()
        {
            // Scaled decimals
            Scanner lexer = this.GetLexer("#'Smalltalk ''");
            object  obj   = lexer.GetToken();

            Assert.IsInstanceOfType(obj, typeof(HashedStringToken));
            HashedStringToken token = (HashedStringToken)obj;

            Assert.IsFalse(token.IsValid);
            Assert.AreEqual("Missing closing ' quote in string literal. Hit EOF.", token.ScanError);
            Assert.AreEqual(0, token.StartPosition.Position);
            Assert.AreEqual(14, token.StopPosition.Position);
        }
        protected virtual ClassDefinitionNode ParseClassDefinition()
        {
            // TODO : Move constants out of code into a the InterchangeFormatConstants class
            // TODO : Move error messages out of code into a the InterchangeFormatErrors class

            // PARSE: <classDefinition> ::= ’Class’ ’named:’ <classNameString>
            //      ’superclass:’ <superclassNameString>
            //      ’indexedInstanceVariables:’ <indexableInstVarType>
            //      ’instanceVariableNames:’ <instanceVariableNames>
            //      ’classVariableNames:’ <classVariableList>
            //      ’sharedPools:’ <poolList>
            //      ’classInstanceVariableNames:’<classInstVariableList>
            //      <elementSeparator>
            ClassDefinitionNode result = this.CreateClassDefinitionNode();

            Token       token = this.GetNextTokenxx();
            StringToken str   = token as StringToken;

            if (str == null)
            {
                this.ReportParserError(result, "Missing class name.", token);
            }
            str = this.VerifyIdentifierString(str, "Class name not an identifier.");
            result.ClassName = str;

            // ’superclass:’ <superclassNameString>
            token = this.GetNextTokenxx();
            KeywordToken cmd = token as KeywordToken;

            if ((cmd == null) || (cmd.Value != "superclass:"))
            {
                this.ReportParserError("Missing class definition #superclass: keyword.", token);
            }
            token = this.GetNextTokenxx();
            str   = token as StringToken;
            if (str == null)
            {
                this.ReportParserError(result, "Missing superclass name.", token);
            }
            else if (str.Value.Length != 0) // It's OK to have empry superclass .... Object does
            {
                str = this.VerifyIdentifierString(str, "Superclass name not an identifier");
            }
            result.SuperclassName = str;

            // ’indexedInstanceVariables:’ <indexableInstVarType>
            token = this.GetNextTokenxx();
            cmd   = token as KeywordToken;
            if ((cmd == null) || (cmd.Value != "indexedInstanceVariables:"))
            {
                this.ReportParserError("Missing class definition #indexedInstanceVariables: keyword.", token);
            }
            token = this.GetNextTokenxx();
            HashedStringToken hstr = token as HashedStringToken;

            if (hstr == null)
            {
                this.ReportParserError(result, "Missing indexed instance variables type.", token);
            }
            result.IndexedInstanceVariables = hstr;

            // ’instanceVariableNames:’ <instanceVariableNames>
            token = this.GetNextTokenxx();
            cmd   = token as KeywordToken;
            if ((cmd == null) || (cmd.Value != "instanceVariableNames:"))
            {
                this.ReportParserError("Missing class definition #instanceVariableNames: keyword.", token);
            }
            token = this.GetNextTokenxx();
            str   = token as StringToken;
            if (str == null)
            {
                this.ReportParserError(result, "Missing instance variable names.", token);
            }
            str = this.VerifyIdentifierList(str, "Instance variable names list contains non-identifiers.");
            result.InstanceVariableNames = str;

            // ’classVariableNames:’ <classVariableList>
            token = this.GetNextTokenxx();
            cmd   = token as KeywordToken;
            if ((cmd == null) || (cmd.Value != "classVariableNames:"))
            {
                this.ReportParserError("Missing class definition #classVariableNames: keyword.", token);
            }
            token = this.GetNextTokenxx();
            str   = token as StringToken;
            if (str == null)
            {
                this.ReportParserError(result, "Missing class variable names.", token);
            }
            str = this.VerifyIdentifierList(str, "Class variable names list contains non-identifiers.");
            result.ClassVariableNames = str;

            // ’sharedPools:’ <poolList>
            token = this.GetNextTokenxx();
            cmd   = token as KeywordToken;
            if ((cmd == null) || (cmd.Value != "sharedPools:"))
            {
                this.ReportParserError("Missing class definition #sharedPools: keyword.", token);
            }
            token = this.GetNextTokenxx();
            str   = token as StringToken;
            if (str == null)
            {
                this.ReportParserError(result, "Missing shared pool names.", token);
            }
            str = this.VerifyIdentifierList(str, "Shared pool names list contains non-identifiers.");
            result.SharedPools = str;

            // ’classInstanceVariableNames:’<classInstVariableList>
            token = this.GetNextTokenxx();
            cmd   = token as KeywordToken;
            if ((cmd == null) || (cmd.Value != "classInstanceVariableNames:"))
            {
                this.ReportParserError("Missing class definition #classInstanceVariableNames: keyword.", token);
            }
            token = this.GetNextTokenxx();
            str   = token as StringToken;
            if (str == null)
            {
                this.ReportParserError(result, "Missing class instance variable names.", token);
            }
            str = this.VerifyIdentifierList(str, "Class instance variable names list contains non-identifiers.");
            result.ClassInstanceVariableNames = str;

            token = this.GetNextTokenxx();
            if (!(token is EofToken))
            {
                this.ReportParserError(result, "Unexpected code found after class definition.", token);
            }

            return(result);
        }