-
Notifications
You must be signed in to change notification settings - Fork 2
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
add a meta-language for formal definitions #69
Conversation
The implementation of the used macro DSL is still missing.
It only performs basic parsing and validation.
It's important to note that due to the - not yet implemented - compile-time evaluation and meta programming facilities, a strict separation between static semantics (i.e., types, symbols, etc.) and dynamic semantics (i.e., how a program behaves at run-time) is not going to be possible. |
Not all rules mentioned in the documentation are enforced at this time.
The current meta-language is a bit too limited at the moment, so I'm going to start over with it. I've made some experiments with PLT Redex, which a gave me a lot of ideas on how to improve the meta-language. |
The new meta-language is more powerful and also more generally applicable, not enforcing a clear separation (or any separation at all) between static and dynamic semantics. Not everything is implemented and the meta-language is unlikely to be final, but it's a good start. The source language definition using the old meta-language is removed.
The definition uses the new meta-language and tries to stay as close to the previous textual definition as possible, even where the textual definition is "wrong".
Except for the special `grammar` section - which is still needed by the `passtool` -, the textual definition is fully superseded by the meta-language definition.
To keep the meta-language pragmatic, I developed a simple-but-working query engine for the meta-language during its development. Beyond making sure that the meta-language can actually be used to express the semantics of a somewhat realistic language, this also discovered a lot of issues with the current source language definition. I've fixed most of them already, but opted to keep the mostly literal translation of the language definition, so as to keep the PR smaller in scope. The query / pattern matching engine is not included in this PR because it no longer works (patterns requiring matching to "look ahead" were disallowed in the beginning, but no longer are, and the engine hasn't caught up yet). In general, the new meta-language is quite similar to Redex (the programming language). A major focus is on pattern matching and inductively-defined relations. The meta-language is certainly not perfect, but it's nonetheless a significant improvement over the hand-wavy notation used by the textual definition. Once there's some experience gathered regarding its shortcomings, some adjustments will most likely be in order / necessary. I've removed the goal of writing a language-to-RST renderer from this PR, because the language definition endeavor is progressing at a far too slow pace and I need to get back to working on the language and implementation itself. The query engine is far more important at the moment, because it's what will drive the language definition tests (and the lack thereof currently blocks further progress on the source language). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this is really cool, it can already represent so much!
for i in 1..<n[1].len: | ||
case n[1][i].kind | ||
of nnkIdent: | ||
# cannot use 'in', because that's a special token only usable as an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dang, that would have been sick
Only the `inp` identifier is allowed as a relation parameter; `out` parses as `nkMutableTy` and is handled separately.
Co-authored-by: Saem Ghani <[email protected]>
Summary
Implement a meta-language for describing languages' abstract syntax and
semantics, using a macro DSL. The source language's textual definition
is replaced with a definition using the new meta-language.
Details
The current formal definition has a few problems:
thus testing/validation
mistakes (both syntactic and semantic)
Using a dedicated meta-language is meant to address the problems listed
above. A macro DSL is used instead of a fully-custom language, which
has the following benefits:
dedicated parser
macro-based code generation possible
The
language
macro only constructs aLanguage
instance, which ismeant to be passed to further processing (e.g., queries, code
generation, rendering, etc.).
The textual definition is replaced with a meta-language equivalent.
Some small adjustments/clarification are made where needed:
l
andch
non-terminals; they need a concrete definitionE-builtin-readFile
rule uses a placeholder definition, asindeterminate values cannot be described with the meta-language at
the moment
Substituting identifiers with values (previously denoted by
e[x/v]
)is now fully defined using the
substitute
meta-function.To-Do
implement a MarkDown (or RST) renderer for languages(postponed)Notes For Reviewers