[cfe-dev] RFC: Extend clang-format to support more/all C-like languages
Ryan Gonzalez
rymg19 at gmail.com
Fri Nov 1 13:13:32 PDT 2013
What if the lexer was an overly large, non-abstract base class? Then, the
derived classes can just override the tokens as needed.
On Fri, Nov 1, 2013 at 1:37 PM, Edwin Vane <revane at gmail.com> wrote:
> I think this is a great idea. clang-format is so useful and I'd love to be
> able to use it with other languges I use. I agree with Chris that lexing
> support for all these languages should be somehow separate from clang to
> prevent clang from becoming unmaintainably complex.
>
>
> On Fri, Nov 1, 2013 at 1:15 PM, Daniel Jasper <djasper at google.com> wrote:
>
>> The context-free parser implemented in clang-format is capable of (or can
>> easily be extended to) understand the structure of basically all C-like
>> languages. A basic definition of C-like languages is the “Influenced”
>> section of C’s Wikipedia page [1].
>>
>> At most, this includes: AMPL, AWK, csh, C++, C--, C#, Objective-C, BitC,
>> D, Go, Rust, Java, JavaScript, Limbo, LPC, Perl, PHP, Pike, Processing,
>> Seed7, Verilog. Today, clang-format already supports C, C++, Objective-C
>> and Objective-C++. Starting from there, it seems almost trivial to extend
>> support to JavaScript and Java which only contain a small number of
>> additional syntactical constructs and can be tokenized with Clang’s lexer.
>> Eventually, we also imagine (and would love to see patches for) formatting
>> C#, D, Go, Rust, and PHP based on their similar syntax and active usage.
>> Maybe there are others the community would be interested in seeing?
>>
>> The benefit of using the same format tool for all these jobs is that many
>> of clang-format’s advanced formatting algorithms (e.g. Tex-like analysis of
>> the entire solution space) are immediately available to the other languages.
>>
>> Concrete proposal:
>>
>> Start with JavaScript. Syntactically, it is very close to C++ and there
>> are already different efforts going on to combine JavaScript and LLVM. Add
>> an additional LanguageStandard (this flag already supports C++03 and C++11)
>> in clang-format’s configuration and gate JavaScript specific formatting
>> decisions (e.g. indentation of JavaScript’s namespace-equivalent on it).
>>
>> To make clang-format more useful to the LLVM project itself, support for
>> the tblgen language seems another worthy goal that can be achieved in the
>> same way as JavaScript.
>>
>> Thoughts? Comments? Concerns with this direction?
>>
>> If this is in line with LLVM’s/Clangs’s roadmap, we'll start working on
>> the few features missing for formatting JavaScript and we should have
>> rudimentary support towards the end of the year.
>>
>> [1] http://en.wikipedia.org/wiki/C_(programming_language)
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
>
>
> --
> Edwin V
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
--
Ryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131101/3f3d2f77/attachment.html>
More information about the cfe-dev
mailing list