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 (!Les2Lexer.IsIdContChar(c)) { if (Les2Lexer.IsSpecialIdChar(c)) { special = true; } else { backquote = true; } } else if (first && !Les2Lexer.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); }
static bool IsSpecialIdentifier(UString name, out bool backquote) { backquote = name.Length == 0; bool special = false, first = true; foreach (char c in name) { if (!Les2Lexer.IsIdContChar(c)) { if (Les2Lexer.IsSpecialIdChar(c)) { special = true; } else { backquote = true; } } else if (first && !Les2Lexer.IsIdStartChar(c)) { special = true; } first = false; } // Watch out for named literals with punctuation e.g. @`-inf_d` and @`-inf_f`: // they will be interpreted as named literals if we don't backquote them. if (special && !backquote && Les2Lexer.NamedLiterals.ContainsKey(name)) { backquote = true; } return(special || backquote); }
protected override void StartToken(char nextCh) { if (_newlinePending) { Newline(); } if (Les2Lexer.IsIdContChar(_lastCh) && Les2Lexer.IsIdContChar(nextCh)) { _out.Write(' '); } else if (Les2Lexer.IsOpContChar(_lastCh) && Les2Lexer.IsOpContChar(nextCh)) { _out.Write(' '); } else if (_lastCh == '-' && (nextCh >= '0' && nextCh <= '9')) // - 2 is different from -2 (-(2) vs integer literal) { _out.Write(' '); } }
protected override void OnNodeChanged(char nextCh) { var lastCh = LastCharWritten; if (Les2Lexer.IsIdContChar(lastCh) && Les2Lexer.IsIdContChar(nextCh)) { StringBuilder.Append(' '); } else if (Les2Lexer.IsOpContChar(lastCh) && Les2Lexer.IsOpContChar(nextCh)) { StringBuilder.Append(' '); } else if (JustWroteSymbolOrSpecialId && Les2Lexer.IsSpecialIdChar(nextCh)) { StringBuilder.Append(' '); } JustWroteSymbolOrSpecialId = false; }