[PATCH] D87495: [SyntaxTree][Synthesis] Add support for simple Leafs and test based on tree dump
Eduardo Caldas via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 11 05:34:17 PDT 2020
eduucaldas added inline comments.
================
Comment at: clang/lib/Tooling/Syntax/Synthesis.cpp:51
+ return createLeaf(A, tok::getKeywordSpelling(K), K);
+}
+
----------------
gribozavr2 wrote:
> Could we make a combined function that does not require the user to make a distinction between punctuation and keywords?
>
> We should also allow creating tokens that have a user-specified spelling, for example, identifiers and string literals.
>
> So maybe define two functions:
>
> ```
> // Uses the provided spelling.
> syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K, StringRef Spelling);
>
> // Infers spelling if possible.
> syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K);
> ```
>
First, thanks for the great comments!
> Could we make a combined function that does not require the user to make a distinction between punctuation and keywords?
We could!
Bui I wouldn't call it `createLeaf`, as it would work strictly for `Keyword`s or `Punctuator`s.
As an alternative we could unify the `createPunctuator`and `createKeyword` into `createPunctuatorOrKeyword` but I would argue that the previous two names are more readable. Effectively, we would be unifying those 2 functions because they have the same signature.
> We should also allow creating tokens that have a user-specified spelling, for example, identifiers and string literals.
That exists already! It is `createLeaf` as is!
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87495/new/
https://reviews.llvm.org/D87495
More information about the cfe-commits
mailing list