Add an LSP demo for BIPL#3
Open
VivekanandaReddy3 wants to merge 1 commit into
Open
Conversation
Provide a language server and a minimal VS Code client for BIPL under languages/BIPL/Python/LSP, mirroring the FSML LSP demo. The server offers diagnostics, hover, go to definition, find references, rename, completion, document symbols and a quick fix. Diagnostics come from two analyses over the syntax tree: type checking, following Language.BIPL.TypeChecker and completing its binary-operator cases, and a definite-assignment data-flow pass. Since BIPL has no declarations, variable types are inferred from a first assignment or a constrained use. Since BIPL programs read inputs from the initial store, an unassigned read is not reported as an error: variables never assigned anywhere are reported as program inputs, and only those assigned on some paths but not all are warned about. The samples in languages/BIPL/samples analyse without errors, which a test enforces.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 adds a language server and a minimal VS Code client for BIPL under languages/BIPL/Python/LSP, laid out to mirror the existing FSML LSP demo.
Features: diagnostics, hover, go to definition, find references, rename, completion, document symbols, and a quick fix.
Static semantics. Two analyses run over the syntax tree:
Type checking, following Language.BIPL.TypeChecker. The Haskell version leaves its binary-operator case as -- TODO: Cases missing and covers Or, Add, Sub, Mul, Geq; this implementation covers the full operator set.
Definite assignment, a small data-flow pass: an if contributes only what both branches assign, and a while body contributes nothing since it may run zero times.
On unassigned reads. BIPL programs read inputs from the initial store, so a naive "read before write is an error" rule would reject the language's own samples — samples/factorialV1.bipl reads x under the comment "Assume x to be positive". Diagnostics therefore use three severities: errors for type mismatches, warnings for variables assigned somewhere but not on the path in question, and information for variables never assigned anywhere, which are program inputs.
Tests. pytest covers the checks and asserts that every sample in languages/BIPL/samples analyses without errors.
Notes. The parser is written directly in Python so every token and node carries a source range, and it keeps cs.egl's right-recursive associativity. It deviates from okStmt in one place: that rule requires both if branches to yield the same variable-type context, which would reject programs where one branch introduces a helper variable, so branches are checked independently and branch agreement is used only for definite assignment.
Happy to adjust the layout or naming to fit the repository's conventions.