Repository navigation
Add pragmas, and a schema comment they can set - #19
Merged
Merged
Conversation
A pragma is a single line comment --@ key = value, or --@ key, on a line of its own before a module, an assignment, a member or a field of an object class. It is for what a plugin needs to be told that the ASN.1 has no way to say, as what a type is to an RPC framework built on asnkit. The comment scanner gives the comments that begin with --@, and once the tree is parsed each is given to what has the location of the first character after it, as the next item with nothing but whitespace and comments between. A pragma after something on its line, before what has no location (END, an extension marker, an item of an ENUMERATED), a key that is not a letter followed by letters, digits, '.', '-' and '_', and a key given twice to the same item are parse errors that tell where. The syntax tree has them as pragmas, a list of [key, value] pairs in the order they are written, last in the fields of Module, TypeAssignment, ValueAssignment, ObjectAssignment, ObjectClassAssignment, ObjectClassField, ObjectSetAssignment and Member, and left out when there are none. It is a list of pairs and not a map, as a map in the readable form is a node. A compiled specification has none, so .asni files are as they were, and .asnst files are of version 1.1. asnkitrt.syntax reads them as a tuple of pairs. The tables of kinds of the compiler and of the runtimes for Rust, the JVM and Python have the field. The .asnst fixtures and examples are made again for the version. Signed-off-by: Matheus Xavier <mxavier@boxtheta.com>
A schema of asnkitcc schema began with what it is of and what made it, as "The JSON Encoding Rules (X.697) of the types of foo.asn, as asnkit writes them. Made by asnkitcc 2.0.0-rc7.". It is now "schema generated by asnkit from foo.asn", with the names of the ASN.1 files, or "schema generated by asnkit" when they are not known, in the $comment of a JSON Schema and the first comment of an XML Schema and a DTD. The pragma schema_comment of a module, --@ schema_comment = Greeter v1, is the comment instead, of the schemas of its types: those of the modules of the types of a schema are a line each. An .asni file has no pragmas, so asnkitcc schema reads them from the ASN.1 files it is given, with schema::comments_of(), which schema::Request takes as comments rather than generator. schema() of the compiler as WebAssembly takes the ASN.1 text as the option specification, which the playground gives it. A comment of XML had "--" replaced once, which left "--" of "---"; it is now replaced until there is none, as the name of a file can have it. Signed-off-by: Matheus Xavier <mxavier@boxtheta.com>
xadaemon
force-pushed
the
compiler-pragmas
branch
from
November 8, 2026 01:57
cb8cb66 to
def0cfe
Compare
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.
Adds pragmas to the compiler: comments in the ASN.1 that reach plugins as key/value pairs in the
.asnst. They are the way to pass information into plugins for the RPC work planned on top of asnkit. The first key asnkit reads itself isschema_comment, for the comment the schema generators write.Pragmas (
faf6599)--@ key = value, or--@ keywith the value"", on a line of its own. A key is a letter followed by letters, digits,.,-and_. A plain-- @, or a--@inside/* */, is still an ordinary comment.[[ ]], in nested types and inSEQUENCE OFelements) or an object class field.END,...or an enum item;.asnst: the eight node kinds above get a new last field,pragmas: a list of[key, value]pairs in source order, left out when there are none. It is a list of pairs rather than a map because a map in the readable form is a node.asnkitrt.syntaxreads it as a tuple of pairs, sodict(node.pragmas or ())works..asnifiles never contain pragmas, and every.asnifixture is byte-identical..asnstgoes to version 1.1, which 1.0 readers still load. The kinds tables in the compiler and in the Rust, JVM and Python runtimes have the new field. The.asnstfixtures and examples were regenerated for the version.Schema comment (
def0cfe)schema generated by asnkit from foo.asn, orschema generated by asnkitwhen the file names aren't known. This is the$commentof a JSON Schema and the first comment of an XML Schema or DTD. It replaces the old sentence, which named the encoding rules and the compiler version.--@ schema_comment = ...before a module: replaces the default for schemas of that module's types. When several of those modules have one, each distinct value is one line..asnihas no pragmas, soasnkitcc schemareads them from the.asninputs. An.asniinput gets the default comment.schema()takes a new option,specification, the ASN.1 text that was compiled. The playground passes it.asnkitcclibrary,schema::Requesttakescomments(fromschema::comments_of()) instead ofgenerator.--is left. Before, it left--in a name likea---b.asn.Testing
cargo test --workspace,cargo clippy --workspace --all-targetsandcargo fmt --checkpass. New tests:packages/asnkit-compiler/tests/pragmas.rsand a schema-comment test inpackages/asnkitcc/tests/schema.rs.uv run python -m unittestpasses, withASNKIT_RUST_BINARYset (547 tests), including the newtest_pragmas.tests.test_schemaalso passes.npm run build && npm testinpackages/asnkit-compiler-wasmpasses (14 tests, one of them new).RELEASING.mddescribes.mkdocs build --strictpasses.KindsTest, because Java isn't installed on the machine this was made on. It's a one-line table change per kind.