Esempio n. 1
0
        public Tuple <string, string[]> Match(string input)
        {
            var value = null as string;
            var match = null as string;
            var found =
                Lexicals.
                Where
                (
                    lexical =>
            {
                if (((match = lexical.Match(input)) != null) && (match.Length > 0))
                {
                    if (lexical.IsLiteral || !Literals.Contains(match))
                    {
                        value = value ?? match;
                        return(match == value);
                    }
                }
                return(false);
            }
                ).
                Select(lexical => lexical.Lhs).
                ToArray();

            return(Tuple.Create(value, found));
        }
Esempio n. 2
0
        /// <summary>
        /// Builds a table of characters and lexical information about them.
        /// </summary>
        /// <returns></returns>
        private static Lexicals[] CreateLexTable()
        {
            Lexicals[] table = new Lexicals[255];
            // Whitespace:
            table[' ']  |= Lexicals.IsWhiteSpace;
            table['\t'] |= Lexicals.IsWhiteSpace;
            table['\r'] |= Lexicals.IsWhiteSpace | Lexicals.IsEOF;
            table['\n'] |= Lexicals.IsWhiteSpace | Lexicals.IsEOF;

            // Name: (section 4.5 Names)
            // A name, like a string, is written as a sequence of characters. It must begin with a
            // slash (/) followed by a sequence of ASCII characters in the range ! (<21>)
            // through ~ (<7E>) except %, (, ), <, >, [, ], {, }, /, and #.
            string nameExluded = "%()<>[]{}/";             // NOTE SOME DISTILLER DOCS USE # as a name character.

            for (char ch = (char)0x21; ch <= 0x7e; ch++)
            {
                if (nameExluded.IndexOf(ch) < 0)
                {
                    table[ch] |= Lexicals.IsName;
                }
            }

            // Numbers, Hex and Octal
            for (char ch = (char)'0'; ch <= '9'; ch++)
            {
                if (ch < 9)
                {
                    table[ch] |= Lexicals.IsOctalDigit;
                }

                table[ch] |= (Lexicals.IsNumber | Lexicals.IsHexDigit | Lexicals.IsIdent);
            }

            // Characters & More Hex
            for (char ch = (char)'A'; ch <= 'Z'; ch++)
            {
                if (ch >= 'A' && ch <= 'F')
                {
                    table[ch] |= Lexicals.IsHexDigit;
                }

                table[ch] |= (Lexicals.IsAlpha | Lexicals.IsIdent);
            }
            for (char ch = (char)'a'; ch <= 'z'; ch++)
            {
                if (ch >= 'a' && ch <= 'f')
                {
                    table[ch] |= Lexicals.IsHexDigit;
                }
                table[ch] |= (Lexicals.IsAlpha | Lexicals.IsIdent);
            }

            return(table);
        }