Skip to content

Commit

Permalink
Implement GNAT Studio syntax highlighting
Browse files Browse the repository at this point in the history
Ref. #243
  • Loading branch information
Alexander Senier committed Jun 13, 2020
1 parent 0783eb8 commit 911f264
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions ide/gnatstudio/recordflux.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import GPS
import gs_utils.gnat_rules
import highlighter.common as hl

from gs_utils import hook

XML = r"""<?xml version="1.0"?>
Expand Down Expand Up @@ -40,6 +42,7 @@
<!-- Actions -->
<action name="check">
<filter id="is_recordflux"/>
<filter id="Source editor"/>
<external>rflx check %F</external>
</action>
Expand All @@ -55,6 +58,7 @@
<action name="generate">
<filter id="is_recordflux"/>
<filter id="Source editor"/>
<external>rflx generate -d %o %F</external>
</action>
Expand Down Expand Up @@ -103,6 +107,60 @@

GPS.parse_xml(XML)

# Highlighting
recordflux_keywords = [
"and",
"array of",
"end",
"for",
"if",
"is",
"message",
"mod",
"new",
"null",
"or",
"package",
"range",
"then",
"type",
"use",
"with",
]

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

tag_aspect = hl.existing_style("Src-Editor-Aspects-Variant", "aspects")

hl_type = hl.simple(r"\b[^;\s]+", tag=hl.tag_type)
type_region = hl.region(r":", r"\b", highlighter=(hl_type,), tag=hl.tag_default)
string_literal = hl.region(r'"', r'"', matchall=False, tag=hl.tag_string)

hl.register_highlighter(
language="recordflux",
spec=(
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_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,
)
)

# Templates
@hook('gps_started')
def __on_gps_started():
GPS.FileTemplate.register(
Expand Down

0 comments on commit 911f264

Please sign in to comment.