Hello, is there a maintained project that includes a file with 100 % of Rust's syntax? I'm working on syntax highlighting and it would be very useful for me if I would be able to see every variation of syntax. I could write my own, but I'm really not sure I won't miss something, and it makes sense to be maintained instead.
I'm not aware of something like that, but searching for big files in known crates and scrolling to the bottom maybe could help in detecting wrong syntax highlighting?
That's my current approach, but it turns out to be quite deficient
Unfortunately, it does not. For example, there is no associated types or static variables or global consts
Then it's quite likely that a document such as what you're requesting currently doesn't exist.
I would imagine that:
find rust/tests -name '*.rs' -exec cat {} \; >torture.rs
Would produce a file with everything. (and would be a good benchmarking target as well)
Well, my intended use case is to open it in 2 editors and compare highlight by eyes, so this is probably not a tangible solution for that problem...
in case like this , which it wont be available . what about creating a file yourself , and add to it whenever you learn smth new? like you need smth , you find its possible and then add it to the file and publish it to we all benefit from it
This sounds like you'd want to fuzz your syntax highlighting code. Intuitively, I think you could try to programmatically generate a random but syntactically valid Rust file, possibly using syn
.
The sheer number of syntactic elements in Rust makes this a daunting task, though. I'd try to find a shortcut here, but so far I can't think of any.
At this point, I'd cast a doubt whether you actually need such a comprehensive testing, given the Rust Project hasn't needed one.
This is one of those times when it would have been useful if there had been a normative EBNF-style declarative grammar for Rust. It would have made it relatively easy to create a random code generator.
This sounds more like "The Universal Library" (written by Kurd Lasswitz. Nice short story to read!). You'd have to follow every possible branch of the EBNF of Rust to get a complete test-file.
But if you strictly use Rust's EBNF for your highlighting, you already have implemented all possible branches and not a single path was left out.
What could go possibly wrong [tm].
I didn't find Rusts's EBNF (except this incomplete and outdated one: Grammar).