Exemple #1
0
 /// <summary>
 /// Determines whether a particular character is valid as the first character of an atom.
 /// </summary>
 public static bool IsValidIdentifierAtomStartChar(char value)
 {
     return(SymbolCharacters.IsValidStartChar(value));
 }
Exemple #2
0
        private static ParseResult TryParseIdentifier <TChars>(
            ExpandedTokenData <TChars> token,
            PipExecutionContext context,
            ref int position,
            out TChars identifier,
            bool logErrors = true)
            where TChars : struct, ICharSpan <TChars>
        {
            Contract.Requires(token.IsValid);
            Contract.RequiresNotNull(context);

            var pathTable = context.PathTable;

            var text = token.Text;

            if (text.Length == 0 || position == text.Length)
            {
                var updateToken = token.UpdateLineInformationForPosition(position);
                identifier = default(TChars);
                return(new ParseResult()
                {
                    Status = ParseStatus.UnexpectedEmptyIdentifier,
                    Path = updateToken.Path.ToString(pathTable),
                    Line = updateToken.Line,
                    Position = updateToken.Position,
                });
            }

            int firstPosition = position;

            char firstChar = text[position];

            if (!SymbolCharacters.IsValidStartChar(firstChar))
            {
                var updateToken = token.UpdateLineInformationForPosition(position);
                identifier = default(TChars);
                return(new ParseResult()
                {
                    Status = ParseStatus.UnexpectedCharacterAtStartOfIdentifier,
                    Path = updateToken.Path.ToString(pathTable),
                    Line = updateToken.Line,
                    Position = updateToken.Position,
                    Text = firstChar.ToString(),
                });
            }

            position++;

            for (; position < text.Length; position++)
            {
                char ch = text[position];
                if (!SymbolCharacters.IsValidChar(ch))
                {
                    break;
                }
            }

            identifier = text.Subsegment(firstPosition, position - firstPosition);
            return(new ParseResult {
                Status = ParseStatus.Success
            });
        }