Esempio n. 1
0
        static bool IsSpecialIdentifier(Symbol name, out bool backquote)
        {
            backquote = name.Name.Length == 0;
            bool special = false, first = true;

            foreach (char c in name.Name)
            {
                if (!LesLexer.IsIdContChar(c))
                {
                    if (LesLexer.IsSpecialIdChar(c))
                    {
                        special = true;
                    }
                    else
                    {
                        backquote = true;
                    }
                }
                else if (first && !LesLexer.IsIdStartChar(c))
                {
                    special = true;
                }
                first = false;
            }

            // Watch out for @`-inf_d` and @`-inf_f`, because they will be
            // interpreted as named literals if we don't backquote them.
            if (special && !backquote && (name.Name == "-inf_d" || name.Name == "-inf_f"))
            {
                backquote = true;
            }
            return(special || backquote);
        }
Esempio n. 2
0
        private void PrintIdOrSymbol(Symbol name, bool isSymbol)
        {
            // Figure out what style we need to use: plain, \\special, or \\`backquoted`
            bool special = isSymbol, backquote = name.Name.Length == 0, first = true;

            foreach (char c in name.Name)
            {
                if (!LesLexer.IsIdContChar(c))
                {
                    if (LesLexer.IsSpecialIdChar(c))
                    {
                        special = true;
                    }
                    else
                    {
                        backquote = true;
                    }
                }
                else if (first && !LesLexer.IsIdStartChar(c))
                {
                    special = true;
                }
                first = false;
            }

            if (special || backquote)
            {
                _out.Write(isSymbol ? "@@" : "@", false);
            }
            if (backquote)
            {
                PrintStringCore('`', false, name.Name);
            }
            else
            {
                _out.Write(name.Name, true);
            }
        }