Comments (3)
What would it take to support newer versions of C# and even other flavors, i.e. CSharp Scripting?
I try to keep up with C# upgrades but it doesn't current support all of C# 7, so they're still a bunch of things to implement. I don't have the list at the moment.
C# scripting is probably a trivial alternative to C# so I'm pretty sure it could fit in the existing C# grammar of the plugin.
Would the antlr project be the right place to implement the grammar?
No, ANTLR is a parser generator. It doesn't officially provide grammars. The only I'm implementing at the moment is an upgrade of https://github.com/antlr/grammars-v4/tree/master/csharp.
Do you know if other projects can be reused, i.e. Visual Studio already has code formatting and MS has made a lot of stuff open source? Maybe they also have some sort of "grammar" files somewhere?
No they don't. Trust me, I've looked :) C# doesn't have an up-to-date grammar specification.
One alternative is to use the actual Roslyn compiler instead of a custom grammar, and you can find the beginning of an implementation on a branch: https://github.com/warrenseine/prettier-plugin-csharp/tree/roslyn.
General question about grammar vs formatting: I assume the grammar is some kind of ruleset or syntax about what is considered "the language", whereas formatting is only concerned about all whitespaces and linebreaks. It seems that the formatting is defined in src/printer.js. Am I roughly correct?
Yes, you are. Parsing and printer are different and implemented in different files, but they are also tightly coupled. As we don't have an official AST specification, the printer expects a specific AST from the parser, so you can't just drop-in any parser and hope get it formatted. In other words, a lot of language logic exists in the printer.
from prettier-plugin-csharp.
Thanks for the explanations.
Follow up question regarding C# scripting:
If I understand you correctly allowing to have c# code (and functions) on the root level of a file (i.e. not nested in any namespace, class or function) is totally doable and could be directly supported by this plugin?
C# scripting also has some way of referencing other dlls, to give an example I think the following is something I would want to be supported:
// Reference to an assembly
#r "Newtonsoft.Json.dll"
using System;
using Newtonsoft.Json;
// class without namespace
class Product
{
public Guid Id{get;set;}
public string Name{get;set;}
public bool Enabled{get;set;}
}
// function without namespace and class
void Foo() {
}
// some code without namespace, class and function
var productObj = new Product {
Id = Guid.NewGuid(),
Name = "FooBar",
Enabled = true
};
Console.WriteLine(JsonConvert.SerializeObject(productObj));
from prettier-plugin-csharp.
Yes, I believe it should be easy to implement in the current parser and printer.
Not sure how Iād do it, but two ways I can think of:
- Add a new
compilation_unit
that allows all these new rules at the root of the file. - Fit new rules into the existing
compilation_unit
(could be tricky as the printer already makes some assumptions that could break usual C# code).
Not much to do on the printer side I think.
from prettier-plugin-csharp.
Related Issues (20)
- How to install and use as plugin in VSCode? HOT 2
- Rename project? HOT 1
- Sorting 'System' first is deprecated HOT 2
- Support for C# 7 local functions HOT 2
- String interpolation handled incorrectly HOT 1
- Can I run this directly from Visual Studio? Are there plans for an extension? HOT 3
- Are you accepting contributors? HOT 2
- Bug: Embedded Empty Statements are deleted HOT 2
- Mixed tabs & spaces HOT 1
- Comments inside empty class definitions don't get printed HOT 1
- Empty braces are not consistently formatted HOT 2
- How to install - doesn't seem to work HOT 2
- JavaScript heap out of memory when importing HOT 7
- Inconsistent #if ... #endif blocks reformatting HOT 2
- Activity HOT 2
- Unable to run HOT 1
- Using formatting HOT 5
- no viable alternative at input 'default;' HOT 1
- What is the current status on this plugin? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prettier-plugin-csharp.