Beispiel #1
0
        public static Parser <SyntaxToken> IdentifierOrKeyword()
        {
            var keywords = SyntaxFacts.GetKeywords().ToArray();

            var identifier = IdentifierStartCharacter()
                             .Once()
                             .Concat(IdentifierPartCharacter().Many())
                             .Text();

            return(identifier
                   .Or(Parse.Char('@').Then(_ => identifier.Select(x => "@" + x)))
                   .Select(x => keywords.Contains(x) && x[0] != '@' ? Syntax.Keyword(x) : Syntax.Identifier(x)));
        }