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); }
protected override void StartToken(char nextCh) { if (_newlinePending) { Newline(); } if (LesLexer.IsIdContChar(_lastCh) && LesLexer.IsIdContChar(nextCh)) { _out.Write(' '); } else if (LesLexer.IsOpContChar(_lastCh) && LesLexer.IsOpContChar(nextCh)) { _out.Write(' '); } }
protected override void StartToken(char nextCh) { if (_newlinePending) { Newline(); } if (LesLexer.IsIdContChar(_lastCh) && LesLexer.IsIdContChar(nextCh)) { _out.Write(' '); } else if (LesLexer.IsOpContChar(_lastCh) && LesLexer.IsOpContChar(nextCh)) { _out.Write(' '); } else if (_lastCh == '-' && (nextCh >= '0' && nextCh <= '9')) // - 2 is different from -2 (-(2) vs integer literal) { _out.Write(' '); } }
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); } }