Skip to content

Commit

Permalink
Parse rflx output into location view
Browse files Browse the repository at this point in the history
Ref. #243
  • Loading branch information
Alexander Senier committed Jun 13, 2020
1 parent 172b170 commit 3729150
Showing 1 changed file with 121 additions and 27 deletions.
148 changes: 121 additions & 27 deletions ide/gnatstudio/recordflux.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""RecordFlux support for GNAT Studio
"""
RecordFlux support for GNAT Studio
"""

import os.path
import re


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 @@ -37,39 +38,49 @@
</Language>
<!-- Filter -->
<filter name="is_recordflux" language="RecordFlux"/>
<filter name="RecordFlux" language="RecordFlux"/>
<!-- Actions -->
<action name="check">
<filter id="is_recordflux"/>
<filter id="Source editor"/>
<filter_and>
<filter id="RecordFlux"/>
<filter id="Source editor"/>
</filter_and>
<external>rflx check %F</external>
<on-failure>
<shell lang="python" show-command="false">recordflux.parse_output(&quot;&quot;&quot;%1&quot;&quot;&quot;)</shell>
</on-failure>
</action>
<action name="check_all">
<filter id="is_recordflux"/>
<shell lang="python" show-command="false">
" ".join([s.name()
for s in GPS.current_context().project().sources()
if s.language() == "recordflux"])
</shell>
<filter id="File"/>
<shell lang="python" show-command="false">recordflux.get_source_files()</shell>
<external>rflx check %1"</external>
<on-failure>
<shell lang="python" show-command="false">recordflux.parse_output(&quot;&quot;&quot;%1&quot;&quot;&quot;)</shell>
</on-failure>
</action>
<action name="generate">
<filter id="is_recordflux"/>
<filter id="Source editor"/>
<external>rflx generate -d %o %F</external>
<filter_and>
<filter id="RecordFlux"/>
<filter id="Source editor"/>
</filter_and>
<external>rflx generate -d generated %F</external>
<on-failure>
<shell lang="python" show-command="false">recordflux.parse_output(&quot;&quot;&quot;%1&quot;&quot;&quot;)</shell>
</on-failure>
</action>
<action name="generate_all">
<filter id="is_recordflux"/>
<shell lang="python" show-command="false">
" ".join([s.name()
for s in GPS.current_context().project().sources()
if s.language() == "recordflux"])
</shell>
<external>rflx generate -d %o %1"</external>
<filter_and>
<filter id="File"/>
</filter_and>
<shell lang="python" show-command="false">recordflux.get_source_files()</shell>
<external>rflx generate -d generated %1"</external>
<on-failure>
<shell lang="python" show-command="false">recordflux.parse_output(&quot;&quot;&quot;%1&quot;&quot;&quot;)</shell>
</on-failure>
</action>
<!-- Aliases -->
Expand Down Expand Up @@ -157,15 +168,98 @@
hl.simple(r"\b[_0-9]+\b", tag=hl.tag_number),
hl.words(("Always_Valid"), tag=tag_aspect),
string_literal,
)
),
)

# Templates
@hook('gps_started')

@hook("gps_started")
def __on_gps_started():
GPS.FileTemplate.register(
alias_name="rflx_package",
label="RecordFlux specification",
unit_param="name",
language="RecordFlux",
is_impl=False)
is_impl=False,
)


message_re = re.compile(
r"^"
r"(?P<filename>[^:]+):"
r"(?P<line>\d+):"
r"(?P<column>\d+): "
r"(?P<subsystem>core|parser|model|cli|internal|graph): "
r"(?P<severity>info|warning|error): "
r"(?P<message>.*)"
r"$"
)

generic_message_re = re.compile(
r"^"
r"(?P<subsystem>core|parser|model|cli|internal|graph): "
r"(?P<severity>info|warning|error): "
r"(?P<message>.*)"
r"$"
)


def to_importance(severity):
if severity == "error":
return GPS.Message.Importance.HIGH
if severity == "warning":
return GPS.Message.Importance.MEDIUM
if severity == "info":
return GPS.Message.Importance.INFORMATIONAL


def parse_output(output):
for m in GPS.Message.list():
m.remove()
message = None
for l in output.splitlines():
result = message_re.match(l)
if result:
data = result.groupdict()
if data["severity"] != "info":
message = GPS.Message(
category="RecordFlux",
file=GPS.File(data["filename"]),
line=int(data["line"]),
column=int(data["column"]),
text="{subsystem}: {severity}: {message}".format(**data),
importance=to_importance(data["severity"]),
)
elif message:
data["relative"] = os.path.basename(data["filename"])
message.create_nested_message(
file=GPS.File(data["filename"]),
line=int(data["line"]),
column=int(data["column"]),
text="{message} ({relative}:{line}:{column})".format(**data),
)
continue

result = generic_message_re.match(l)
if result:
data = result.groupdict()
message = GPS.Message(
category="RecordFlux",
file=GPS.File(data["subsystem"]),
line=1,
column=1,
text="{subsystem}: {severity}: {message}".format(**data),
importance=to_importance(data["severity"]),
)


def get_source_files():
files = (
GPS.current_context().project().sources()
if GPS.current_context().project()
else GPS.current_context().files()
)

if files:
return " ".join([s.name() for s in files if s.language() == "recordflux"])

raise GPS.Exception("No files found")

0 comments on commit 3729150

Please sign in to comment.