-
Notifications
You must be signed in to change notification settings - Fork 1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotated Text for C# and VB #1775
Comments
I think that it's overcomplicated and under performs. For example, in your JSON example, due to generic parsing of the string you eliminate the ability to include double quotes. Strict JSON only accepts double quotes for strings. So you could switch to using single quotes as the delimiters, but then you preclude the ability to include single quotes within strings. You'd need a second escape mechanism just to support that, twice over as it also needs to support escaped characters embedded in the JSON also. For normal strings that might require validation I'd much prefer the simple analyzer approach that can be tuned to know when a String literal might contain JSON either by recognizing known method invocation patterns (e.g. |
@HaloFour In the JSON example the content could be plain old contents of string. |
You have to propose changing that if you're planning on having custom prefixes and postfixes. That would completely change the meaning of |
I like the idea of custom string literals. Custom escape sequences, compile-time and/or runtime errors, and custom parsing can really add value and enable embedded DSLs. The compile-time side would probably need to be something that could plug into Roslyn akin to an analyzer. Then there wouldn't be a need for the custom syntax. (Of course, you could then create the custom syntax on top of that using such an embedded DSL.) |
@AdamSpeight2008 This feels very unnecessary for something at the csharplang level. This seems to be about tooling/APIs. Why would it not be sufficient to just have |
Note: what would be interesting (and i think is in line with what @HaloFour is saying) would be if you could have a language construct that then allowed you to control things like escaping/quotation. Because then you could embed something like html, without having to figure out how to escape every quote character you will definitely encounter. If htis doesn't really address that, then this is effectively mostly a request to make public the work i'm doing over in the linked PR. That would be more appropriate over at dotnet/roslyn as this is asking for a plugin API for DSLs. I'm definitely supportive of that. However, it would be driven elsewhere. |
cough #89 cough 😁 |
Semantically, this feels wrong, I understand why you would suggest that but asking why it wouldn't be sufficient is really weird coming from you which to me feels almost as if you're trolling, regardless, here are 4 reasons why it wouldn't be sufficient:
Something like this should be addressed by the language and in my opinion this is a step in the right direction, combining #89 and #1452 we could do something like this |
Source-only attributes just adds another way that tools/editors have for hinting that the string is JSON. 😄 |
I'm puzzled. |
Not trolling. It was a genuine question.
Your second sentence completely contradicts the first. You say they're not supposed to provide hints to productivity tools... and then you show how they're exactly used to provide hints to productivity tools :)
Why not? We can have intellisense do whatever we want it to do. Also, using comments to provide extra info has a long history of prior art. TypeScript still uses this as a core part of its language/tooling story.
I don't get this. So what if users remove it? If it's not helping them, then they'll remove it and will be fine. If it's helping them... they won't remove it :)
Easy. Have those tools update themselves to support the community conventions. I mean... how would you expect it to work with Adam's suggestion? Why/how would resharper understand |
Agreed. Humorously enough, part of the discussion around source-attributes is that they're simply 'trivia'. That way from a language/impl perspective you can have them between any tokens. They would effectively just be comments, but perhaps with a slight bit of structure to them to help drive consistency across usage. if we had that, then i would simply say:
I don't see hte need for a specific type of string literal. Just have a generalized annotation ability (and, absent that, just use a comment). It's more than sufficient for the needs of intellisense. |
Okay. :)
lol, it's merely poor wording on my part but what I meant is that comments shouldn't be used for hints but they are by some productivity tools because we don't have a better alternative.
Are you referring to JSDoc? JSDoc was defined prior to TypeScript and it supports it because it has to, people that migrate their codebases from JavaScript to TypeScript would want to do it gradually and it wouldn't be sensible for a tool that supposed to be a superset of JavaScript to just ignore it, especially when TypeScript can take advantage over it and improve the experience but JSDoc is also well defined unlike in the case of C# where it's really arbitrary at least for the time being and each vendor has its own way to add hints. |
I don't see any C# language change request or proposal here. Am I not understanding, or is this in the wrong github repository? |
The point is to have a well defined approach that helps everyone and allow developers to be more productive everywhere regardless to the tools they choose to use, the point for these hints to be part of the code not foreign to the code. Removing and adding comments will just add contention between developers, especially, in open source projects where it's not too far fetched for developers to use different tools.
I actually don't expect it to work out of the box. If we could come up with a convention then it might be good enough for the IDE and productivity tools to recognize it and offer intellisense and color highlighting but I really can't see how this "community conventions" will happen.
If this is sufficient then why some attributes that are merely hints to the compiler are not comments? I know there's no motivation to add attributes everywhere or similar concept into the language atm because there aren't enough if at all use-cases to support it besides what we're discussing here that can be solved by abusing comments and introducing conventions. It's not just intellisense, it's highlighting too with something like attributes everywhere you get this for free with comments it's not really free. |
Using comments in VB would be a little trickier as it doesn't have comment blocks eg |
There are consider the same as plain old strings, just extended by a prefix (which helps the parser etc ). Output = switch( prefix )
{
case "$": Parse_As_Interpolation_String()
case "@": Parse_As_Verbatim_String()
case "$@":
case "@$": Parse_As_InterpolationVerbatim_String()
default:
var valid = parsers.TryGetKey(prefix, out parser )
if( valid )
{
parser( );
}
else
{
Parse_As_Plain_Old_String()
}
} |
@gafter This proposal enables custom string delimiters. Relaxing that, I don't think it would necessitate a language change. |
Well... the IDE is going to support I'm really not seeing how it will be much different from typing |
Ok... but what makes the alternative better? At best i can get a marginal benefit claim here. But it's reallllllly razor thin. So i'd rather just work with what we have and what works in the ecosystem today rather than have to spend a bunch of effort to get back to the point we could already be at today. |
I am not referring to jsdoc. I am referring to |
This is a very dangerous thing to support, because there is no guarantee your 'parser' function will support all the requirements necessary for incremental parsing. It would also require the internal implementation of the lexer and parser (which are complex) be made publicly available. These subsystems are quite complex due to many factors (incremental parsing, nested xml support, preprocessors, etc.), and i do not think there is any realistic way they could be exposed for extensibility purposes without a massive amount of effort being thrown into them. |
You rarely get anything for free :) Even if htis was 'attributes everywhere' it would not be free. You would still have to update pretty much all (or at least 'most') IDE features to support this new concept. You think it's free because someone (often me :D) goes off and does all the work to support that feature. But that someone (again me, in this case :D) went and showed that all that work can also be done using comments as the signifier, and without requiring any new syntax. |
@CyrusNajmabadi To me it depends on whether the custom string parser could affect C# parsing, say by providing a different escape literal. If so, I would prefer not to use a comment for the annotation since I don't feel it is appropriate for the reader to ignore the annotation. |
@bondsbw Agreed. If this actually changes string parsing, i think it needs to be a new construct of some sort. However, for changing string parsing, it would then need to be something very limited that we can control (i.e. something like @HaloFour 's proposal). Otherwise, all bets are off in terms of how we could make things like incremental parsing work. Note: i really don't know how to effectively expose offering different escape literals. The best i can think of is that you support custom delimiters. Then, while parsing, you treat it like a verbatim literal, where there are no escapes. And until you hit your delimiter, every character you run into is just a plain char. |
@CyrusNajmabadi I trust your judgement and expertise in this area and if you think that comments are just as good I'm down with it. ❤️ |
I'm just stating that i think they're "good enough" especially for the case where this isn't actually changing/enabling anything different lexically/syntactically. I was able to personally get this working in just a few days (though it's now been 8 months just waiting on reviews ... :( ). So, to me, the marginal benefit of a language feature here is minimal. :) |
I found this proposal after considering making one myself. I've recently started using the lit-html for front end Javascript development and realized that it is founded on the concept of tagged template literals which I hadn't realized were part of the newish template literal feature which basically similar to C# string interpolation. The main difference with a tagged template literal is that it allows one to specify a function, referred to as a "tag", as a prefix to the literal which takes the template and the parameters as arguments and allows returning any type of value as a result. Think something like Example lit-html in ES6: const helloTemplate = (name) => html`<div>Hello ${name}!</div>`; Having this feature in the .NET language space (C#, F#, VB?) but having it work to produce a custom literal at compile time would be nice. My particlar use case would be to allow defining a custom literal of sorts for utf8 strings as defined in the NStack library. Example potential literal for ustring: var myUtf8String = utf8`My String with each char as only a single byte.`; Perhaps like with |
You can already do this today in C#. in JS When you write: The equivalent in C# is to just write: someTag($"1{2 + 3}4");
// ...
void someTag(FormattableString s)
{
var format = s.Format;
var args = s.GetArguments();
// do wahtever you want
} The only difference between JS and C# here is one of syntax. JS allows |
You could do that today in C# as: |
Excellent! Now in the case of utf8 it would be nice if this could become a
complile time operation to safe the default UTF16 string litteral
allocation.
…On Wed, Aug 22, 2018, 1:15 AM CyrusNajmabadi ***@***.***> wrote:
Example potential literal for ustring:
You could do that today in C# as: Utf8($"whatever you want")
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1775 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABZjCqghKuOm1a_WYak_rNIFxkF-jnxKks5uTOjegaJpZM4VwVkH>
.
|
That's an entirely different request :) It's completely unrelated to tag or templates and whatnot. :) Feel free to open an issue on that (if it doesn't already exist). |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
I've be think about abstracting out the internal definitions of String / Char syntax nodes in C# and VB.
So that it allows us raise some validation from syntax to semantics, as well as acting as base to help implement addition textual constructs.
Syntax Layout (Draft)
Existing Definitions as AnnotatedText
Reference: VirtualChar
Semantic Validation
Which allows possible codefixes to be offered. Remove Invalid Characters and Remove Char Literal Character.
Prefix
The Prefix part of the design allows the IDE to support contextual Intellisense, compile-time validation and aid the colourisation.
Content
This provide specific contextual parsing / syntax.
Examples
GUID Literal
JSON
The text was updated successfully, but these errors were encountered: