Add B (Formal Method) language #7651
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request adds the detection of files used for the B formal method.
The B-method is a formal method for writing code that satisfies some formal mathematical description. You start with a mathematical machine (
.mch), refine it in refinement steps (.ref), and finally end with an implementation (.imp), which can be transpiled into an executable programming language (such as C, ADA, or Rust.)These files are not commonly checked into public github repositories, as the projects are generally either too academic or too corporate. This means the latter two extensions are on the border of acceptable of being added to linguist, with the most questionable being
.ref, which has a little over two hundred files, most of which are in separate repositories as far as I can tell.For the syntax highlighting, I had to write my own tmGrammar file, as none exist (though Vim does supports B without plugins,) which I did basing myself on the open B Language Reference, making a quick VSCode extension. I did this in one grammar file instead of three because the B Language Reference describes it like that.
I used the name
B (Formal Method)to not confuse anyone about it being the predecessor of C, which is a different language called B. This B is a successor of Z.Because machine, refinement (or reference) and implementation are not terms unique to B, the extensions are not either, even while no other users are in linguist currently. Because of this, I added some heuristics that should allow these extensions to only be classified as B when they are B, leaving them unclassified otherwise.
Checklist:
.mch, Machine file, starting point of the B-method: https://github.com/search?type=code&q=NOT+is%3Afork+path%3A*.mch+MACHINE+END.imp, Implementation file, end point of the B-method: https://github.com/search?type=code&q=NOT+is%3Afork+path%3A*.imp+IMPLEMENTATION+OPERATIONS+END.ref, Refinement file, containing the intermediate steps from machine to implementation: https://github.com/search?type=code&q=NOT+is%3Afork+path%3A*.ref+REFINEMENT+REFINES+END#8aa8c5.mch,.imp, or.ref, but a search of the files finds that all of these extensions are more commonly used outside of the B method, so I added heuristics. For each of those heuristics, my intent is to have the file only be classified as B if the regex pattern matches, else having it remain an unclassified file, but I did not find a way to test this working.