// subtree gets succ.

    public override TokenSet Init_FollowSet(ParseNode_Root parser, TokenSet succ)
    {
        Init_PreCheckSet(parser);
        FollowSet = succ;
        node.Init_FollowSet(parser, succ);
        return(FirstSet);
    }
示例#2
0
 public void FromArrayWithUnsortedArrayThrows()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         TokenSet.FromArray(new[] { "z", "a" });
     });
 }
示例#3
0
        public void UnicodeTest()
        {
            TokenSet tokens = Tokenizer.Tokenize("N'NOON'");

            Assert.AreEqual(1, tokens.Count);
            Assert.AreEqual("'NOON'", tokens.First.Value);
        }
示例#4
0
        public void Current_MoveNext_CurrentHasValue()
        {
            var tokenSet = new TokenSet(new[] { new Token() });

            tokenSet.MoveNext();
            tokenSet.Current.Should().NotBeNull();
        }
示例#5
0
        public bool TrySetTokens(string?idToken, string?accessToken)
        {
            if (string.IsNullOrEmpty(idToken) || string.IsNullOrEmpty(accessToken))
            {
                return(false);
            }

            if (TryParseJsonPayload(idToken, out var json))
            {
                if (json.RootElement.TryGetProperty("exp", out var expProperty) &&
                    expProperty.TryGetInt64(out long exp))
                {
                    if (DateTimeOffset.FromUnixTimeSeconds(exp) < DateTimeOffset.UtcNow)
                    {
                        return(false);
                    }
                }
                if (json.RootElement.TryGetProperty("preferred_username", out var usernameProperty))
                {
                    UserName = usernameProperty.GetString();
                }

                if (json.RootElement.TryGetProperty("sub", out var userIdProperty))
                {
                    UserId = userIdProperty.GetString();
                }
            }
            Token = accessToken;
            TokenSet?.Invoke();
            return(true);
        }
示例#6
0
        public async Task BuilderBuildsInvertedIndex()
        {
            var builder = new Builder();

            builder.AddField("title");
            await builder.Add(new Document
            {
                { "id", "id" },
                { "title", "test" },
                { "body", "missing" }
            });

            Index index = builder.Build();

            Assert.Empty(builder.InvertedIndex["test"]["title"]["id"]);

            Assert.IsType <Vector>(builder.FieldVectors["title/id"]);

            Assert.False(builder.InvertedIndex.ContainsKey("missing"));

            var needle = TokenSet.FromString("test");

            Assert.Contains("test", builder.TokenSet.Intersect(needle).ToEnumeration());

            Assert.Equal(1, builder.DocumentCount);

            Assert.Equal(1, builder.AverageFieldLength["title"]);

            Assert.NotNull(index);
        }
 // Use this for initialization
 void Start()
 {
     start     = false;
     startTime = 0.0f;
     /* Generate TokenSet base on the information and the template (TokenSet) */
     localSet = new TokenSet(directionList, positionList, tokenTemplate);
 }
示例#8
0
        public void ToEnumerateIncludesSingleWords()
        {
            string word     = "bat";
            var    tokenSet = TokenSet.FromString(word);

            Assert.Equal(new[] { word }, tokenSet.ToEnumeration());
        }
示例#9
0
 // checks for ambiguous lookahead.
 public bool Accepts(TokenSet s)
 {
     if (s.set != null)
     {
         if (set != null)
         {
             var intersection = new BitArray(set);
             intersection = intersection.And(s.set);
             for (var n = 0; n < intersection.Count; ++n)
             {
                 if (intersection[n])
                 {
                     return(true);
                 }
             }
         }
         else if (tokenId >= 0)
         {
             return(s.set[tokenId]);
         }
     }
     else if (s.tokenId >= 0)
     {
         if (set != null)
         {
             return(set[s.tokenId]);
         }
         if (tokenId >= 0)
         {
             return(tokenId == s.tokenId);
         }
     }
     return(false);
 }
 public override TokenSet Init_PreCheckSet(ParseNode_Root parser)
 {
     if (FirstSet == null)
     {
         FirstSet = new TokenSet();
         foreach (var t in nodes)
         {
             if (t is ParseNode_ManyOpt_If)
             {
                 continue;
             }
             var set = t.Init_PreCheckSet(parser);
             if (FirstSet.Accepts(set))
             {
                 Debug.LogError(this + ": ambiguous alternatives");
                 Debug.LogWarning(FirstSet.Intersecton(set).ToString(parser));
             }
             FirstSet.Add(set);
         }
         foreach (var t in nodes)
         {
             if (t is ParseNode_ManyOpt_If)
             {
                 var set = t.Init_PreCheckSet(parser);
                 FirstSet.Add(set);
             }
         }
     }
     return(FirstSet);
 }
示例#11
0
        public void ParseSentence_EmptyTokenSet_NullCommand()
        {
            var tokenSet = new TokenSet();
            var cmd      = _parser.ParseSentence(tokenSet);

            cmd.Should().BeNull();
        }
示例#12
0
 public override TokenSet Init_PreCheckSet(ParseNode_Root parser)
 {
     if (FirstSet == null)
     {
         FirstSet = new TokenSet();
         if (nodes.Count == 0)
         {
             FirstSet.AddEmpty();
         }
         else
         {
             for (int i = 0; i < nodes.Count; ++i)
             {
                 var t   = nodes[i];
                 var set = t.Init_PreCheckSet(parser);
                 FirstSet.Add(set);
                 if (!set.ContainsEmpty())
                 {
                     FirstSet.RemoveEmpty();
                     break;
                 }
             }
         }
     }
     return(FirstSet);
 }
        public async Task <ApiResponse <List <Artist> > > GetArtists(TokenSet tokenSet, List <string> artistIds, bool shouldCache = false)
        {
            var artistList     = new List <Artist>();
            var completedCount = 0;

            while (completedCount != artistIds.Count)
            {
                var currentSet      = artistIds.Skip(completedCount).Take(MAX_ARTIST_LIMIT_VALUE);
                var idString        = string.Join(",", currentSet);
                var artistsResponse = shouldCache ?
                                      await _client.SendAsyncWithCaching <ArtistsWrapper>(tokenSet, HttpMethod.Get, $"artists?ids={idString}") :
                                      await _client.SendAsync <ArtistsWrapper>(tokenSet, HttpMethod.Get, $"artists?ids={idString}");

                if (!artistsResponse.IsSuccessStatusCode)
                {
                    break;
                }

                artistList.AddRange(artistsResponse.Content.Artists);
                completedCount += artistsResponse.Content.Artists.Count;
            }

            return(new ApiResponse <List <Artist> >(HttpStatusCode.OK)
            {
                Content = artistList
            });
        }
示例#14
0
        public void IntersectWithFuzzierStringTranspose()
        {
            var x = TokenSet.FromString("bca");
            var y = TokenSet.FromFuzzyString("abc", 2);

            Assert.Equal(new[] { "bca" }, x.Intersect(y).ToEnumeration());
        }
示例#15
0
 private BlockStatement ParseStatementBlock(TokenSet followers) {
   SourceLocationBuilder slb = new SourceLocationBuilder(this.scanner.CurrentSourceLocation);
   List<Statement> statements = new List<Statement>();
   this.ParseStatements(statements, followers);
   slb.UpdateToSpan(this.scanner.CurrentSourceLocation);
   return new BlockStatement(statements, slb);
 }
示例#16
0
        public void IntersectWithFuzzierStringSubstitution()
        {
            var x = TokenSet.FromString("axx");
            var y = TokenSet.FromFuzzyString("abc", 2);

            Assert.Equal(new[] { "axx" }, x.Intersect(y).ToEnumeration());
        }
示例#17
0
        public async Task ReturnValidTokenWhenExpiredAndRenewAllowed()
        {
            using (var httpTest = new HttpTest())
            {
                // Arrange
                RepositoryEnrichedTokenSet tokenSet = new RepositoryEnrichedTokenSet
                {
                    AthleteId    = "1",
                    AccessToken  = "2",
                    ExpiresAtUtc = DateTime.UtcNow.AddDays(-1),
                    RefreshToken = "3"
                };
                _tokenRepository.GetForAccessToken("1").Returns(tokenSet);
                httpTest.RespondWith(JsonConvert.SerializeObject(new StravaTokenExchangeResponse
                {
                    access_token = "4",
                    athlete      = new TokenExchangeAthlete {
                        id = "1"
                    },
                    expires_at    = (int)DateTime.UtcNow.AddDays(1).Subtract(new DateTime(1970, 1, 1)).TotalSeconds,
                    refresh_token = "5"
                }));

                // Act
                TokenSet result = await _testSubject.GetTokenSetForAccessToken("1", true);

                // Assert
                Assert.Equal("1", result.AthleteId);
                Assert.Equal("4", result.AccessToken);
                httpTest.ShouldHaveCalled(_options.TokenEndPoint);
            }
        }
示例#18
0
        public void ToEnumerationIncludesAllWords()
        {
            string[] words    = new[] { "bat", "cat" };
            var      tokenSet = TokenSet.FromArray(words);

            Assert.True(new HashSet <string>(words).SetEquals(tokenSet.ToEnumeration()));
        }
示例#19
0
 private Statement ParseFor(TokenSet followers)
   //^ requires this.currentToken == Token.For;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   SourceLocationBuilder slb = new SourceLocationBuilder(this.scanner.CurrentSourceLocation);
   this.GetNextToken();
   if (this.currentToken == Token.Each) return this.ParseForEach(slb, followers);
   SmallBasicSimpleName variableName = this.ParseSimpleName(followers|Parser.ExpressionStart|Token.Equals|Token.To|Token.Step|Token.EndOfLine);
   variableName.rootClass = this.rootClass;
   this.Skip(Token.Equals);
   Expression startValue = this.ParseExpression(followers|Parser.ExpressionStart|Token.To|Token.Step|Token.EndOfLine);
   variableName.expressionToInferTargetTypeFrom = startValue;
   SourceLocationBuilder rslb = new SourceLocationBuilder(startValue.SourceLocation);
   this.Skip(Token.To);
   Expression endValue = this.ParseExpression(followers|Parser.ExpressionStart|Token.Step|Token.EndOfLine);
   rslb.UpdateToSpan(endValue.SourceLocation);
   Expression/*?*/ stepValue = null;
   if (this.currentToken == Token.Step) {
     this.GetNextToken();
     stepValue = this.ParseExpression(followers|Token.EndOfLine);
   }
   this.Skip(Token.EndOfLine);
   BlockStatement body = this.ParseStatementBlock(followers|Token.Next);
   slb.UpdateToSpan(body.SourceLocation);
   ForRangeStatement result = new ForRangeStatement(null, variableName, new Range(startValue, endValue, rslb), stepValue, body, slb); //TODO Spec#: Range should not be ambiguous
   this.SkipClosingKeyword(Token.Next, followers);
   return result;
 }
示例#20
0
        public Task <TokenSet> AddOrUpdateTokenSet(TokenSet tokenSet)
        {
            AddOrUpdateTokenSetCount++;

            if (tokenSet is null)
            {
                throw new ArgumentNullException(nameof(tokenSet));
            }

            var existingToken = TokenSets.Find(t => t.Id == tokenSet.Id);

            if (existingToken != null)
            {
                TokenSets.Remove(existingToken);
            }

            if (string.IsNullOrEmpty(tokenSet.Id))
            {
                tokenSet.Id = Guid.NewGuid().ToString();
            }

            TokenSets.Add(tokenSet);

            return(Task.FromResult(tokenSet));
        }
示例#21
0
        public async Task <ApiResponse <T> > SendAsync <T>(TokenSet tokenSet, HttpMethod method, string endpoint)
        {
            var requestUrl = endpoint.Contains("https://") ? endpoint : $"{_config.ApiBaseUri}/{endpoint}";
            var request    = new HttpRequestMessage(method, requestUrl)
            {
                Headers =
                {
                    { "Authorization", $"Bearer {tokenSet.AccessToken}" }
                }
            };
            var response = await _client.SendAsync(request);

            var apiResponse = new ApiResponse <T>(response.StatusCode);

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                apiResponse.Content = JsonConvert.DeserializeObject <T>(content);
            }
            else
            {
                apiResponse.ReasonPhrase = response.ReasonPhrase;
            }

            return(apiResponse);
        }
示例#22
0
        public void TokenSetToStringWritesLeftOperationRight()
        {
            var set = new TokenSet {
                Left = "Left", Operation = "Operation", Right = "Right"
            };

            Assert.AreEqual("Left Operation Right", set.ToString());
        }
示例#23
0
        public void IntersectWithContainedWildcardBacktrackingIntersection()
        {
            var      x = TokenSet.FromString("ababc");
            var      y = TokenSet.FromString("a*bc");
            TokenSet z = x.Intersect(y);

            Assert.Equal(new[] { "ababc" }, z.ToEnumeration());
        }
示例#24
0
        public void IntersectWithContainedWildcardNoIntersection()
        {
            var      x = TokenSet.FromString("foo");
            var      y = TokenSet.FromString("b*r");
            TokenSet z = x.Intersect(y);

            Assert.Empty(z.ToEnumeration());
        }
示例#25
0
        public void IntersectWiildcardMatchesZeroOrMoreCharacters()
        {
            var      x = TokenSet.FromString("foo");
            var      y = TokenSet.FromString("foo*");
            TokenSet z = x.Intersect(y);

            Assert.Equal(new[] { "foo" }, z.ToEnumeration());
        }
示例#26
0
        public void IntersectWithContainedWildcardBacktrackingNoIntersection()
        {
            var      x = TokenSet.FromString("ababc");
            var      y = TokenSet.FromString("a*ac");
            TokenSet z = x.Intersect(y);

            Assert.Empty(z.ToEnumeration());
        }
示例#27
0
        public void IntersectLeadingAndTrailingBacktrackingIntersection()
        {
            var      x = TokenSet.FromString("acbaabab");
            var      y = TokenSet.FromString("*ab*");
            TokenSet z = x.Intersect(y);

            Assert.Equal(new[] { "acbaabab" }, z.ToEnumeration());
        }
示例#28
0
        public void CatastrophicBacktrackingWithLeadingCharacters()
        {
            var      x = TokenSet.FromString("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
            var      y = TokenSet.FromString("*ff");
            TokenSet z = x.Intersect(y);

            Assert.Single(z.ToEnumeration());
        }
示例#29
0
        public void FromStringWithoutWildCard()
        {
            var idProvider = new TokenSetIdProvider();
            var x          = TokenSet.FromString("a", idProvider);

            Assert.Equal("0a2", x.ToString());
            Assert.True(x.Edges['a'].IsFinal);
        }
示例#30
0
        public void IntersectMultipleContainedWildcardBackTracking()
        {
            var      x = TokenSet.FromString("acbaabab");
            var      y = TokenSet.FromString("a*ba*b");
            TokenSet z = x.Intersect(y);

            Assert.Equal(new[] { "acbaabab" }, z.ToEnumeration());
        }
示例#31
0
        public void FromArrayWithSortedArray()
        {
            var tokenSet = TokenSet.FromArray(new[] { "a", "z" });

            Assert.Equal(
                new[] { "a", "z" },
                tokenSet.ToEnumeration().OrderBy(t => t));
        }
示例#32
0
        public void IntersectWithContainedWildcardIntersection()
        {
            var      x = TokenSet.FromString("foo");
            var      y = TokenSet.FromString("f*o");
            TokenSet z = x.Intersect(y);

            Assert.Equal(new[] { "foo" }, z.ToEnumeration());
        }
示例#33
0
 private Statement ParseDo(TokenSet followers)
   //^ requires this.currentToken == Token.Do;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   SourceLocationBuilder slb = new SourceLocationBuilder(this.scanner.CurrentSourceLocation);
   this.GetNextToken();
   this.Skip(Token.While);
   Expression condition = this.ParseExpression(followers|Token.EndOfLine);
   this.Skip(Token.EndOfLine);
   BlockStatement body = this.ParseStatementBlock(followers|Token.Loop);
   slb.UpdateToSpan(this.scanner.CurrentSourceLocation);
   WhileDoStatement result = new WhileDoStatement(condition, body, slb);
   this.SkipClosingKeyword(Token.Loop, followers);
   return result;
 }
示例#34
0
 private void ParseStatements(List<Statement> statements, TokenSet followers)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   while (Parser.StatementStart[this.currentToken]) {
     switch (this.currentToken) {
       case Token.Do: statements.Add(this.ParseDo(followers)); break;
       case Token.For: statements.Add(this.ParseFor(followers)); break;
       case Token.Gosub: statements.Add(this.ParseGosub(followers)); break;
       case Token.Goto: statements.Add(this.ParseGoto(followers)); break;
       case Token.Identifier: statements.Add(this.ParseAssignmentOrCallOrLabel(followers)); break;
       case Token.If: statements.Add(this.ParseIf(followers)); break;
       case Token.Return: statements.Add(this.ParseReturn(followers)); break;
       case Token.EndOfLine: this.GetNextToken(); break;
       default: this.SkipTo(followers); break;
     }
   }
 }
示例#35
0
 protected override Expression ParseBraceLabeledExpression(SourceLocationBuilder slb, TokenSet followers)
 {
     var lab = (VccLabeledExpression)this.ParseLabeledExpression(followers | Token.RightBrace);
       this.Skip(Token.RightBrace);
       var body = this.ParseExpression(followers);
       var labString = lab.Label.Name.Value;
       var labName = new VccByteStringLiteral(labString, lab.Label.SourceLocation);
       var labArg = lab.Expression;
       if (labArg is DummyExpression)
     labArg = new CompileTimeConstant(1, false, lab.Label.SourceLocation);
       if (labString == "use") { // this condition is sort of a hack, it should likely look at some function \lbl_use(...) or something
     labArg = new VccByteStringLiteral(labArg.SourceLocation.Source, labArg.SourceLocation);
       }
       var args = new[] { labName, labArg, body };
       slb.UpdateToSpan(body.SourceLocation);
       return new VccMethodCall(this.GetSimpleNameFor("\\labeled_expression"), args, slb.GetSourceLocation());
 }
示例#36
0
        public void TestCountByName()
        {
            TokenSet a = new TokenSet((IRandom)m_Random.MockInstance);
            a.Name = "a";

            TokenSet a2 = new TokenSet((IRandom)m_Random.MockInstance);
            a2.Name = "a";

            Assert.AreEqual(0, m_TokenSetCollection.CountByName("a"));

            m_TokenSetCollection.Add(a);
            Assert.AreEqual(1, m_TokenSetCollection.CountByName("a"));

            m_TokenSetCollection.Add(a2);
            Assert.AreEqual(2, m_TokenSetCollection.CountByName("a"));

            Assert.AreEqual(0, m_TokenSetCollection.CountByName("b"));
        }
示例#37
0
        public void TestGetByName()
        {
            TokenSet a = new TokenSet((IRandom)m_Random.MockInstance);
            a.Name = "a";

            TokenSet a2 = new TokenSet((IRandom)m_Random.MockInstance);
            a2.Name = "a";

            Assert.IsNull(m_TokenSetCollection.FindByName("a"));

            m_TokenSetCollection.Add(a);
            Assert.AreSame(a, m_TokenSetCollection.FindByName("a"));

            m_TokenSetCollection.Add(a2);
            Assert.AreSame(a, m_TokenSetCollection.FindByName("a"));

            Assert.IsNull(m_TokenSetCollection.FindByName("b"));
        }
示例#38
0
 protected override List<Expression> ParseArgumentList(SourceLocationBuilder slb, TokenSet followers)
 {
     var result = new List<Expression>();
       this.Skip(Token.LeftParenthesis);
       while (this.currentToken != Token.RightParenthesis) {
     if (this.currentToken == Token.Specification) {
       result.Add(this.ParseSpecArgument(followers | Token.Comma | Token.Specification | Token.RightParenthesis));
       continue;
     }
     result.Add(this.ParseArgumentExpression(followers | Token.Comma | Token.Specification | Token.RightParenthesis));
     if (this.currentToken == Token.Comma) {
       this.GetNextToken();
       continue;
     }
     if (this.currentToken == Token.Specification)
       continue;
     break;
       }
       slb.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken);
       this.SkipOverTo(Token.RightParenthesis, followers);
       return result;
 }
示例#39
0
 private void ParseGenericTypeParameterConstraintsClauses(List<Ast.GenericTypeParameterDeclaration> genericTypeParameters, TokenSet followers)
   // ^ requires forall{Ast.GenericTypeParameterDeclaration genericTypeParameter in genericTypeParameters; genericTypeParameter is SpecSharpGenericTypeParameterDeclaration};
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   while (this.currentToken == Token.Where) {
     this.GetNextToken();
     if (!Parser.IdentifierOrNonReservedKeyword[this.currentToken])
       this.HandleError(Error.ExpectedIdentifier);
     NameDeclaration name = this.ParseNameDeclaration();
     SpecSharpGenericTypeParameterDeclaration/*?*/ applicableParameter = null;
     foreach (Ast.GenericTypeParameterDeclaration genericTypeParameter in genericTypeParameters)
       if (genericTypeParameter.Name.UniqueKey == name.UniqueKey) {
         //^ assume genericTypeParameter is SpecSharpGenericTypeParameterDeclaration; //follows from precondition
         applicableParameter = (SpecSharpGenericTypeParameterDeclaration)genericTypeParameter; 
         break; 
       }
     if (applicableParameter == null) {
       this.HandleError(name.SourceLocation, Error.TyVarNotFoundInConstraint);
       applicableParameter = new SpecSharpGenericTypeParameterDeclaration(null, name, (ushort)genericTypeParameters.Count);
     }
     this.Skip(Token.Colon);
     this.ParseGenericTypeParameterConstraints(applicableParameter, followers|Token.Where);
   }
   this.SkipTo(followers);
 }
示例#40
0
 private void SkipSemiColon(TokenSet followers)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   if (this.currentToken == Token.Semicolon) {
     this.GetNextToken();
     this.SkipTo(followers);
   } else {
     this.Skip(Token.Semicolon);
     while (!this.scanner.TokenIsFirstAfterLineBreak && this.currentToken != Token.Semicolon && this.currentToken != Token.RightBrace && this.currentToken != Token.EndOfFile
       && (this.currentToken != Token.LeftBrace || !followers[Token.LeftBrace]))
       this.GetNextToken();
     if (this.currentToken == Token.Semicolon) 
       this.GetNextToken();
     this.SkipTo(followers);
   }
 }
示例#41
0
 private void ParseGenericTypeParameterConstraints(SpecSharpGenericTypeParameterDeclaration applicableParameter, TokenSet followers)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   TokenSet constraintStart = Parser.IdentifierOrNonReservedKeyword|Token.Struct|Token.Class|Token.New;
   if (!constraintStart[this.currentToken]) {
     this.HandleError(Error.TypeExpected);
     this.SkipTo(followers);
     return;
   }
   if (this.currentToken == Token.Class) {
     this.GetNextToken();
     applicableParameter.MustBeReferenceType = true;
   } else if (this.currentToken == Token.Struct) {
     this.GetNextToken();
     applicableParameter.MustBeValueType = true;
   }
   while (constraintStart[this.currentToken]) {
     if (this.currentToken == Token.Class || this.currentToken == Token.Struct) {
       this.HandleError(Error.RefValBoundMustBeFirst);
       this.GetNextToken(); continue;
     } else if (this.currentToken == Token.New) {
       this.GetNextToken();
       this.Skip(Token.LeftParenthesis);
       this.Skip(Token.RightParenthesis);
       applicableParameter.MustHaveDefaultConstructor = true;
       if (this.currentToken == Token.Comma) {
         this.HandleError(Error.NewBoundMustBeLast);
       }
       break;
     }
     //^ assume this.currentToken != Token.EndOfFile;
     applicableParameter.AddConstraint(this.ParseTypeExpression(false, false, constraintStart|Token.Comma|followers));
     if (this.currentToken != Token.Comma) break;
     this.GetNextToken();
   }
   this.SkipTo(followers);
 }
示例#42
0
 private void SkipTo(TokenSet followers)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   if (followers[this.currentToken]) return;
   Error error = Error.InvalidExprTerm;
   if (this.currentToken == Token.Using)
     error = Error.UsingAfterElements;
   else if (!this.insideBlock)
     error = Error.InvalidMemberDecl;
   this.HandleError(error, this.scanner.GetTokenSource());
   while (!followers[this.currentToken] && this.currentToken != Token.EndOfFile)
     this.GetNextToken();
 }
示例#43
0
 private void SkipTo(TokenSet followers, Error error, params string[] messages)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   if (error != Error.None)
     this.HandleError(error, messages);
   while (!followers[this.currentToken] && this.currentToken != Token.EndOfFile)
     this.GetNextToken();
 }
示例#44
0
 private void ParseTypeDeclaration(List<INamespaceDeclarationMember> namespaceMembers, TokenSet followers)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   SourceLocationBuilder sctx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken);
   List<SourceCustomAttribute>/*?*/ attributes = this.ParseAttributes(followers|Parser.AttributeOrTypeDeclarationStart);
   List<ModifierToken> modifiers = this.ParseModifiers();
   TypeDeclaration.Flags flags = this.ConvertToTypeDeclarationFlags(modifiers);
   switch (this.currentToken) {
     case Token.Class:
       this.ParseNamespaceClassDeclaration(namespaceMembers, attributes, flags, sctx, followers); 
       break;
     case Token.Interface:
       this.ParseNamespaceInterfaceDeclaration(namespaceMembers, attributes, flags, sctx, followers); 
       break;
     case Token.Struct:
       this.ParseNamespaceStructDeclaration(namespaceMembers, attributes, flags, sctx, followers); 
       break;
     case Token.Delegate:
       this.ParseNamespaceDelegateDeclaration(namespaceMembers, attributes, flags, sctx, followers);
       break;
     case Token.Enum:
       this.ParseNamespaceEnumDeclaration(namespaceMembers, attributes, flags, sctx, followers);
       break;
     default:
       if (modifiers.Count > 0 || !followers[this.currentToken])
         this.SkipTo(followers, Error.BadTokenInType);
       return;
   }
 }
示例#45
0
文件: TokenSets.cs 项目: DvdKhl/dgrok
        static TokenSets()
        {
            AddOp = new TokenSet("addition operator");
            AddOp.Add(TokenType.PlusSign);
            AddOp.Add(TokenType.MinusSign);
            AddOp.Add(TokenType.OrKeyword);
            AddOp.Add(TokenType.XorKeyword);

            Block = new TokenSet("block");
            Block.Add(TokenType.BeginKeyword);
            Block.Add(TokenType.AsmKeyword);

            ClassDisposition = new TokenSet("class disposition");
            ClassDisposition.Add(TokenType.AbstractSemikeyword);
            ClassDisposition.Add(TokenType.SealedSemikeyword);

            ConstHeader = new TokenSet("const section");
            ConstHeader.Add(TokenType.ConstKeyword);
            ConstHeader.Add(TokenType.ResourceStringKeyword);

            Directive = new TokenSet("directive");
            Directive.Add(TokenType.AbstractSemikeyword);
            Directive.Add(TokenType.AssemblerSemikeyword);
            Directive.Add(TokenType.CdeclSemikeyword);
            Directive.Add(TokenType.DispIdSemikeyword);
            Directive.Add(TokenType.DynamicSemikeyword);
            Directive.Add(TokenType.ExportSemikeyword);
            Directive.Add(TokenType.ExternalSemikeyword);
            Directive.Add(TokenType.FarSemikeyword);
            Directive.Add(TokenType.FinalSemikeyword);
            Directive.Add(TokenType.ForwardSemikeyword);
            Directive.Add(TokenType.InlineKeyword);
            Directive.Add(TokenType.LocalSemikeyword);
            Directive.Add(TokenType.MessageSemikeyword);
            Directive.Add(TokenType.NearSemikeyword);
            Directive.Add(TokenType.OverloadSemikeyword);
            Directive.Add(TokenType.OverrideSemikeyword);
            Directive.Add(TokenType.PascalSemikeyword);
            Directive.Add(TokenType.RegisterSemikeyword);
            Directive.Add(TokenType.ReintroduceSemikeyword);
            Directive.Add(TokenType.SafecallSemikeyword);
            Directive.Add(TokenType.StaticSemikeyword);
            Directive.Add(TokenType.StdcallSemikeyword);
            Directive.Add(TokenType.VarArgsSemikeyword);
            Directive.Add(TokenType.VirtualSemikeyword);
            // also includes PortabilityDirective, see below

            ExportsSpecifier = new TokenSet("'index' or 'name'");
            ExportsSpecifier.Add(TokenType.IndexSemikeyword);
            ExportsSpecifier.Add(TokenType.NameSemikeyword);

            ForDirection = new TokenSet("'to' or 'downto'");
            ForDirection.Add(TokenType.ToKeyword);
            ForDirection.Add(TokenType.DownToKeyword);

            ForwardableType = new TokenSet("forwardable type");
            ForwardableType.Add(TokenType.ClassKeyword);
            ForwardableType.Add(TokenType.DispInterfaceKeyword);
            ForwardableType.Add(TokenType.InterfaceKeyword);

            InitSection = new TokenSet("initialization section");
            InitSection.Add(TokenType.AsmKeyword);
            InitSection.Add(TokenType.BeginKeyword);
            InitSection.Add(TokenType.InitializationKeyword);
            InitSection.Add(TokenType.EndKeyword);

            InterfaceType = new TokenSet("interface type");
            InterfaceType.Add(TokenType.InterfaceKeyword);
            InterfaceType.Add(TokenType.DispInterfaceKeyword);

            Keyword = new TokenSet("keyword");
            Keyword.Add(TokenType.AndKeyword);
            Keyword.Add(TokenType.ArrayKeyword);
            Keyword.Add(TokenType.AsKeyword);
            Keyword.Add(TokenType.AsmKeyword);
            Keyword.Add(TokenType.BeginKeyword);
            Keyword.Add(TokenType.CaseKeyword);
            Keyword.Add(TokenType.ClassKeyword);
            Keyword.Add(TokenType.ConstKeyword);
            Keyword.Add(TokenType.ConstructorKeyword);
            Keyword.Add(TokenType.DestructorKeyword);
            Keyword.Add(TokenType.DispInterfaceKeyword);
            Keyword.Add(TokenType.DivKeyword);
            Keyword.Add(TokenType.DoKeyword);
            Keyword.Add(TokenType.DownToKeyword);
            Keyword.Add(TokenType.ElseKeyword);
            Keyword.Add(TokenType.EndKeyword);
            Keyword.Add(TokenType.ExceptKeyword);
            Keyword.Add(TokenType.ExportsKeyword);
            Keyword.Add(TokenType.FileKeyword);
            Keyword.Add(TokenType.FinalizationKeyword);
            Keyword.Add(TokenType.FinallyKeyword);
            Keyword.Add(TokenType.ForKeyword);
            Keyword.Add(TokenType.FunctionKeyword);
            Keyword.Add(TokenType.GotoKeyword);
            Keyword.Add(TokenType.IfKeyword);
            Keyword.Add(TokenType.ImplementationKeyword);
            Keyword.Add(TokenType.InKeyword);
            Keyword.Add(TokenType.InheritedKeyword);
            Keyword.Add(TokenType.InitializationKeyword);
            Keyword.Add(TokenType.InlineKeyword);
            Keyword.Add(TokenType.InterfaceKeyword);
            Keyword.Add(TokenType.IsKeyword);
            Keyword.Add(TokenType.LabelKeyword);
            Keyword.Add(TokenType.LibraryKeyword);
            Keyword.Add(TokenType.ModKeyword);
            Keyword.Add(TokenType.NilKeyword);
            Keyword.Add(TokenType.NotKeyword);
            Keyword.Add(TokenType.ObjectKeyword);
            Keyword.Add(TokenType.OfKeyword);
            Keyword.Add(TokenType.OrKeyword);
            Keyword.Add(TokenType.PackedKeyword);
            Keyword.Add(TokenType.ProcedureKeyword);
            Keyword.Add(TokenType.ProgramKeyword);
            Keyword.Add(TokenType.PropertyKeyword);
            Keyword.Add(TokenType.RaiseKeyword);
            Keyword.Add(TokenType.RecordKeyword);
            Keyword.Add(TokenType.RepeatKeyword);
            Keyword.Add(TokenType.ResourceStringKeyword);
            Keyword.Add(TokenType.SetKeyword);
            Keyword.Add(TokenType.ShlKeyword);
            Keyword.Add(TokenType.ShrKeyword);
            Keyword.Add(TokenType.StringKeyword);
            Keyword.Add(TokenType.ThenKeyword);
            Keyword.Add(TokenType.ThreadVarKeyword);
            Keyword.Add(TokenType.ToKeyword);
            Keyword.Add(TokenType.TryKeyword);
            Keyword.Add(TokenType.TypeKeyword);
            Keyword.Add(TokenType.UnitKeyword);
            Keyword.Add(TokenType.UntilKeyword);
            Keyword.Add(TokenType.UsesKeyword);
            Keyword.Add(TokenType.VarKeyword);
            Keyword.Add(TokenType.WhileKeyword);
            Keyword.Add(TokenType.WithKeyword);
            Keyword.Add(TokenType.XorKeyword);

            MethodType = new TokenSet("method heading");
            MethodType.Add(TokenType.ConstructorKeyword);
            MethodType.Add(TokenType.DestructorKeyword);
            MethodType.Add(TokenType.FunctionKeyword);
            MethodType.Add(TokenType.ProcedureKeyword);
            MethodType.Add(TokenType.OperatorSemikeyword);

            MulOp = new TokenSet("multiplication operator");
            MulOp.Add(TokenType.TimesSign);
            MulOp.Add(TokenType.DivideBySign);
            MulOp.Add(TokenType.DivKeyword);
            MulOp.Add(TokenType.AndKeyword);
            MulOp.Add(TokenType.ModKeyword);
            MulOp.Add(TokenType.ShlKeyword);
            MulOp.Add(TokenType.ShrKeyword);

            ParameterizedPropertyDirective = new TokenSet("property directive");
            ParameterizedPropertyDirective.Add(TokenType.DefaultSemikeyword);
            ParameterizedPropertyDirective.Add(TokenType.DispIdSemikeyword);
            ParameterizedPropertyDirective.Add(TokenType.ImplementsSemikeyword);
            ParameterizedPropertyDirective.Add(TokenType.IndexSemikeyword);
            ParameterizedPropertyDirective.Add(TokenType.ReadSemikeyword);
            ParameterizedPropertyDirective.Add(TokenType.StoredSemikeyword);
            ParameterizedPropertyDirective.Add(TokenType.WriteSemikeyword);

            ParameterlessPropertyDirective = new TokenSet("property directive");
            ParameterlessPropertyDirective.Add(TokenType.NoDefaultSemikeyword);
            ParameterlessPropertyDirective.Add(TokenType.ReadOnlySemikeyword);
            ParameterlessPropertyDirective.Add(TokenType.WriteOnlySemikeyword);

            ParameterModifier = new TokenSet("parameter modifier");
            ParameterModifier.Add(TokenType.ConstKeyword);
            ParameterModifier.Add(TokenType.OutSemikeyword);
            ParameterModifier.Add(TokenType.VarKeyword);

            PortabilityDirective = new TokenSet("portability directive");
            PortabilityDirective.Add(TokenType.PlatformSemikeyword);
            PortabilityDirective.Add(TokenType.DeprecatedSemikeyword);
            PortabilityDirective.Add(TokenType.LibraryKeyword);
            PortabilityDirective.Add(TokenType.ExperimentalSemikeyword);

            Program = new TokenSet("program");
            Program.Add(TokenType.ProgramKeyword);
            Program.Add(TokenType.LibraryKeyword);

            RelOp = new TokenSet("relational operator");
            RelOp.Add(TokenType.EqualSign);
            RelOp.Add(TokenType.GreaterThan);
            RelOp.Add(TokenType.LessThan);
            RelOp.Add(TokenType.LessOrEqual);
            RelOp.Add(TokenType.GreaterOrEqual);
            RelOp.Add(TokenType.NotEqual);
            RelOp.Add(TokenType.InKeyword);
            RelOp.Add(TokenType.IsKeyword);
            RelOp.Add(TokenType.AsKeyword);

            Semikeyword = new TokenSet("semikeyword");
            Semikeyword.Add(TokenType.AbsoluteSemikeyword);
            Semikeyword.Add(TokenType.AbstractSemikeyword);
            Semikeyword.Add(TokenType.AssemblerSemikeyword);
            Semikeyword.Add(TokenType.AssemblySemikeyword);
            Semikeyword.Add(TokenType.AtSemikeyword);
            Semikeyword.Add(TokenType.AutomatedSemikeyword);
            Semikeyword.Add(TokenType.CdeclSemikeyword);
            Semikeyword.Add(TokenType.ContainsSemikeyword);
            Semikeyword.Add(TokenType.DefaultSemikeyword);
            Semikeyword.Add(TokenType.DeprecatedSemikeyword);
            Semikeyword.Add(TokenType.DispIdSemikeyword);
            Semikeyword.Add(TokenType.DynamicSemikeyword);
            Semikeyword.Add(TokenType.ExperimentalSemikeyword);
            Semikeyword.Add(TokenType.ExportSemikeyword);
            Semikeyword.Add(TokenType.ExternalSemikeyword);
            Semikeyword.Add(TokenType.FarSemikeyword);
            Semikeyword.Add(TokenType.FinalSemikeyword);
            Semikeyword.Add(TokenType.ForwardSemikeyword);
            Semikeyword.Add(TokenType.HelperSemikeyword);
            Semikeyword.Add(TokenType.ImplementsSemikeyword);
            Semikeyword.Add(TokenType.IndexSemikeyword);
            Semikeyword.Add(TokenType.LocalSemikeyword);
            Semikeyword.Add(TokenType.MessageSemikeyword);
            Semikeyword.Add(TokenType.NameSemikeyword);
            Semikeyword.Add(TokenType.NearSemikeyword);
            Semikeyword.Add(TokenType.NoDefaultSemikeyword);
            Semikeyword.Add(TokenType.OnSemikeyword);
            Semikeyword.Add(TokenType.OperatorSemikeyword);
            Semikeyword.Add(TokenType.OutSemikeyword);
            Semikeyword.Add(TokenType.OverloadSemikeyword);
            Semikeyword.Add(TokenType.OverrideSemikeyword);
            Semikeyword.Add(TokenType.PackageSemikeyword);
            Semikeyword.Add(TokenType.PascalSemikeyword);
            Semikeyword.Add(TokenType.PlatformSemikeyword);
            Semikeyword.Add(TokenType.PrivateSemikeyword);
            Semikeyword.Add(TokenType.ProtectedSemikeyword);
            Semikeyword.Add(TokenType.PublicSemikeyword);
            Semikeyword.Add(TokenType.PublishedSemikeyword);
            Semikeyword.Add(TokenType.ReadSemikeyword);
            Semikeyword.Add(TokenType.ReadOnlySemikeyword);
            Semikeyword.Add(TokenType.RegisterSemikeyword);
            Semikeyword.Add(TokenType.ReintroduceSemikeyword);
            Semikeyword.Add(TokenType.RequiresSemikeyword);
            Semikeyword.Add(TokenType.ResidentSemikeyword);
            Semikeyword.Add(TokenType.SafecallSemikeyword);
            Semikeyword.Add(TokenType.SealedSemikeyword);
            Semikeyword.Add(TokenType.StaticSemikeyword);
            Semikeyword.Add(TokenType.StdcallSemikeyword);
            Semikeyword.Add(TokenType.StoredSemikeyword);
            Semikeyword.Add(TokenType.StrictSemikeyword);
            Semikeyword.Add(TokenType.UnsafeSemikeyword);
            Semikeyword.Add(TokenType.VarArgsSemikeyword);
            Semikeyword.Add(TokenType.VirtualSemikeyword);
            Semikeyword.Add(TokenType.WriteSemikeyword);
            Semikeyword.Add(TokenType.WriteOnlySemikeyword);

            UnaryOperator = new TokenSet("unary operator");
            UnaryOperator.Add(TokenType.AtSign);
            UnaryOperator.Add(TokenType.InheritedKeyword);
            UnaryOperator.Add(TokenType.MinusSign);
            UnaryOperator.Add(TokenType.NotKeyword);
            UnaryOperator.Add(TokenType.PlusSign);

            Uses = new TokenSet("uses clause");
            Uses.Add(TokenType.UsesKeyword);
            Uses.Add(TokenType.ContainsSemikeyword);

            VarHeader = new TokenSet("var section");
            VarHeader.Add(TokenType.VarKeyword);
            VarHeader.Add(TokenType.ThreadVarKeyword);

            VisibilitySingleWord = new TokenSet("'private', 'protected', 'public', or 'published'");
            VisibilitySingleWord.Add(TokenType.PrivateSemikeyword);
            VisibilitySingleWord.Add(TokenType.ProtectedSemikeyword);
            VisibilitySingleWord.Add(TokenType.PublicSemikeyword);
            VisibilitySingleWord.Add(TokenType.PublishedSemikeyword);

            Ident = new TokenSet("identifier");
            Ident.Add(TokenType.Identifier);
            Ident.AddRange(Semikeyword);

            IdentNoVisibility = new TokenSet("identifier no visibility");
            IdentNoVisibility.AddRange(Ident);
            IdentNoVisibility.RemoveRange(VisibilitySingleWord);
            IdentNoVisibility.Remove(TokenType.StrictSemikeyword);

            Directive.AddRange(PortabilityDirective);

            Particle = new TokenSet("expression");
            Particle.Add(TokenType.FileKeyword);
            Particle.Add(TokenType.NilKeyword);
            Particle.Add(TokenType.Number);
            Particle.Add(TokenType.OpenBracket);
            Particle.Add(TokenType.OpenParenthesis);
            Particle.Add(TokenType.StringKeyword);
            Particle.Add(TokenType.StringLiteral);
            Particle.AddRange(Ident);

            Expression = new TokenSet("expression");
            Expression.AddRange(Particle);
            Expression.AddRange(UnaryOperator);
            Expression.Add(TokenType.FunctionKeyword);
            Expression.Add(TokenType.ProcedureKeyword);

            ExtendedIdent = new TokenSet("identifier (including keyword)");
            ExtendedIdent.AddRange(Ident);
            ExtendedIdent.AddRange(Keyword);

            LabelId = new TokenSet("label");
            LabelId.Add(TokenType.Number);
            LabelId.AddRange(Ident);

            Parameter = new TokenSet("parameter");
            Parameter.AddRange(Ident);
            Parameter.AddRange(ParameterModifier);

            SimpleParameterType = new TokenSet("parameter type");
            SimpleParameterType.Add(TokenType.FileKeyword);
            SimpleParameterType.Add(TokenType.StringKeyword);
            SimpleParameterType.AddRange(Ident);

            Visibility = new TokenSet("visibility specifier");
            Visibility.Add(TokenType.StrictSemikeyword);
            Visibility.AddRange(VisibilitySingleWord);
        }
示例#46
0
 private void ParseEnumMember(TypeExpression typeExpression, List<ITypeDeclarationMember> members, TokenSet followers)
   //^ requires this.currentToken == Token.LeftBracket || Parser.IdentifierOrNonReservedKeyword[this.currentToken];
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   SourceLocationBuilder sctx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken);
   List<SourceCustomAttribute>/*?*/ attributes = this.ParseAttributes(followers|Parser.AttributeOrTypeDeclarationStart|Parser.IdentifierOrNonReservedKeyword);
   if (!Parser.IdentifierOrNonReservedKeyword[this.currentToken])
     this.HandleError(Error.ExpectedIdentifier);
   NameDeclaration name = this.ParseNameDeclaration();
   Expression/*?*/ initializer = null;
   if (this.currentToken == Token.Assign) {
     this.GetNextToken();
     initializer = this.ParseExpression(followers);
   }
   EnumMember member = new EnumMember(attributes, typeExpression, name, initializer, sctx);
   members.Add(member);
   this.SkipTo(followers);
 }
示例#47
0
 private void ParseNamespaceBody(List<INamespaceDeclarationMember> members, List<Ast.SourceCustomAttribute>/*?*/ sourceAttributes, TokenSet followers) {
 tryAgain:
   this.ParseExternalAliasDirectives(members, followers|Parser.AttributeOrNamespaceOrTypeDeclarationStart|Token.Using|Token.EndOfFile);
   this.ParseUsingDirectives(members, followers|Parser.AttributeOrNamespaceOrTypeDeclarationStart|Token.Extern|Token.EndOfFile);
   if (this.currentToken == Token.Extern) {
     this.HandleError(Error.ExternAfterElements);
     goto tryAgain;
   }
   if (sourceAttributes != null)
     this.ParseAttributes(ref sourceAttributes, true, followers|Parser.NamespaceOrTypeDeclarationStart);
   if (this.currentToken != Token.EndOfFile)
     this.ParseNamespaceMemberDeclarations(members, followers);
   members.TrimExcess();
 }
示例#48
0
 private void ParseTypeMembers(SourceLocationBuilder sctx, IName typeName, List<ITypeDeclarationMember> members, TokenSet followers)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   TokenSet followersOrTypeMemberStart = followers|Parser.TypeMemberStart;
   for (; ; ) {
     SourceLocationBuilder tctx = new SourceLocationBuilder(this.scanner.SourceLocationOfLastScannedToken);
     List<SourceCustomAttribute>/*?*/ attributes = this.ParseAttributes(followersOrTypeMemberStart);
     List<ModifierToken> modifiers = this.ParseModifiers();
     switch (this.currentToken) {
       case Token.Class:
         this.ParseNestedClassDeclaration(members, attributes, this.ConvertToTypeDeclarationFlags(modifiers), tctx, followersOrTypeMemberStart);
         break;
       case Token.Interface:
         this.ParseNestedInterfaceDeclaration(members, attributes, this.ConvertToTypeDeclarationFlags(modifiers), tctx, followersOrTypeMemberStart);
         break;
       case Token.Struct:
         this.ParseNestedStructDeclaration(members, attributes, this.ConvertToTypeDeclarationFlags(modifiers), tctx, followersOrTypeMemberStart);
         break;
       case Token.Enum:
         this.ParseNestedEnumDeclaration(members, attributes, this.ConvertToTypeDeclarationFlags(modifiers), tctx, followersOrTypeMemberStart);
         break;
       case Token.Delegate:
         this.ParseNestedDelegateDeclaration(members, attributes, this.ConvertToTypeDeclarationFlags(modifiers), tctx, followersOrTypeMemberStart);
         break;
       case Token.Const:
         this.ParseConst(members, attributes, modifiers, tctx, followersOrTypeMemberStart);
         break;
       case Token.Invariant:
         goto default;
         //this.ParseInvariant(attributes, modifierTokens, modifierContexts, tctx, followersOrTypeMemberStart);
         //break;
       case Token.Bool:
       case Token.Decimal:
       case Token.Sbyte:
       case Token.Byte:
       case Token.Short:
       case Token.Ushort:
       case Token.Int:
       case Token.Uint:
       case Token.Long:
       case Token.Ulong:
       case Token.Char:
       case Token.Float:
       case Token.Double:
       case Token.Object:
       case Token.String:
       case Token.Void:
       case Token.Identifier:
         this.ParseConstructorOrFieldOrMethodOrPropertyOrStaticInitializer(typeName, members, attributes, modifiers, tctx, followersOrTypeMemberStart);
         break;
       case Token.Event:
         this.ParseEvent(members, attributes, modifiers, tctx, followersOrTypeMemberStart); 
         break;
       case Token.Operator:
       case Token.Explicit:
       case Token.Implicit:
         this.ParseOperator(members, attributes, modifiers, null, tctx, followersOrTypeMemberStart); 
         break;
       case Token.BitwiseNot:
         this.ParseDestructor(typeName, members, attributes, modifiers, tctx, followersOrTypeMemberStart); 
         break;
       default:
         if (Parser.IdentifierOrNonReservedKeyword[this.currentToken]) goto case Token.Identifier;
         sctx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken);
         this.SkipTo(followers);
         return;
     }
   }
 }
示例#49
0
 private void ParseNestedEnumDeclaration(List<ITypeDeclarationMember> namespaceMembers, List<SourceCustomAttribute>/*?*/ attributes, TypeDeclaration.Flags flags, SourceLocationBuilder sctx, TokenSet followers)
   //^ requires this.currentToken == Token.Enum;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   this.GetNextToken();
   if (!Parser.IdentifierOrNonReservedKeyword[this.currentToken])
     this.HandleError(Error.ExpectedIdentifier);
   NameDeclaration name = this.ParseNameDeclaration();
   TypeExpression/*?*/ underlyingType = null;
   if (this.currentToken == Token.Colon) {
     this.GetNextToken();
     if (this.currentToken != Token.EndOfFile)
       underlyingType = this.ParseTypeExpression(false, false, followers|Token.LeftBrace);
   }
   List<ITypeDeclarationMember> members = new List<ITypeDeclarationMember>();
   NestedEnumDeclaration type = new NestedEnumDeclaration(attributes, flags, name, underlyingType, members, sctx);
   namespaceMembers.Add(type);
   this.ParseRestOfEnum(sctx, type, members, followers);
 }
示例#50
0
 //^ [Pure]
 public static TokenSet operator |(TokenSet ts, Token t){
   TokenSet result = new TokenSet();
   int i = (int)t;
   if (i < 64){
     result.bits0 = ts.bits0 | (1ul << i);
     result.bits1 = ts.bits1;
     result.bits2 = ts.bits2;
     result.bits3 = ts.bits3;
   }else if (i < 128){
     result.bits0 = ts.bits0;
     result.bits1 = ts.bits1 | (1ul << (i-64));
     result.bits2 = ts.bits2;
     result.bits3 = ts.bits3;
   }else if (i < 192){
     result.bits0 = ts.bits0;
     result.bits1 = ts.bits1;
     result.bits2 = ts.bits2 | (1ul << (i-128));
     result.bits3 = ts.bits3;
   }else{
     result.bits0 = ts.bits0;
     result.bits1 = ts.bits1;
     result.bits2 = ts.bits2;
     result.bits3 = ts.bits3 | (1ul << (i-192));
   }
   return result;
 }
示例#51
0
    static Parser(){
      AddOneOrSubtractOne = new TokenSet();
      AddOneOrSubtractOne |= Token.AddOne;
      AddOneOrSubtractOne |= Token.SubtractOne;

      AddOrRemoveOrModifier = new TokenSet();
      AddOrRemoveOrModifier |= Token.Add;
      AddOrRemoveOrModifier |= Token.Remove;
      AddOrRemoveOrModifier |= Token.New;
      AddOrRemoveOrModifier |= Token.Public;
      AddOrRemoveOrModifier |= Token.Protected;
      AddOrRemoveOrModifier |= Token.Internal;
      AddOrRemoveOrModifier |= Token.Private;
      AddOrRemoveOrModifier |= Token.Abstract;
      AddOrRemoveOrModifier |= Token.Sealed;
      AddOrRemoveOrModifier |= Token.Static;
      AddOrRemoveOrModifier |= Token.Readonly;
      AddOrRemoveOrModifier |= Token.Volatile;
      AddOrRemoveOrModifier |= Token.Virtual;
      AddOrRemoveOrModifier |= Token.Override;
      AddOrRemoveOrModifier |= Token.Extern;
      AddOrRemoveOrModifier |= Token.Unsafe;

      AssignmentOperators = new TokenSet();      
      AssignmentOperators |= Token.PlusAssign;
      AssignmentOperators |= Token.Assign;
      AssignmentOperators |= Token.BitwiseAndAssign;
      AssignmentOperators |= Token.BitwiseOrAssign;
      AssignmentOperators |= Token.BitwiseXorAssign;
      AssignmentOperators |= Token.DivideAssign;
      AssignmentOperators |= Token.LeftShiftAssign;
      AssignmentOperators |= Token.MultiplyAssign;
      AssignmentOperators |= Token.RemainderAssign;
      AssignmentOperators |= Token.RightShiftAssign;
      AssignmentOperators |= Token.SubtractAssign;

      AttributeOrTypeDeclarationStart = new TokenSet();
      AttributeOrTypeDeclarationStart |= Token.LeftBracket;
      AttributeOrTypeDeclarationStart |= Token.New;
      AttributeOrTypeDeclarationStart |= Token.Partial;
      AttributeOrTypeDeclarationStart |= Token.Unsafe;
      AttributeOrTypeDeclarationStart |= Token.Public;
      AttributeOrTypeDeclarationStart |= Token.Internal;
      AttributeOrTypeDeclarationStart |= Token.Abstract;
      AttributeOrTypeDeclarationStart |= Token.Sealed;
      AttributeOrTypeDeclarationStart |= Token.Static;
      AttributeOrTypeDeclarationStart |= Token.Class;
      AttributeOrTypeDeclarationStart |= Token.Delegate;
      AttributeOrTypeDeclarationStart |= Token.Enum;
      AttributeOrTypeDeclarationStart |= Token.Interface;
      AttributeOrTypeDeclarationStart |= Token.Struct;

      CaseOrDefaultOrRightBrace = new TokenSet();
      CaseOrDefaultOrRightBrace |= Token.Case;
      CaseOrDefaultOrRightBrace |= Token.Default;
      CaseOrDefaultOrRightBrace |= Token.RightBrace;

      CaseOrColonOrDefaultOrRightBrace = CaseOrDefaultOrRightBrace;
      CaseOrColonOrDefaultOrRightBrace |= Token.Colon;

      CatchOrFinally = new TokenSet();
      CatchOrFinally |= Token.Catch;
      CatchOrFinally |= Token.Finally;

      ContractStart = new TokenSet();
      ContractStart |= Token.Requires;
      ContractStart |= Token.Modifies;
      ContractStart |= Token.Ensures;
      ContractStart |= Token.Throws;

      EndOfFile = new TokenSet();
      EndOfFile |= Token.EndOfFile;

      GetOrLeftBracketOrSetOrModifier = new TokenSet();
      GetOrLeftBracketOrSetOrModifier |= Token.Get;
      GetOrLeftBracketOrSetOrModifier |= Token.LeftBracket;
      GetOrLeftBracketOrSetOrModifier |= Token.Set;
      GetOrLeftBracketOrSetOrModifier |= Token.New;
      GetOrLeftBracketOrSetOrModifier |= Token.Public;
      GetOrLeftBracketOrSetOrModifier |= Token.Protected;
      GetOrLeftBracketOrSetOrModifier |= Token.Internal;
      GetOrLeftBracketOrSetOrModifier |= Token.Private;
      GetOrLeftBracketOrSetOrModifier |= Token.Abstract;
      GetOrLeftBracketOrSetOrModifier |= Token.Sealed;
      GetOrLeftBracketOrSetOrModifier |= Token.Static;
      GetOrLeftBracketOrSetOrModifier |= Token.Readonly;
      GetOrLeftBracketOrSetOrModifier |= Token.Volatile;
      GetOrLeftBracketOrSetOrModifier |= Token.Virtual;
      GetOrLeftBracketOrSetOrModifier |= Token.Override;
      GetOrLeftBracketOrSetOrModifier |= Token.Extern;
      GetOrLeftBracketOrSetOrModifier |= Token.Unsafe;
      
      IdentifierOrNonReservedKeyword = new TokenSet();
      IdentifierOrNonReservedKeyword |= Token.Identifier;
      IdentifierOrNonReservedKeyword |= Token.Acquire;
      IdentifierOrNonReservedKeyword |= Token.Add;
      IdentifierOrNonReservedKeyword |= Token.Alias;
      IdentifierOrNonReservedKeyword |= Token.Assert;
      IdentifierOrNonReservedKeyword |= Token.Assume;
      IdentifierOrNonReservedKeyword |= Token.Count;
      IdentifierOrNonReservedKeyword |= Token.Ensures;
      IdentifierOrNonReservedKeyword |= Token.Exists;
      IdentifierOrNonReservedKeyword |= Token.Expose;
      IdentifierOrNonReservedKeyword |= Token.Forall;
      IdentifierOrNonReservedKeyword |= Token.Get;
      IdentifierOrNonReservedKeyword |= Token.Modifies;
      IdentifierOrNonReservedKeyword |= Token.Old;
      IdentifierOrNonReservedKeyword |= Token.Otherwise;
      IdentifierOrNonReservedKeyword |= Token.Partial;
      IdentifierOrNonReservedKeyword |= Token.Read;
      IdentifierOrNonReservedKeyword |= Token.Remove;
      IdentifierOrNonReservedKeyword |= Token.Requires;
      IdentifierOrNonReservedKeyword |= Token.Set;
      IdentifierOrNonReservedKeyword |= Token.Throws;
      IdentifierOrNonReservedKeyword |= Token.Unique;
      IdentifierOrNonReservedKeyword |= Token.Value;
      IdentifierOrNonReservedKeyword |= Token.Var;
      IdentifierOrNonReservedKeyword |= Token.Write;
      IdentifierOrNonReservedKeyword |= Token.Yield;
      IdentifierOrNonReservedKeyword |= Token.Where;      

      InfixOperators = new TokenSet();      
      InfixOperators |= Token.PlusAssign;
      InfixOperators |= Token.As;
      InfixOperators |= Token.Assign;
      InfixOperators |= Token.BitwiseAnd;
      InfixOperators |= Token.BitwiseAndAssign;
      InfixOperators |= Token.BitwiseOr;
      InfixOperators |= Token.BitwiseOrAssign;
      InfixOperators |= Token.BitwiseXor;
      InfixOperators |= Token.BitwiseXorAssign;
      InfixOperators |= Token.Conditional;
      InfixOperators |= Token.Divide;
      InfixOperators |= Token.DivideAssign;
      InfixOperators |= Token.Equal;
      InfixOperators |= Token.GreaterThan;
      InfixOperators |= Token.GreaterThanOrEqual;
      InfixOperators |= Token.Is;
      //InfixOperators |= Token.Iff;
      //InfixOperators |= Token.Implies;
      InfixOperators |= Token.LeftShift;
      InfixOperators |= Token.LeftShiftAssign;
      InfixOperators |= Token.LessThan;
      InfixOperators |= Token.LessThanOrEqual;
      InfixOperators |= Token.LogicalAnd;
      InfixOperators |= Token.LogicalOr;
      //InfixOperators |= Token.Maplet; 
      InfixOperators |= Token.Multiply;
      InfixOperators |= Token.MultiplyAssign;
      InfixOperators |= Token.NotEqual;
      InfixOperators |= Token.NullCoalescing;
      InfixOperators |= Token.Plus;
      //InfixOperators |= Token.Range; 
      InfixOperators |= Token.Remainder;
      InfixOperators |= Token.RemainderAssign;
      InfixOperators |= Token.RightShift;
      InfixOperators |= Token.RightShiftAssign;
      InfixOperators |= Token.Subtract;
      InfixOperators |= Token.SubtractAssign;
      InfixOperators |= Token.Arrow;

      TypeStart = new TokenSet();
      TypeStart |= Parser.IdentifierOrNonReservedKeyword;
      TypeStart |= Token.Bool;
      TypeStart |= Token.Decimal;
      TypeStart |= Token.Sbyte;
      TypeStart |= Token.Byte;
      TypeStart |= Token.Short;
      TypeStart |= Token.Ushort;
      TypeStart |= Token.Int;
      TypeStart |= Token.Uint;
      TypeStart |= Token.Long;
      TypeStart |= Token.Ulong;
      TypeStart |= Token.Char;
      TypeStart |= Token.Float;
      TypeStart |= Token.Double;
      TypeStart |= Token.Object;
      TypeStart |= Token.String;
      TypeStart |= Token.LeftBracket;
      TypeStart |= Token.LeftParenthesis;

      ParameterTypeStart = new TokenSet();
      ParameterTypeStart |= Parser.TypeStart;
      ParameterTypeStart |= Token.Ref;
      ParameterTypeStart |= Token.Out;
      ParameterTypeStart |= Token.Params;

      PrimaryStart = new TokenSet();
      PrimaryStart |= Parser.IdentifierOrNonReservedKeyword;
      PrimaryStart |= Token.This;
      PrimaryStart |= Token.Base;
      PrimaryStart |= Token.Value;
      PrimaryStart |= Token.New;
      PrimaryStart |= Token.Typeof;
      PrimaryStart |= Token.Sizeof;
      PrimaryStart |= Token.Stackalloc;
      PrimaryStart |= Token.Checked;
      PrimaryStart |= Token.Unchecked;
      PrimaryStart |= Token.HexLiteral;
      PrimaryStart |= Token.IntegerLiteral;
      PrimaryStart |= Token.StringLiteral;
      PrimaryStart |= Token.CharLiteral;
      PrimaryStart |= Token.RealLiteral;
      PrimaryStart |= Token.Null;
      PrimaryStart |= Token.False;
      PrimaryStart |= Token.True;
      PrimaryStart |= Token.Bool;
      PrimaryStart |= Token.Decimal;
      PrimaryStart |= Token.Sbyte;
      PrimaryStart |= Token.Byte;
      PrimaryStart |= Token.Short;
      PrimaryStart |= Token.Ushort;
      PrimaryStart |= Token.Int;
      PrimaryStart |= Token.Uint;
      PrimaryStart |= Token.Long;
      PrimaryStart |= Token.Ulong;
      PrimaryStart |= Token.Char;
      PrimaryStart |= Token.Float;
      PrimaryStart |= Token.Double;
      PrimaryStart |= Token.Object;
      PrimaryStart |= Token.String;
      PrimaryStart |= Token.LeftParenthesis;

      ProtectionModifier = new TokenSet();
      ProtectionModifier |= Token.Public;
      ProtectionModifier |= Token.Protected;
      ProtectionModifier |= Token.Internal;
      ProtectionModifier |= Token.Private;

      NamespaceOrTypeDeclarationStart = new TokenSet();
      NamespaceOrTypeDeclarationStart |= Token.Partial;
      NamespaceOrTypeDeclarationStart |= Token.Unsafe;
      NamespaceOrTypeDeclarationStart |= Token.Public;
      NamespaceOrTypeDeclarationStart |= Token.Internal;
      NamespaceOrTypeDeclarationStart |= Token.Abstract;
      NamespaceOrTypeDeclarationStart |= Token.Sealed;
      NamespaceOrTypeDeclarationStart |= Token.Static;
      NamespaceOrTypeDeclarationStart |= Token.Namespace;
      NamespaceOrTypeDeclarationStart |= Token.Class;
      NamespaceOrTypeDeclarationStart |= Token.Delegate;
      NamespaceOrTypeDeclarationStart |= Token.Enum;
      NamespaceOrTypeDeclarationStart |= Token.Interface;
      NamespaceOrTypeDeclarationStart |= Token.Struct;

      AttributeOrNamespaceOrTypeDeclarationStart = AttributeOrTypeDeclarationStart;
      AttributeOrNamespaceOrTypeDeclarationStart |= Token.Namespace;
      AttributeOrNamespaceOrTypeDeclarationStart |= Token.Private; //For error recovery
      AttributeOrNamespaceOrTypeDeclarationStart |= Token.Protected; //For error recovery

      RightParenthesisOrSemicolon = new TokenSet();
      RightParenthesisOrSemicolon |= Token.RightParenthesis;
      RightParenthesisOrSemicolon |= Token.Semicolon;

      TypeMemberStart = new TokenSet();
      TypeMemberStart |= Token.LeftBracket;
      TypeMemberStart |= Token.LeftParenthesis;
      TypeMemberStart |= Token.LeftBrace;
      TypeMemberStart |= Token.New;
      TypeMemberStart |= Token.Partial;
      TypeMemberStart |= Token.Public;
      TypeMemberStart |= Token.Protected;
      TypeMemberStart |= Token.Internal;
      TypeMemberStart |= Token.Private;
      TypeMemberStart |= Token.Abstract;
      TypeMemberStart |= Token.Sealed;
      TypeMemberStart |= Token.Static;
      TypeMemberStart |= Token.Readonly;
      TypeMemberStart |= Token.Volatile;
      TypeMemberStart |= Token.Virtual;
      TypeMemberStart |= Token.Override;
      TypeMemberStart |= Token.Extern;
      TypeMemberStart |= Token.Unsafe;
      TypeMemberStart |= Token.Const;
      TypeMemberStart |= Parser.IdentifierOrNonReservedKeyword;
      TypeMemberStart |= Token.Event;
      TypeMemberStart |= Token.This;
      TypeMemberStart |= Token.Operator;
      TypeMemberStart |= Token.BitwiseNot;
      TypeMemberStart |= Token.Static;
      TypeMemberStart |= Token.Class;
      TypeMemberStart |= Token.Delegate;
      TypeMemberStart |= Token.Enum;
      TypeMemberStart |= Token.Interface;
      TypeMemberStart |= Token.Struct;
      TypeMemberStart |= Token.Bool;
      TypeMemberStart |= Token.Decimal;
      TypeMemberStart |= Token.Sbyte;
      TypeMemberStart |= Token.Byte;
      TypeMemberStart |= Token.Short;
      TypeMemberStart |= Token.Ushort;
      TypeMemberStart |= Token.Int;
      TypeMemberStart |= Token.Uint;
      TypeMemberStart |= Token.Long;
      TypeMemberStart |= Token.Ulong;
      TypeMemberStart |= Token.Char;
      TypeMemberStart |= Token.Float;
      TypeMemberStart |= Token.Double;
      TypeMemberStart |= Token.Object;
      TypeMemberStart |= Token.String;
      TypeMemberStart |= Token.Void;
      TypeMemberStart |= Token.Invariant;

      TypeOperator = new TokenSet();
      TypeOperator |= Token.LeftBracket;
      TypeOperator |= Token.Multiply;
      TypeOperator |= Token.Plus;
      TypeOperator |= Token.Conditional;
      TypeOperator |= Token.LogicalNot;
      TypeOperator |= Token.BitwiseAnd;

      UnaryStart = new TokenSet();
      UnaryStart |= Parser.IdentifierOrNonReservedKeyword;
      UnaryStart |= Token.LeftParenthesis;
      UnaryStart |= Token.LeftBracket;
      UnaryStart |= Token.This;
      UnaryStart |= Token.Base;
      UnaryStart |= Token.Value;
      UnaryStart |= Token.AddOne;
      UnaryStart |= Token.SubtractOne;
      UnaryStart |= Token.New;
      UnaryStart |= Token.Default;
      UnaryStart |= Token.Typeof;
      UnaryStart |= Token.Sizeof;
      UnaryStart |= Token.Stackalloc;
      UnaryStart |= Token.Delegate;
      UnaryStart |= Token.Checked;
      UnaryStart |= Token.Unchecked;
      UnaryStart |= Token.HexLiteral;
      UnaryStart |= Token.IntegerLiteral;
      UnaryStart |= Token.StringLiteral;
      UnaryStart |= Token.CharLiteral;
      UnaryStart |= Token.RealLiteral;
      UnaryStart |= Token.Null;
      UnaryStart |= Token.False;
      UnaryStart |= Token.True;
      UnaryStart |= Token.Bool;
      UnaryStart |= Token.Decimal;
      UnaryStart |= Token.Sbyte;
      UnaryStart |= Token.Byte;
      UnaryStart |= Token.Short;
      UnaryStart |= Token.Ushort;
      UnaryStart |= Token.Int;
      UnaryStart |= Token.Uint;
      UnaryStart |= Token.Long;
      UnaryStart |= Token.Ulong;
      UnaryStart |= Token.Char;
      UnaryStart |= Token.Float;
      UnaryStart |= Token.Double;
      UnaryStart |= Token.Object;
      UnaryStart |= Token.String;
      UnaryStart |= Token.Plus;
      UnaryStart |= Token.BitwiseNot;
      UnaryStart |= Token.LogicalNot;
      UnaryStart |= Token.Multiply;
      UnaryStart |= Token.Subtract;
      UnaryStart |= Token.AddOne;
      UnaryStart |= Token.SubtractOne;
      UnaryStart |= Token.Multiply;
      UnaryStart |= Token.BitwiseAnd;

      StatementStart = new TokenSet();
      StatementStart |= Parser.UnaryStart;
      StatementStart |= Token.LeftBrace;
      StatementStart |= Token.Semicolon;
      StatementStart |= Token.Acquire;
      StatementStart |= Token.Assert;
      StatementStart |= Token.Assume;
      StatementStart |= Token.If;
      StatementStart |= Token.Switch;
      StatementStart |= Token.While;
      StatementStart |= Token.Do;
      StatementStart |= Token.For;
      StatementStart |= Token.Foreach;
      StatementStart |= Token.While;
      StatementStart |= Token.Break;
      StatementStart |= Token.Continue;
      StatementStart |= Token.Goto;
      StatementStart |= Token.Return;
      StatementStart |= Token.Throw;
      StatementStart |= Token.Yield;
      StatementStart |= Token.Try;
      StatementStart |= Token.Catch; //Not really, but helps error recovery
      StatementStart |= Token.Finally; //Not really, but helps error recovery
      StatementStart |= Token.Checked;
      StatementStart |= Token.Unchecked;
      StatementStart |= Token.Read;
      StatementStart |= Token.Write;
      StatementStart |= Token.Expose;
      StatementStart |= Token.Fixed;
      StatementStart |= Token.Lock;
      StatementStart |= Token.Unsafe;
      StatementStart |= Token.Using;
      StatementStart |= Token.Const;
      StatementStart |= Token.Delegate;
      StatementStart |= Token.Void;

      Term = new TokenSet();
      Term |= Token.ArgList;
      Term |= Token.MakeRef;
      Term |= Token.RefType;
      Term |= Token.RefValue;
      Term |= Token.Base;
      Term |= Token.Checked;
      Term |= Token.Default;
      Term |= Token.Delegate;
      Term |= Token.False;
      Term |= Token.New;
      Term |= Token.Null;
      Term |= Token.Sizeof;
      Term |= Token.This;
      Term |= Token.True;
      Term |= Token.Typeof;
      Term |= Token.Unchecked;
      Term |= Token.Identifier;
      Term |= Token.IntegerLiteral;
      Term |= Token.RealLiteral;
      Term |= Token.StringLiteral;
      Term |= Token.CharLiteral;
      Term |= Token.LeftParenthesis;

      Predefined = new TokenSet();
      Predefined |= Token.Bool;
      Predefined |= Token.Decimal;
      Predefined |= Token.Sbyte;
      Predefined |= Token.Byte;
      Predefined |= Token.Short;
      Predefined |= Token.Ushort;
      Predefined |= Token.Int;
      Predefined |= Token.Uint;
      Predefined |= Token.Long;
      Predefined |= Token.Ulong;
      Predefined |= Token.Char;
      Predefined |= Token.Float;
      Predefined |= Token.Double;
      Predefined |= Token.Object;
      Predefined |= Token.String;
      Predefined |= Token.Void;

      UnaryOperator = new TokenSet();
      UnaryOperator |= Token.Base;
      UnaryOperator |= Token.Default;
      UnaryOperator |= Token.Sizeof;
      UnaryOperator |= Token.This;
      UnaryOperator |= Token.Typeof;
      UnaryOperator |= Token.BitwiseAnd;
      UnaryOperator |= Token.Plus;
      UnaryOperator |= Token.Subtract;
      UnaryOperator |= Token.Multiply;
      UnaryOperator |= Token.BitwiseNot;
      UnaryOperator |= Token.LogicalNot;
      UnaryOperator |= Token.AddOne;
      UnaryOperator |= Token.SubtractOne;

      NullableTypeNonFollower = Term | Predefined | UnaryOperator;

      TypeArgumentListNonFollower = NullableTypeNonFollower;
      //TypeArgumentListNonFollower[Token.LeftParenthesis] = false;

      CastFollower = IdentifierOrNonReservedKeyword;
      CastFollower |= Token.LeftParenthesis;
      CastFollower |= Token.This;
      CastFollower |= Token.Base;
      CastFollower |= Token.Value;
      CastFollower |= Token.AddOne;
      CastFollower |= Token.SubtractOne;
      CastFollower |= Token.New;
      CastFollower |= Token.Default;
      CastFollower |= Token.Typeof;
      CastFollower |= Token.Sizeof;
      CastFollower |= Token.Stackalloc;
      CastFollower |= Token.Delegate;
      CastFollower |= Token.Checked;
      CastFollower |= Token.Unchecked;
      CastFollower |= Token.HexLiteral;
      CastFollower |= Token.IntegerLiteral;
      CastFollower |= Token.StringLiteral;
      CastFollower |= Token.CharLiteral;
      CastFollower |= Token.RealLiteral;
      CastFollower |= Token.Null;
      CastFollower |= Token.False;
      CastFollower |= Token.True;
      CastFollower |= Token.Bool;
      CastFollower |= Token.Decimal;
      CastFollower |= Token.Sbyte;
      CastFollower |= Token.Byte;
      CastFollower |= Token.Short;
      CastFollower |= Token.Ushort;
      CastFollower |= Token.Int;
      CastFollower |= Token.Uint;
      CastFollower |= Token.Long;
      CastFollower |= Token.Ulong;
      CastFollower |= Token.Char;
      CastFollower |= Token.Float;
      CastFollower |= Token.Double;
      CastFollower |= Token.Object;
      CastFollower |= Token.String;
      CastFollower |= Token.BitwiseNot;
      CastFollower |= Token.LogicalNot;
      CastFollower |= Token.Delegate;
    }
示例#52
0
 private void ParseBaseTypes(List<TypeExpression> baseTypes, TokenSet followers)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   if (this.currentToken == Token.Colon) {
     this.GetNextToken();
     TokenSet baseTypeStart = Parser.IdentifierOrNonReservedKeyword|Parser.Predefined;
     while (baseTypeStart[this.currentToken]) {
       //^ assume this.currentToken != Token.EndOfFile;
       baseTypes.Add(this.ParseTypeExpression(false, false, followers|Token.Comma));
       if (this.currentToken != Token.Comma) break;
       this.GetNextToken();
     }
   }
   this.SkipTo(followers);
 }
示例#53
0
 private void ParseGenericTypeParameters(List<Ast.GenericTypeParameterDeclaration> genericParameters, TokenSet followers) {
   if (this.currentToken != Token.LessThan) return;
   this.GetNextToken();
   while (this.currentToken != Token.GreaterThan && this.currentToken != Token.Colon && this.currentToken != Token.LeftBrace && this.currentToken != Token.EndOfFile) {
     List<SourceCustomAttribute>/*?*/ attributes = this.ParseAttributes(followers|Parser.IdentifierOrNonReservedKeyword);
     if (!Parser.IdentifierOrNonReservedKeyword[this.currentToken])
       this.HandleError(Error.ExpectedIdentifier);
     NameDeclaration name = this.ParseNameDeclaration();
     genericParameters.Add(new SpecSharpGenericTypeParameterDeclaration(attributes, name, (ushort)genericParameters.Count));
     if (this.currentToken != Token.Comma) break;
     this.GetNextToken();
   }
   if (this.currentToken == Token.RightShift)
     this.currentToken = Token.GreaterThan;
   else
     this.SkipOverTo(Token.GreaterThan, followers);
 }
示例#54
0
 private void ParseRestOfEnum(SourceLocationBuilder sctx, TypeDeclaration type, List<ITypeDeclarationMember> members, TokenSet followers)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   TypeExpression texpr = new NamedTypeExpression(new SimpleName(type.Name, type.Name.SourceLocation, false));
   this.Skip(Token.LeftBrace);
   while (this.currentToken == Token.LeftBracket || Parser.IdentifierOrNonReservedKeyword[this.currentToken]){
     this.ParseEnumMember(texpr, members, followers|Token.Comma|Token.RightBrace);
     if (this.currentToken == Token.RightBrace) break;
     this.Skip(Token.Comma);
     if (this.currentToken == Token.RightBrace) break;
   }
   sctx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken);
   this.Skip(Token.RightBrace);
   if (this.currentToken == Token.Semicolon)
     this.GetNextToken();
   this.SkipTo(followers);
 }
示例#55
0
 //^ [Pure]
 public static TokenSet operator|(TokenSet ts1, TokenSet ts2) {
   TokenSet result = new TokenSet();
   result.bits0 = ts1.bits0 | ts2.bits0;
   result.bits1 = ts1.bits1 | ts2.bits1;
   result.bits2 = ts1.bits2 | ts2.bits2;
   result.bits3 = ts1.bits3 | ts2.bits3;
   return result;
 }
示例#56
0
 private void ParseAttributes(ref List<SourceCustomAttribute>/*?*/ sourceAttributes, bool globalAttributes, TokenSet followers) {
   while (this.currentToken == Token.LeftBracket) {
     int position = this.scanner.CurrentDocumentPosition();
     this.GetNextToken();
     AttributeTargets target = this.ParseAttributeTarget();
     if (globalAttributes) {
       if (target != AttributeTargets.Assembly && target != AttributeTargets.Module) {
         this.scanner.RestoreDocumentPosition(position);
         this.currentToken = Token.None;
         this.GetNextToken();
         return;
       }
     }
     while (true) {
       Expression expr = this.ParseExpression(followers|Token.Comma|Token.RightBracket);
       MethodCall/*?*/ mcall = expr as MethodCall;
       if (mcall != null && (mcall.MethodExpression is SimpleName || mcall.MethodExpression is QualifiedName || mcall.MethodExpression is AliasQualifiedName)) {
         AttributeTypeExpression type = new AttributeTypeExpression(mcall.MethodExpression);
         List<Expression> arguments = new List<Expression>(mcall.OriginalArguments);
         bool seenNamedArgument = false;
         for (int i = 0, n = arguments.Count; i < n; i++) {
           Assignment/*?*/ assignment = arguments[i] as Assignment;
           if (assignment == null) {
             if (seenNamedArgument)
               this.HandleError(arguments[i].SourceLocation, Error.NamedArgumentExpected);
             continue;
           }
           SimpleName/*?*/ name = assignment.Target.Expression as SimpleName;
           if (name == null) {
             this.HandleError(assignment.Target.SourceLocation, Error.ExpectedIdentifier);
             name = new SimpleName(Dummy.Name, assignment.Target.SourceLocation, false);
           }
           seenNamedArgument = true;
           arguments[i] = new NamedArgument(name, assignment.Source, assignment.SourceLocation);
         }
         if (sourceAttributes == null) sourceAttributes = new List<SourceCustomAttribute>(1);
         sourceAttributes.Add(new SourceCustomAttribute(target, type, arguments, mcall.SourceLocation));
       } else if (expr is SimpleName || expr is QualifiedName || expr is AliasQualifiedName) {
         AttributeTypeExpression type = new AttributeTypeExpression(expr);
         if (sourceAttributes == null) sourceAttributes = new List<SourceCustomAttribute>(1);
         sourceAttributes.Add(new SourceCustomAttribute(target, type, new List<Expression>(0), expr.SourceLocation));
       } else {
         this.HandleError(expr.SourceLocation, Error.ExpectedIdentifier);
       }
       if (this.currentToken != Token.Comma) break;
       this.GetNextToken();
     }
     this.Skip(Token.RightBracket);
   }
   if (sourceAttributes != null) sourceAttributes.TrimExcess();
 }
示例#57
0
 private void ParseNestedStructDeclaration(List<ITypeDeclarationMember> typeMembers, List<SourceCustomAttribute>/*?*/ attributes, TypeDeclaration.Flags flags, SourceLocationBuilder sctx, TokenSet followers)
   //^ requires this.currentToken == Token.Struct;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   this.GetNextToken();
   if (!Parser.IdentifierOrNonReservedKeyword[this.currentToken])
     this.HandleError(Error.ExpectedIdentifier);
   NameDeclaration name = this.ParseNameDeclaration();
   List<Ast.GenericTypeParameterDeclaration> genericParameters = new List<Ast.GenericTypeParameterDeclaration>();
   List<TypeExpression> baseTypes = new List<TypeExpression>();
   List<ITypeDeclarationMember> members = new List<ITypeDeclarationMember>();
   NestedStructDeclaration type = new NestedStructDeclaration(attributes, flags, name, genericParameters, baseTypes, members, sctx);
   typeMembers.Add(type);
   this.ParseRestOfTypeDeclaration(sctx, type, genericParameters, baseTypes, members, followers);
 }
示例#58
0
 private void ParseNestedDelegateDeclaration(List<ITypeDeclarationMember> typeMembers, List<SourceCustomAttribute>/*?*/ attributes, TypeDeclaration.Flags flags, SourceLocationBuilder sctx, TokenSet followers)
   //^ requires this.currentToken == Token.Delegate;
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   this.GetNextToken();
   TypeExpression returnType = this.ParseTypeExpression(false, false, followers|Token.LeftParenthesis|Token.Semicolon|Parser.IdentifierOrNonReservedKeyword);
   if (!Parser.IdentifierOrNonReservedKeyword[this.currentToken])
     this.HandleError(Error.ExpectedIdentifier);
   NameDeclaration name = this.ParseNameDeclaration();
   List<Ast.GenericTypeParameterDeclaration> genericParameters = new List<Ast.GenericTypeParameterDeclaration>();
   List<Ast.ParameterDeclaration> parameters = new List<Ast.ParameterDeclaration>();
   SignatureDeclaration signature = new SignatureDeclaration(returnType, parameters, sctx);
   NestedDelegateDeclaration type = new NestedDelegateDeclaration(attributes, flags, name, genericParameters, signature, sctx);
   typeMembers.Add(type);
   this.ParseGenericTypeParameters(genericParameters, followers|Token.LeftParenthesis|Token.Where|Token.Semicolon);
   this.ParseParameters(parameters, Token.RightParenthesis, followers|Token.Where|Token.Semicolon, sctx);
   this.ParseGenericTypeParameterConstraintsClauses(genericParameters, followers|Token.Semicolon);
   sctx.UpdateToSpan(this.scanner.SourceLocationOfLastScannedToken);
   if (this.currentToken == Token.Semicolon)
     this.GetNextToken();
   this.SkipTo(followers);
 }
示例#59
0
 private void ParseRestOfTypeDeclaration(SourceLocationBuilder sctx, TypeDeclaration type, List<Ast.GenericTypeParameterDeclaration> genericParameters,
   List<TypeExpression> baseTypes, List<ITypeDeclarationMember> members, TokenSet followers)
   //^ ensures followers[this.currentToken] || this.currentToken == Token.EndOfFile;
 {
   this.ParseGenericTypeParameters(genericParameters, followers|Token.Colon|Token.LeftBrace|Token.Where);
   this.ParseBaseTypes(baseTypes, followers|Token.LeftBrace|Token.Where);
   this.ParseGenericTypeParameterConstraintsClauses(genericParameters, followers|Token.LeftBrace);
   this.Skip(Token.LeftBrace);
   this.ParseTypeMembers(sctx, type.Name, members, followers|Token.RightBrace);
   ISourceLocation tokLoc = this.scanner.SourceLocationOfLastScannedToken;
   //^ assume tokLoc.SourceDocument == sctx.SourceDocument;
   sctx.UpdateToSpan(tokLoc);
   this.Skip(Token.RightBrace);
   if (this.currentToken == Token.Semicolon)
     this.GetNextToken();
   this.SkipTo(followers);
 }
示例#60
0
 private List<SourceCustomAttribute>/*?*/ ParseAttributes(TokenSet followers) {
   List<SourceCustomAttribute>/*?*/ result = null;
   this.ParseAttributes(ref result, false, followers);
   this.SkipTo(followers);
   return result;
 }