Exemplo n.º 1
0
        protected virtual void ReadSuffix(ISourceStream source, CompoundTokenDetails details)
        {
            if (!_suffixesFirsts.Contains(source.PreviewChar))
            {
                return;
            }
            var comparisonType = CaseSensitivePrefixesSuffixes ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase;

            foreach (string sfx in Suffixes)
            {
                //Suffixes are usually case insensitive, even if language is case-sensitive. So we cannot use source.MatchSymbol here,
                // we need case-specific comparison
                if (string.Compare(source.GetText(source.PreviewPosition, sfx.Length), 0, sfx, 0, sfx.Length, comparisonType) != 0)
                {
                    continue;
                }
                //We found suffix
                details.Suffix          = sfx;
                source.PreviewPosition += sfx.Length;
                //Set TypeCode from suffix
                TypeCode[] codes;
                if (!string.IsNullOrEmpty(details.Suffix) && SuffixTypeCodes.TryGetValue(details.Suffix, out codes))
                {
                    details.TypeCodes = codes;
                }
                return;
            } //foreach
        }     //method
Exemplo n.º 2
0
        protected override Token QuickParse(ParsingContext context, ISourceStream source)
        {
            if (!_allFirstCharsSet.Contains(source.PreviewChar))
            {
                return(null);
            }
            source.PreviewPosition++;
            while (_allCharsSet.Contains(source.PreviewChar) && !source.EOF())
            {
                source.PreviewPosition++;
            }
            //if it is not a terminator then cancel; we need to go through full algorithm
            if (!this.Grammar.IsWhitespaceOrDelimiter(source.PreviewChar))
            {
                return(null);
            }
            var token = source.CreateToken(this.OutputTerminal);

            if (CaseRestriction != CaseRestriction.None && !CheckCaseRestriction(token.ValueString))
            {
                return(null);
            }
            //!!! Do not convert to common case (all-lower) for case-insensitive grammar. Let identifiers remain as is,
            //  it is responsibility of interpreter to provide case-insensitive read/write operations for identifiers
            // if (!this.GrammarData.Grammar.CaseSensitive)
            //    token.Value = token.Text.ToLower(CultureInfo.InvariantCulture);
            CheckReservedWord(token);
            return(token);
        }
Exemplo n.º 3
0
        protected virtual void ReadPrefix(ISourceStream source, CompoundTokenDetails details)
        {
            if (!_prefixesFirsts.Contains(source.PreviewChar))
            {
                return;
            }
            var comparisonType = CaseSensitivePrefixesSuffixes ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            foreach (string pfx in Prefixes)
            {
                // Prefixes are usually case insensitive, even if language is case-sensitive. So we cannot use source.MatchSymbol here,
                // we need case-specific comparison
                if (string.Compare(source.Text, source.PreviewPosition, pfx, 0, pfx.Length, comparisonType) != 0)
                {
                    continue;
                }
                //We found prefix
                details.Prefix          = pfx;
                source.PreviewPosition += pfx.Length;
                //Set flag from prefix
                short pfxFlags;
                if (!string.IsNullOrEmpty(details.Prefix) && PrefixFlags.TryGetValue(details.Prefix, out pfxFlags))
                {
                    details.Flags |= (short)pfxFlags;
                }
                return;
            } //foreach
        }     //method