vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.86k stars 2.17k forks source link

Declare Language Specification #288

Open malisetti opened 5 years ago

malisetti commented 5 years ago

Something like https://golang.org/ref/spec

spy16 commented 5 years ago

This is important I think. Can help reduce ambiguity for any contributors. I'd like to help if you all think we should do this.

LouCle commented 5 years ago

V already has https://vlang.io/docs.

spy16 commented 5 years ago

I was talking about more of a language spec. With technical description of grammar and implementation details. Docs section is more of a language usage documentation

LouCle commented 5 years ago

Ah. We have been talking about writing an extensive compiler specification. I'll pin this issue.

medvednikov commented 5 years ago

These are different things. @mseshachalam refers to language spec, you refer to compiler spec.

spy16 commented 5 years ago

@medvednikov Do you think it would be good idea to start on this ? I am interested in working on this.

ntrel commented 5 years ago

It might be good to require new features to the compiler to come with spec docs. The existing features can be documented over time (0.2 seems too ambitious and no one's volunteered, plus some features are probably still in flux).

spy16 commented 5 years ago

Agreed about new compiler features to come with spec docs. With respect to existing ones, that was precisely the question. "starting" on it. Also, syntax-wise i think @medvednikov has already sort of finalized it. So, only implementation is under flux. My thought was that some type of formal documentation can help contributors to the compiler itself.

medvednikov commented 5 years ago

Yeah, I think that would be great, @spy16

I've also created an RFC repo: https://github.com/vlang/rfcs

spy16 commented 5 years ago

Any thoughts on how to get started here? Golang language specification is simple and straightforward. But what about the file format ? are you expecting it to be in markdown or something else? @medvednikov

mindplay-dk commented 5 years ago

Does it make sense to write a spec at this point already? It sounds like a lot of features and syntax are still being discussed.

Might make more sense to extract a specification after 1.0, so the language can grow and settle organically until then?

hsiaosiyuan0 commented 5 years ago

I'd like to contribute a V to JavaScript compiler, it's better to have a relatively clear spec about the grammar

theonewolf commented 4 years ago

@mindplay-dk it is important to write a spec to test, via proof, fundamental properties of the language such as progress and preservation.

See chapter 6 on Type Safety: http://www.cs.cmu.edu/~rwh/pfpl/2nded.pdf

Here's another short writeup on StackOverflow: https://cs.stackexchange.com/a/58124

I would be very excited to see V formally specified, and have type safety properties proven on its specification. This would level up the language in maturity, and a more confident choice for engineers to use.

mindplay-dk commented 4 years ago

@theonewolf I agree with all of that, as such - but the author seems to be taking more of an organic, exploratory approach, and having to maintain a spec as well basically double the workload.

At this stage, it might be better to have an executable spec, something like what PHP has? Basically a bunch of files saying "given this V input, program should give this output" - the benefit of an executable spec is, someone writing (say) a JS compiler for the V language, can easily run the exact same tests; so you're not just relying on written communication between the spec author and someone implementing the spec, but rather you have something formal and repeatable.

V lends itself well to this style of testing, being able to run a program from source-code directly. Many of the library features are already using that style of testing. The core language tests don't use this style of testing - so these are more like unit-tests, which, if you can run them and they pass, you're complying with the spec, but it's still an executable spec, and someone implementing an alternative compiler could definitely reuse this.

That said, a formal AST spec might make sense though. :-)

theonewolf commented 4 years ago

@mindplay-dk I'm happy with any step in this direction. I really love the conciseness of V overall. Something feels good about that.

Let's not aim for perfect, or even good, when we just need good enough right now.

medvednikov commented 4 years ago

We will have a formal spec after 1.0.

medvednikov commented 4 years ago

And the language will barely change after 1.0, similar to Go.

wenq1 commented 1 year ago

The parser might be generated by a higher order function using BNF or PEG. See

https://github.com/pointlander/peg

mingodad commented 1 year ago

See also this https://github.com/vlang/vls/issues/428 EBNF grammar to be viewed at https://www.bottlecaps.de/rr/ui