Skip to content
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

Added The Device Modeling Language (DML) #7009

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@
[submodule "vendor/grammars/desktop.tmbundle"]
path = vendor/grammars/desktop.tmbundle
url = https://github.com/Mailaender/desktop.tmbundle.git
[submodule "vendor/grammars/device-modeling-language"]
path = vendor/grammars/device-modeling-language
url = https://github.com/intel/device-modeling-language.git
[submodule "vendor/grammars/diff.tmbundle"]
path = vendor/grammars/diff.tmbundle
url = https://github.com/textmate/diff.tmbundle
Expand Down
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ vendor/grammars/denizenscript-grammar:
- source.denizenscript
vendor/grammars/desktop.tmbundle:
- source.desktop
vendor/grammars/device-modeling-language:
- source.dml
vendor/grammars/diff.tmbundle:
- source.diff
vendor/grammars/dm-syntax:
Expand Down
4 changes: 4 additions & 0 deletions lib/linguist/heuristics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ disambiguations:
# : dependency
# path/file.ext1 : some/path/../file.ext2
pattern: '([\/\\].*:\s+.*\s\\$|: \\$|^[ %]:|^[\w\s\/\\.]+\w+\.\w+\s*:\s+[\w\s\/\\.]+\w+\.\w+)'
- extensions: ['.dml']
rules:
- language: Device Modeling Language
pattern: '(^dml\s1.4;)'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have no effect as Linguist doesn't know of any other language that uses the .dml extension. See my primary comment for more details.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was under the impression that if this regex didn't match, and given that there are no other languages in linguist that has a .dml extension, the language of the file would simply not be recognized.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. Linguist works like a funnel... everything goes in at the top and then works through each of the strategies in decreasing order of specificity until a single language is identified:

linguist/lib/linguist.rb

Lines 51 to 71 in 5fad8d5

# Internal: The strategies used to detect the language of a file.
#
# A strategy is an object that has a `.call` method that takes two arguments:
#
# blob - An object that quacks like a blob.
# languages - An Array of candidate Language objects that were returned by the
# previous strategy.
#
# A strategy should return an Array of Language candidates.
#
# Strategies are called in turn until a single Language is returned.
STRATEGIES = [
Linguist::Strategy::Modeline,
Linguist::Strategy::Filename,
Linguist::Shebang,
Linguist::Strategy::Extension,
Linguist::Strategy::XML,
Linguist::Strategy::Manpage,
Linguist::Heuristics,
Linguist::Classifier
]

As Linguist would only know of the .dml extension with this language, it would stop the process there which as as you can see is before the heuristics strategy. It would also however apply this to all .dml files found on GitHub.

There is an exception to this: very generic extensions which we add to the generic.yml file. These are checked against the heuristics really early in the extension strategy.

Thinking about this further, I think .dml is a good candidate to add to generic.yml too which would then mean this heuristic is used and will leave the other languages unaffected.

Please can you add this extension to the generic.yml file. This heuristic can also be improved (we don't need the capturing group and the tiny overhead it brings with it):

Suggested change
pattern: '(^dml\s1.4;)'
pattern: '^dml\s1.4;'

- extensions: ['.dsp']
rules:
- language: Microsoft Developer Studio Project
Expand Down
10 changes: 10 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,16 @@ DirectX 3D File:
ace_mode: text
tm_scope: none
language_id: 201049282
Device Modeling Language:
type: programming
aliases:
- DML
extensions:
- ".dml"
ace_mode: text
color: "#0068B5"
tm_scope: source.dml
language_id: 806438883
TSonono marked this conversation as resolved.
Show resolved Hide resolved
Dockerfile:
type: programming
aliases:
Expand Down
73 changes: 73 additions & 0 deletions samples/Device Modeling Language/sample-device.dml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
dml 1.4;

device sample_device;

param desc = "A sample DML device";

param documentation = "This is a sample DML device intended as a sample for"
+ " the Linguist project";

import "sample-interface.dml";

attribute n_regs_written is (pseudo_attr, uint64_attr) "" {
method get() -> (attr_value_t) {
local uint8 n_written_regs = 0;
foreach reg in (each register_written in (regs)) {
if (reg.has_been_written())
n_written_regs += 1;
}
return SIM_make_attr_uint64(n_written_regs);
}

method set(attr_value_t val) throws {
if (SIM_attr_integer(val) != 0) {
log error: "n_regs_written can be only set to 0 to reset written"
+ " status on all registers in the 'regs' bank";
throw;
}

foreach reg in (each register_written in (regs)) {
reg.reset_written();
}
}
}

implement sample {
saved int arg_sum = 0;
method simple_method(int arg) {
arg_sum += arg;
}
}

template register_written is (register, write) {
saved bool written;

method write(uint64 value) default {
this.written = true;
default(value);
}

shared method has_been_written() -> (bool) {
return this.written;
}

shared method reset_written() {
this.written = false;
}
}

bank regs {
param desc = dev.desc + "custom desc";
register r1 size 4 @ 0x0000 is (read, register_written) {
method read() -> (uint64) {
log info, 3: "read from r1";
return 42 + sample.arg_sum;
}
}
register r2 size 4 @ 0x0004 is (write, register_written) {
method write(uint64 value) {
log info, 3: "wrote %d to r2", value;
default(value);
}
}
}
11 changes: 11 additions & 0 deletions samples/Device Modeling Language/sample-interface.dml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dml 1.4;

header %{
typedef struct {
void (*simple_method)(conf_object_t *obj, int arg);
} sample_interface_t;
%}

extern typedef struct {
void (*simple_method)(conf_object_t *obj, int arg);
} sample_interface_t;
1 change: 1 addition & 0 deletions vendor/grammars/device-modeling-language
210 changes: 210 additions & 0 deletions vendor/licenses/git_submodule/device-modeling-language.dep.yml

Large diffs are not rendered by default.