Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom syntax extensions #2909

Merged
merged 14 commits into from
May 4, 2023
Merged

Support for custom syntax extensions #2909

merged 14 commits into from
May 4, 2023

Conversation

nikswamy
Copy link
Collaborator

@nikswamy nikswamy commented May 2, 2023

This PR adds support for custom syntax extensions.

You can write in place of a top-level declaration

```your_dsl_name
whatever syntax
```

In a compiler plugin, you can call

val register_extension_parser (extension_name:string) (parser:extension_parser) : unit

passing "your_dsl_name" to register a custom parser for whatever syntax your DSL chooses.

The extension_parser has type:

type extension_parser = 
   open_namespaces_and_abbreviations ->
   contents:string ->
   p:FStar.Compiler.Range.range ->
   either error_message decl'

receiving:

  1. open_namespaces_and_abbreviations: The open namespaces and module abbreviations in the current scope environment

  2. the concrete syntax of the your DSL as a string

  3. The source range at which the string begins (so you can report syntax errors relative to the position in the source file)

and returning

either an error message or a FStar.Parser.AST.decl'. If the latter, then this decl' is processed by the rest of the compiler pipeline as is.

For an example of this mechanism see: https://github.com/FStarLang/steel/blob/nik_ranges/share/steel/examples/pulse/CustomSyntax.fst

Base automatically changed from taramana_no_steel to master May 3, 2023 17:37
@nikswamy nikswamy merged commit 4a89fa2 into master May 4, 2023
@nikswamy nikswamy deleted the nik_syntax_extension branch May 4, 2023 18:05
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