Skip to content

Add an LSP demo for BIPL#3

Open
VivekanandaReddy3 wants to merge 1 commit into
softlang:masterfrom
VivekanandaReddy3:bipl-lsp
Open

Add an LSP demo for BIPL#3
VivekanandaReddy3 wants to merge 1 commit into
softlang:masterfrom
VivekanandaReddy3:bipl-lsp

Conversation

@VivekanandaReddy3

Copy link
Copy Markdown

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant