feat: formatter: escape identifiers
This commit is contained in:
parent
c43e6624f9
commit
eded953022
1 changed files with 12 additions and 3 deletions
|
|
@ -238,11 +238,20 @@ goLeft
|
|||
def identNoAntiquot.formatter : Formatter | _ => do
|
||||
checkKind identKind;
|
||||
stx ← getCur;
|
||||
-- TODO: pretty-print Name using «»
|
||||
pushToken stx.getId.toString;
|
||||
let s := stx.getId.toString;
|
||||
-- try to parse `s` as-is; if it fails, escape
|
||||
pst ← parseToken s;
|
||||
let s := if pst.stxStack == #[stx] then s else match stx.getId with
|
||||
| Name.str Name.anonymous s _ => "«" ++ s ++ "»"
|
||||
| _ => panic! "unimplemented: escaping non-atomic identifiers (is anyone even using those?)";
|
||||
pushToken s;
|
||||
goLeft
|
||||
|
||||
@[builtinFormatter rawIdent] def rawIdent.formatter := identNoAntiquot.formatter
|
||||
@[builtinFormatter rawIdent] def rawIdent.formatter : Formatter | _ => do
|
||||
checkKind identKind;
|
||||
stx ← getCur;
|
||||
pushToken stx.getId.toString;
|
||||
goLeft
|
||||
|
||||
def visitAtom (k : SyntaxNodeKind) : Formatter | p => do
|
||||
stx ← getCur;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue