-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add support for PSL, PATROL Scripting Language (#2735) #2739
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
Merged
RunDevelopment
merged 4 commits into
PrismJS:master
from
sentrysoftware:feature/issue-2735-psl
Jan 27, 2021
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
05beca7
Add support for PSL, PATROL Scripting Language (#2735)
bertysentry 2321fd5
Improvements after code review, notably:
bertysentry 4d98ba7
Use `builtin` for PSL built-in functions and `function` for user-defi…
bertysentry fb1ef57
Changed "PSL" for "PATROL Scripting Language"
bertysentry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| Prism.languages.psl = { | ||
| 'comment': [ | ||
| { | ||
| pattern: /#.*/, | ||
| greedy: true | ||
| } | ||
| ], | ||
bertysentry marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 'string': [{ | ||
bertysentry marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pattern: /"(?:\\"|[^"\r\n]|[\r\n])*"/, | ||
bertysentry marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| greedy: true, | ||
| inside: { | ||
| 'symbol': /\\[ntrbA-Z"\\]/ | ||
| } | ||
| }, | ||
| { | ||
| pattern: /<<<([a-zA-Z_]\w*)[\r\n](?:.*[\r\n])*?\1\b/, | ||
| alias: 'heredoc-string', | ||
| greedy: true | ||
| }], | ||
|
|
||
| 'keyword': /\b(?:export|function|local|exit|last|next|requires|return|until|case|default|do|elsif|else|for|foreach|if|switch|while|line|word|__single|__multi)\b/, | ||
bertysentry marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 'constant': /\b(?:ALARM|CHART_ADD_GRAPH|CHART_DELETE_GRAPH|CHART_DESTROY|CHART_LOAD|CHART_PRINT|EOF|FALSE|False|false|NO|No|no|OK|OFFLINE|PSL_PROF_LOG|R_CHECK_HORIZ|R_CHECK_VERT|R_CLICKER|R_COLUMN|R_FRAME|R_ICON|R_LABEL|R_LABEL_CENTER|R_LIST_MULTIPLE|R_LIST_MULTIPLE_ND|R_LIST_SINGLE|R_LIST_SINGLE_ND|R_MENU|R_POPUP|R_POPUP_SCROLLED|R_RADIO_HORIZ|R_RADIO_VERT|R_ROW|R_SCALE_HORIZ|R_SCALE_VERT|R_SPINNER|R_TEXT_FIELD|R_TEXT_FIELD_LABEL|R_TOGGLE|TRUE|True|true|TRIM_LEADING|TRIM_TRAILING|TRIM_REDUNDANT|TRIM_LEADING_AND_TRAILING|VOID|WARN)\b/, | ||
| 'variable': /\b(?:errno|exit_status|PslDebug)\b/, | ||
| 'function': /\b(?:acos|add_diary|annotate|annotate_get|asctime|asin|atan|atexit|ascii_to_ebcdic|batch_set|blackout|cat|ceil|chan_exists|change_state|close|code_cvt|cond_signal|cond_wait|console_type|convert_base|convert_date|convert_locale_date|cos|cosh|create|destroy_lock|dump_hist|date|destroy|difference|dget_text|dcget_text|ebcdic_to_ascii|encrypt|event_archive|event_catalog_get|event_check|event_query|event_range_manage|event_range_query|event_report|event_schedule|event_trigger|event_trigger2|execute|exists|exp|fabs|floor|fmod|full_discovery|file|fopen|ftell|fseek|grep|get_vars|getenv|get|get_chan_info|get_ranges|get_text|gethostinfo|getpid|getpname|history_get_retention|history|index|int|is_var|intersection|isnumber|internal|in_transition|join|kill|length|lines|lock|lock_info|log|loge|log10|matchline|msg_check|msg_get_format|msg_get_severity|msg_printf|msg_sprintf|ntharg|num_consoles|nthargf|nthline|nthlinef|num_bytes|print|proc_exists|process|popen|printf|pconfig|poplines|pow|PslExecute|PslFunctionCall|PslFunctionExists|PslSetOptions|random|read|readln|refresh_parameters|remote_check|remote_close|remote_event_query|remote_event_trigger|remote_file_send|remote_open|remove|replace|rindex|sec_check_priv|sec_store_get|sec_store_set|set_alarm_ranges|set_locale|share|sin|sinh|sleep|sopen|sqrt|srandom|subset|set|substr|system|sprintf|sort|subset|snmp_agent_config|_snmp_debug|snmp_agent_stop|snmp_agent_start|snmp_h_set|snmp_h_get_next|snmp_h_get|snmp_set|snmp_walk|snmp_get_next|snmp_get|snmp_config|snmp_close|snmp_open|snmp_trap_receive|snmp_trap_ignore|snmp_trap_listen|snmp_trap_send|snmp_trap_raise_std_trap|snmp_trap_register_im|splitline|strcasecmp|str_repeat|trim|tail|tan|tanh|time|tmpnam|tolower|toupper|trace_psl_process|text_domain|unlock|unique|union|unset|va_arg|va_start|write)\b/, | ||
RunDevelopment marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 'number': /\b(?:(?:0[xX][0-9a-fA-F]*)|(?:[0-9]+\.[0-9]+)|[0-9]+)\b/, | ||
bertysentry marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 'operator': /[+\-~=\/*%&><\^!|\.]/, | ||
bertysentry marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 'punctuation': /[\(\){}\[\]:;,?]/ | ||
bertysentry marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <h2>Strings</h2> | ||
| <pre><code># PSL Strings are properly rendered | ||
| print("Hello, World!"); | ||
|
|
||
| # Escaped sequences are highlighted too | ||
| print("Goodbye \H\H\H\H\H\H\H\HHello, World!\n"); | ||
|
|
||
| # Multi-line strings are supported | ||
| print("multi | ||
| line"); | ||
| </code></pre> | ||
|
|
||
| <h2>Numbers</h2> | ||
| <pre><code>a = 1; | ||
| b = 2.5; | ||
| c = 0xff; | ||
| </code></pre> | ||
|
|
||
| <h2>PSL Built-in Functions</h2> | ||
| <pre><code>p = nthargf(process(".*"), 1, " \t", "\n"); | ||
| lock("test"); | ||
| execute("OS", "pwd"); | ||
| </code></pre> | ||
|
|
||
| <h2>PSL Keywords</h2> | ||
| <pre><code>foreach entry (["aaa", "bbb", "ccc"]) { | ||
| if (grep("[bc]", entry)) { | ||
| last; | ||
| } | ||
| } | ||
| </code></pre> | ||
|
|
||
| <h2>PSL Constants</h2> | ||
| <pre><code>set("/CLASS/inst/paramA/state", WARN); | ||
| if (true) { | ||
| PslDebug = -1; | ||
| } | ||
| output = execute("OS", "echo test"); | ||
| if (errno) { | ||
| print(ALARM." with errno=".errno."\n"); | ||
| } | ||
| print(trim(output, "\n\r\t ", TRIM_LEADING_AND_TRAILING)); | ||
| </code></pre> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Comment | ||
| # This is not a "string" | ||
| # This is not a <<<HERE_DOC document HERE_DOC | ||
| ### Comment | ||
| "string # with hash"#comment | ||
| # Indented comment | ||
| # Tab-indented comment | ||
|
|
||
| ---------------------------------------------------- | ||
|
|
||
| [ | ||
| ["comment", "# Comment"], | ||
| ["comment", "# This is not a \"string\""], | ||
| ["comment", "# This is not a <<<HERE_DOC document HERE_DOC"], | ||
| ["comment", "### Comment"], | ||
| ["string", ["\"string # with hash\""]], ["comment", "#comment"], | ||
| ["comment", "# Indented comment"], | ||
| ["comment", "# Tab-indented comment"] | ||
| ] | ||
|
|
||
| ---------------------------------------------------- | ||
|
|
||
| Test for comments |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <<<ABC_1 | ||
| Text "string" | ||
| # comment "string" | ||
bertysentry marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ABC_1; | ||
|
|
||
| <<<ABC_2 | ||
| 2nd here_doc \n\t | ||
| ABC_2; | ||
|
|
||
| ---------------------------------------------------- | ||
|
|
||
| [ | ||
| ["string", "<<<ABC_1\r\nText \"string\"\r\n# comment \"string\"\r\nABC_1"], | ||
| ["punctuation", ";"], | ||
|
|
||
| ["string", "<<<ABC_2\r\n2nd here_doc \\n\\t\r\nABC_2"], ["punctuation", ";"] | ||
| ] | ||
|
|
||
| ---------------------------------------------------- | ||
|
|
||
| Test for "here_documents" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| 1 | ||
| 1.3 | ||
| 1.0 | ||
| 01.2 | ||
| 0xF0 | ||
| 0xbcde0 | ||
| 0XA390 | ||
|
|
||
| ---------------------------------------------------- | ||
|
|
||
| [ | ||
| ["number", "1"], | ||
| ["number", "1.3"], | ||
| ["number", "1.0"], | ||
| ["number", "01.2"], | ||
| ["number", "0xF0"], | ||
| ["number", "0xbcde0"], | ||
| ["number", "0XA390"] | ||
| ] | ||
|
|
||
| ---------------------------------------------------- | ||
|
|
||
| Test for numbers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| function test(limit) { | ||
| for (i = 0 ; i < limit ; i++) { | ||
| s = s + i; # s has not been initialized! | ||
| } | ||
| print(s."\n"); | ||
| } | ||
|
|
||
| ---------------------------------------------------- | ||
|
|
||
| [ | ||
| ["keyword", "function"], | ||
| " test", | ||
| ["punctuation", "("], | ||
| "limit", | ||
| ["punctuation", ")"], | ||
| ["punctuation", "{"], | ||
|
|
||
| ["keyword", "for"], | ||
| ["punctuation", "("], | ||
| "i ", | ||
| ["operator", "="], | ||
| ["number", "0"], | ||
| ["punctuation", ";"], | ||
| " i ", | ||
| ["operator", "<"], | ||
| " limit ", | ||
| ["punctuation", ";"], | ||
| " i", | ||
| ["operator", "+"], | ||
| ["operator", "+"], | ||
| ["punctuation", ")"], | ||
| ["punctuation", "{"], | ||
|
|
||
| "\r\n\t\ts ", | ||
| ["operator", "="], | ||
| " s ", | ||
| ["operator", "+"], | ||
| " i", | ||
| ["punctuation", ";"], | ||
| ["comment", "# s has not been initialized!"], | ||
|
|
||
| ["punctuation", "}"], | ||
|
|
||
| ["function", "print"], | ||
| ["punctuation", "("], | ||
| "s", | ||
| ["operator", "."], | ||
| ["string", [ | ||
| "\"", | ||
| ["symbol", "\\n"], | ||
| "\"" | ||
| ]], | ||
| ["punctuation", ")"], | ||
| ["punctuation", ";"], | ||
|
|
||
| ["punctuation", "}"] | ||
| ] | ||
|
|
||
| ---------------------------------------------------- | ||
|
|
||
| General test for the most common PSL statements, all mixed together |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| "abc" | ||
| "a \"bc\"" | ||
| "a\nbc" | ||
| "a\invalid" | ||
| "a # comment" | ||
bertysentry marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "multi | ||
| line string" | ||
|
|
||
| ---------------------------------------------------- | ||
|
|
||
| [ | ||
| ["string", ["\"abc\""]], | ||
| ["string", [ | ||
| "\"a ", | ||
| ["symbol", "\\\""], | ||
| "bc", | ||
| ["symbol", "\\\""], | ||
| "\"" | ||
| ]], | ||
| ["string", [ | ||
| "\"a", | ||
| ["symbol", "\\n"], | ||
| "bc\"" | ||
| ]], | ||
| ["string", ["\"a\\invalid\""]], | ||
| ["string", ["\"a # comment\""]], | ||
| ["string", ["\"multi\r\nline string\""]] | ||
| ] | ||
|
|
||
| ---------------------------------------------------- | ||
|
|
||
| Test for strings | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.