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 Robot Framework plain text format #2034

Merged
merged 3 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,11 @@
"title": "Roboconf",
"owner": "Golmote"
},
"robot-framework": {
"title": "Robot Framework",
"alias": "robot",
"owner": "RunDevelopment"
},
"ruby": {
"title": "Ruby",
"require": "clike",
Expand Down
104 changes: 104 additions & 0 deletions components/prism-robot-framework.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
(function (Prism) {

var comment = {
pattern: /(^[ \t]*| {2}|\t)#.*/m,
lookbehind: true,
greedy: true
};

var variable = {
pattern: /((?:^|[^\\])(?:\\{2})*)[$@&%]\{(?:[^{}\r\n]|\{[^{}\r\n]*\})*\}/,
lookbehind: true,
inside: {
'punctuation': /^[$@&%]\{|\}$/
}
};

function createSection(name, inside) {
var extendecInside = {};

extendecInside['section-header'] = {
pattern: /^ ?\*{3}.+?\*{3}/,
alias: 'keyword'
};

// copy inside tokens
for (var token in inside) {
extendecInside[token] = inside[token];
}

extendecInside['tag'] = {
pattern: /([\r\n](?: |\t)[ \t]*)\[[-\w]+\]/,
lookbehind: true,
inside: {
'punctuation': /\[|\]/
}
};
extendecInside['variable'] = variable;
extendecInside['comment'] = comment;

return {
pattern: RegExp(/^ ?\*{3}[ \t]*<name>[ \t]*\*{3}(?:.|[\r\n](?!\*{3}))*/.source.replace(/<name>/g, name), 'im'),
Copy link
Member

Choose a reason for hiding this comment

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

Will this work with the gulp task we have in the build that does the .source replace?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Here's the minified version of that line (pulled from components/prism-robot-framework.min.js):

pattern:RegExp("^ ?\\*{3}[ \t]*<name>[ \t]*\\*{3}(?:.|[\r\\n](?!\\*{3}))*".replace(/<name>/g,t),"im")

What made you think it wouldn't work?

Copy link
Member

Choose a reason for hiding this comment

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

I didn't remember how it worked and I was wondering if the dynamic rewrite was an issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't remember how it worked

Barely. I used a regex to find all RegExp literals which end with /.source and replace those with the optimized source value. I say optimized but it's really just a few things like replace \\t with \t to save a few characters. It's technically incorrect as it's not the real source value but it works well for Prism where we never leave the world of regex patterns.

I'm planning to drop this as soon as our minifier supports this. With regard to #1578, I opened an issue at Terser which can minify ES6+ code.

alias: 'section',
inside: extendecInside
};
}


var docTag = {
pattern: /(\[Documentation\](?: |\t)[ \t]*)(?![ \t]|#)(?:.|[ \t]*(?:\r\n?|\n)[ \t]*\.{3}[ \t]*)+/,
lookbehind: true,
alias: 'string'
};

var testNameLike = {
pattern: /([\r\n] ?)(?!#)(?:\S(?:[ \t]\S)*)+/,
lookbehind: true,
alias: 'function',
inside: {
'variable': variable
}
};

var testPropertyLike = {
pattern: /([\r\n](?: |\t)[ \t]*)(?!\[|\.{3}|#)(?:\S(?:[ \t]\S)*)+/,
lookbehind: true,
inside: {
'variable': variable
}
};

Prism.languages['robot-framework'] = {
'settings': createSection('Settings', {
'documentation': {
pattern: /([\r\n] ?Documentation(?: |\t)[ \t]*)(?![ \t]|#)(?:.|[ \t]*(?:\r\n?|\n)[ \t]*\.{3}[ \t]*)+/,
lookbehind: true,
alias: 'string'
},
'property': {
pattern: /([\r\n] ?)(?!\.{3}|#)(?:\S(?:[ \t]\S)*)+/,
lookbehind: true
}
}),
'variables': createSection('Variables'),
'test-cases': createSection('Test Cases', {
'test-name': testNameLike,
'documentation': docTag,
'property': testPropertyLike
}),
'keywords': createSection('Keywords', {
'keyword-name': testNameLike,
'documentation': docTag,
'property': testPropertyLike
}),
'tasks': createSection('Tasks', {
'task-name': testNameLike,
'documentation': docTag,
'property': testPropertyLike
}),
'comment': comment
};

Prism.languages.robot = Prism.languages['robot-framework'];

}(Prism));
1 change: 1 addition & 0 deletions components/prism-robot-framework.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions examples/prism-robot-framework.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<h2>Full example</h2>
<pre><code>*** Settings ***
Documentation Example using the space separated plain text format.
Library OperatingSystem

*** Variables ***
${MESSAGE} Hello, world!

*** Test Cases ***
My Test
[Documentation] Example test
Log ${MESSAGE}
My Keyword /tmp

Another Test
Should Be Equal ${MESSAGE} Hello, world!

*** Keywords ***
My Keyword
[Arguments] ${path}
Directory Should Exist ${path}</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
"objectpascal": "pascal",
"px": "pcaxis",
"py": "python",
"robot": "robot-framework",
"rb": "ruby",
"trig": "turtle",
"ts": "typescript",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
"tsx": "React TSX",
"renpy": "Ren'py",
"rest": "reST (reStructuredText)",
"robot-framework": "Robot Framework",
"robot": "Robot Framework",
"rb": "Ruby",
"sas": "SAS",
"sass": "Sass (Sass)",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions tests/languages/robot-framework/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# comment

*** Keywords *** # comment
Run Program # comment
[Arguments] @{args} # comment
Run Process program.py @{args} # comment

----------------------------------------------------

[
["comment", "# comment"],
["keywords", [
["section-header", "*** Keywords ***"],
["comment", "# comment"],
["keyword-name", [
"Run Program"
]],
["comment", "# comment"],
["tag", [
["punctuation", "["],
"Arguments",
["punctuation", "]"]
]],
["variable", [
["punctuation", "@{"],
"args",
["punctuation", "}"]
]],
["comment", "# comment"],
["property", [
"Run Process"
]],
" program.py ",
["variable", [
["punctuation", "@{"],
"args",
["punctuation", "}"]
]],
["comment", "# comment"]
]]
]

----------------------------------------------------

Checks for comments.
Loading