Skip to content

Commit

Permalink
Update keyword highlighting
Browse files Browse the repository at this point in the history
Ref. eng/recordflux/RecordFlux#1815
  • Loading branch information
andrestt committed Nov 27, 2024
1 parent ee8bcb9 commit a61b4d9
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for SPARK Pro 25.0 (eng/recordflux/RecordFlux#1823)
- Support for GNAT Pro 25.0 (eng/recordflux/RecordFlux#1823)

### Fixed

- Keyword highlighting in GNAT Studio and VS Code (eng/recordflux/RecordFlux#1815)

## [0.25.0] - 2024-11-05

### Added
Expand Down
20 changes: 10 additions & 10 deletions doc/development_guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Make targets for common development tasks are:
- ``install`` Install project in editable mode
- ``doc`` Generate HTML documentation
- ``dist`` Create Python package
- ``vscode`` Build the VS Code extension (which can be then installed via `rflx install vscode`)
- ``vscode`` Build the VS Code extension (which can be then installed via ``rflx install vscode``)
- ``clean`` Remove build directories and generated files
- ``clean_all`` Bring the repository to a completely clean state

Expand Down Expand Up @@ -529,7 +529,7 @@ Default Annotations
^^^^^^^^^^^^^^^^^^^

It is often useful to show a piece of user's code along with a message concerning the code.
The simplest way to do that is by using the default annotation mechanism implemented in the `ErrorEntry` class which can be used to construct messages of all the severity categories defined above.
The simplest way to do that is by using the default annotation mechanism implemented in the ``ErrorEntry`` class which can be used to construct messages of all the severity categories defined above.

For instance, the following error message:

Expand All @@ -547,7 +547,7 @@ is by default automatically augmented by the tool with a default annotation like
4 | session S is
| ^^^^^^^
However, if an explicit `help` annotation has been provided in the message constructor, then having it together with the default annotation leads to a duplicate underline under the highlighted code section:
However, if an explicit ``help`` annotation has been provided in the message constructor, then having it together with the default annotation leads to a duplicate underline under the highlighted code section:

.. code:: console
Expand All @@ -558,7 +558,7 @@ However, if an explicit `help` annotation has been provided in the message const
| ^^^^^^^
| ------- help: use "machine" instead
To avoid this set the `generate_default_annotation` parameter to `False` when constructing an instance of `ErrorEntry` class.
To avoid this set the ``generate_default_annotation`` parameter to ``False`` when constructing an instance of ``ErrorEntry`` class.
This yields a more optimal message like the one below:

.. code:: console
Expand Down Expand Up @@ -630,13 +630,13 @@ General
-------

The primary specification for the RecordFlux language is the `Language Reference <../../doc/language_reference/language_reference.rst>`_ document which formally specifies its syntax and documents also the intended semantics.
The grammar specification in that document is machine-readable and `tools/check_grammar.py` can be used to validate whether the contents of a given `.rflx` file is compatible with that syntax definition.
The grammar specification in that document is machine-readable and ``tools/check_grammar.py`` can be used to validate whether the contents of a given ``.rflx`` file is compatible with that syntax definition.

A parser for the RecordFlux language is implemented in the `rflx` tool using the `Langkit <https://github.com/AdaCore/langkit>`_ framework.
A parser for the RecordFlux language is implemented in the ``rflx`` tool using the `Langkit <https://github.com/AdaCore/langkit>`_ framework.

Syntax highlighting of `.rflx` files has been provided for the following IDEs and editors: VS Code, GNAT Studio, Vim and Neovim.
These can be installed using the `rflx install` command.
A prerequisite for installing the RecordFlux VS Code extension is to build it locally with the command `make vscode`.
Syntax highlighting of ``.rflx`` files has been provided for the following IDEs and editors: VS Code, GNAT Studio, Vim and Neovim.
These can be installed using the ``rflx install`` command.
A prerequisite for installing the RecordFlux VS Code extension is to build it locally with the command ``make vscode``.

Making changes to the syntax
----------------------------
Expand All @@ -660,4 +660,4 @@ Backwards compatibility

When the RecordFlux syntax is changed in a backwards incompatible manner, for instance, a construct is removed or a keyword is changed, then the old construct must still be preserved in the parser and a dedicated syntax check must be implemented.
This is more helpful to the user since generic parsing errors are difficult to interpret.
For instance, you can have a look at how the syntax check for modular type definitions of the form `type T is mod 8` is implemented in `parser.py <../../rflx/specification/parser.py>`_.
For instance, you can have a look at how the syntax check for modular type definitions of the form ``type T is mod 8`` is implemented in `parser.py <../../rflx/specification/parser.py>`_.
77 changes: 67 additions & 10 deletions rflx/ide/gnatstudio/recordflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,89 @@
GPS.parse_xml(XML)

# Highlighting

recordflux_types = [
"Channel",
]

recordflux_attributes = [
"Append",
"Extend",
"First",
"Has_Data",
"Last",
"Present",
"Read",
"Reset",
"Size",
"Valid",
"Valid_Checksum",
"Write",
]

recordflux_attribute_expressions = [
"Head",
"Opaque",
]

recordflux_simple_aspects = [
"Always_Valid",
"Readable",
"Writable",
]

recordflux_value_aspects = [
"Byte_Order",
"Checksum",
"Desc",
"First",
"Size",
]

recordflux_keywords = [
"all",
"and",
"sequence of",
"begin",
"case",
"end",
"exception",
"for",
"function",
"generic",
"goto",
"if",
"in",
"is",
"machine",
"message",
"mod",
"new",
"not",
"null",
"of",
"or",
"package",
"range",
"renames",
"return",
"sequence",
"session",
"some",
"state",
"then",
"transition",
"type",
"unsigned",
"use",
"when",
"where",
"with",
]

recordflux_literals = [
"False",
"High_Order_First",
"Low_Order_First",
"True",
]

Expand All @@ -188,19 +249,15 @@
spec=(
hl.simple(r"--[^\n]*", tag=hl.tag_comment),
type_region,
hl.simple(r"\b'First", tag=tag_aspect),
hl.simple(r"\b'Last", tag=tag_aspect),
hl.simple(r"\b'Length", tag=tag_aspect),
hl.simple(r"\b'Size", tag=tag_aspect),
hl.simple(r"\bFirst\s+=>", tag=tag_aspect),
hl.simple(r"\bLast\s+=>", tag=tag_aspect),
hl.simple(r"\bLength\s+=>", tag=tag_aspect),
hl.simple(r"\bSize\s+=>", tag=tag_aspect),
hl.words(recordflux_types, tag=hl.tag_keyword),
hl.words([rf"\b'{w}" for w in recordflux_attributes], tag=tag_aspect),
hl.words([rf"\b'{w}" for w in recordflux_attribute_expressions], tag=tag_aspect),
hl.words(recordflux_simple_aspects, tag=tag_aspect),
*[hl.simple(rf"\b{w}\s+=>", tag=tag_aspect) for w in recordflux_value_aspects],
hl.words(recordflux_keywords, tag=hl.tag_keyword),
hl.words(recordflux_literals, tag=hl.tag_keyword),
hl.simple(r"16#[_A-Fa-f0-9]+#", tag=hl.tag_number),
hl.simple(r"\b[_0-9]+\b", tag=hl.tag_number),
hl.words(("Always_Valid"), tag=tag_aspect),
string_literal,
),
)
Expand Down
4 changes: 2 additions & 2 deletions rflx/ide/vim/recordflux.vim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ syntax keyword rflxKeyword when
syntax keyword rflxKeyword First
syntax keyword rflxKeyword Size
syntax keyword rflxKeyword Last
syntax match rflxKeyword "'Opaque"
syntax match rflxKeyword "[.]\\{2,\\}"
syntax match rflxKeyword "Always_Valid"
syntax keyword rflxKeyword end
Expand All @@ -30,7 +31,6 @@ syntax keyword rflxKeyword of
syntax keyword rflxKeyword generic
syntax keyword rflxKeyword function
syntax keyword rflxKeyword return
syntax keyword rflxKeyword Channel
syntax keyword rflxKeyword Readable
syntax keyword rflxKeyword Writable
syntax keyword rflxKeyword machine
Expand Down Expand Up @@ -103,8 +103,8 @@ syntax keyword rflxBoolean False
hi link rflxBoolean Boolean

" Builtin types
syntax keyword rflxType Channel
syntax keyword rflxType Opaque
syntax keyword rflxType Boolean
hi link rflxType Type

" Match number literal such as `1` or in an explicit base `#16#FF#`
Expand Down
6 changes: 3 additions & 3 deletions rflx/ide/vscode/syntax/recordflux.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"operators": {
"name": "entity.name.operator.recordflux",
"match": "=>|=|\\*|\\+|\\-|/=|\\.\\.|<|<=|>|>=|:=|\\b(or|and|range|sequence|unsigned|'First|'Size|'Last|'Valid_Checksum|'Valid|'Write|'Read)\\b"
"match": "=>|=|\\*|\\+|\\-|/=|\\.\\.|<|<=|>|>=|:=|\\b(and|mod|or|range|sequence|unsigned|'Append|'Extend|'First|'Has_Data|'Head|'Last|'Opaque|'Present|'Read|'Reset|'Size|'Valid|'Valid_Checksum|'Write)\\b"
},
"strings": {
"name": "string.quoted.double.recordflux",
Expand All @@ -62,15 +62,15 @@
},
{
"name": "variable.language.recordflux",
"match": "\\b(Size|Byte_Order|Checksum)\\b"
"match": "\\b(Byte_Order|Checksum|Desc|First|Size)\\b"
}
]
},
"types": {
"patterns": [
{
"name": "entity.name.type.recordflux",
"match": "\\b(Opaque|Channel)"
"match": "\\b(Channel|Opaque)\\b"
}
]
}
Expand Down
5 changes: 4 additions & 1 deletion tools/rflxlexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
MAPPINGS = {
pygments.token.Keyword: [
"All",
"Always_Valid",
"Append",
"Begin",
"Byte_Order",
Expand All @@ -22,6 +23,7 @@
"End",
"Exception",
"Extend",
"False",
"First",
"For",
"Function",
Expand All @@ -36,6 +38,7 @@
"Low_Order_First",
"Machine",
"Message",
"Mod",
"New",
"Null",
"Of",
Expand All @@ -54,13 +57,13 @@
"State",
"Then",
"Transition",
"True",
"Type",
"Unsigned",
"Use",
"Valid",
"Valid_Checksum",
"When",
"Where",
"With",
"Writable",
"Write",
Expand Down

0 comments on commit a61b4d9

Please sign in to comment.