From 7f1a45fc4bb45a1464e6cd33a5ac9f9fc286cc1f Mon Sep 17 00:00:00 2001 From: Defman21 Date: Fri, 5 Jan 2018 22:51:40 +0300 Subject: [PATCH 1/3] Rust: syntax highlighting Signed-off-by: Defman21 --- src/python-sitelib/langinfo_prog.py | 4 + src/udl/Conscript | 6 ++ src/udl/GUIDs.txt | 3 +- .../Rust/components/koRust_UDL_Language.py | 69 +++++++++++++ src/udl/udl/rust-mainlex.udl | 98 +++++++++++++++++++ 5 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 src/udl/skel/Rust/components/koRust_UDL_Language.py create mode 100644 src/udl/udl/rust-mainlex.udl diff --git a/src/python-sitelib/langinfo_prog.py b/src/python-sitelib/langinfo_prog.py index 6e72b614b8..73aee76546 100644 --- a/src/python-sitelib/langinfo_prog.py +++ b/src/python-sitelib/langinfo_prog.py @@ -728,3 +728,7 @@ class SwiftScriptLangInfo(LangInfo): name = "Swift" exts = ['.swift'] +class RustLangInfo(LangInfo): + """https://rust-lang.org""" + name = "Rust" + exts = ['.rs'] \ No newline at end of file diff --git a/src/udl/Conscript b/src/udl/Conscript index 0efe1d3f97..a03f1c2093 100644 --- a/src/udl/Conscript +++ b/src/udl/Conscript @@ -266,6 +266,12 @@ my @lexers = ( codename => "haml_language", udl_path => "haml-mainlex.udl", skel => "skel/Haml", + }, + { + language_name => "Rust", + codename => "rust_language", + udl_path => "rust-mainlex.udl", + skel => "skel/Rust", } ); foreach my $info (@lexers) { diff --git a/src/udl/GUIDs.txt b/src/udl/GUIDs.txt index f6d33fcbf1..d645d7c774 100644 --- a/src/udl/GUIDs.txt +++ b/src/udl/GUIDs.txt @@ -17,4 +17,5 @@ ActionScript 4dd22f3a-52e2-426d-8a21-6f7ea2ba91ac reStructuredText d98cc808-2981-4aa0-841b-e5e920d83177 TracWiki b843faa8-aeea-4fcb-aeb9-36c4483c6f95 Docker 54072a7f-a845-4b78-b63f-fc47c583e0b8 -R ec4a2833-5994-4c94-9be5-db6a8952029f \ No newline at end of file +R ec4a2833-5994-4c94-9be5-db6a8952029f +Rust FABBE082-7E14-41C3-92EA-90F5CB95519C \ No newline at end of file diff --git a/src/udl/skel/Rust/components/koRust_UDL_Language.py b/src/udl/skel/Rust/components/koRust_UDL_Language.py new file mode 100644 index 0000000000..4cd034ed89 --- /dev/null +++ b/src/udl/skel/Rust/components/koRust_UDL_Language.py @@ -0,0 +1,69 @@ +#!python +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.1 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# The Original Code is Komodo code. +# +# The Initial Developer of the Original Code is ActiveState Software Inc. +# Portions created by ActiveState Software Inc are Copyright (C) 2000-2007 +# ActiveState Software Inc. All Rights Reserved. +# +# Contributor(s): +# ActiveState Software Inc +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +"""Language package for Rust""" + +import logging +from koUDLLanguageBase import KoUDLLanguage + +log = logging.getLogger("koRustLanguage") +log.setLevel(logging.DEBUG) + +def registerLanguage(registry): + log.debug("Registering language Rust") + registry.registerLanguage(KoRustLanguage()) + +class KoRustLanguage(KoUDLLanguage): + name = "Rust" + _reg_desc_ = "%s Language" % name + _reg_contractid_ = "@activestate.com/koLanguage?language=%s;1" \ + % (name) + _reg_clsid_ = "{FABBE082-7E14-41C3-92EA-90F5CB95519C}" + _reg_categories_ = [("komodo-language", name)] + + lexresLangName = "Rust" + lang_from_udl_family = {'SSL': 'Rust'} + + accessKey = 'r' + primary = 1 + defaultExtension = ".rs" + downloadURL = 'http://rust-lang.org/' + commentDelimiterInfo = { + "line": [ "//" ], + "block": [ ("/*", "*/") ], + } + supportsSmartIndent = "brace" \ No newline at end of file diff --git a/src/udl/udl/rust-mainlex.udl b/src/udl/udl/rust-mainlex.udl new file mode 100644 index 0000000000..8805f4a033 --- /dev/null +++ b/src/udl/udl/rust-mainlex.udl @@ -0,0 +1,98 @@ +language Rust + +family markup +initial IN_M_DEFAULT +# Null-transition to get into SSL state +state IN_M_DEFAULT: +/./ : redo, => IN_SSL_DEFAULT + + +family ssl +start_style SSL_DEFAULT +end_style SSL_VARIABLE + +keyword_style SSL_IDENTIFIER => SSL_WORD + +keywords [ + '_', 'abstract', 'alignof', 'as', 'become', 'box', 'break', 'const', + 'continue', 'crate', 'do', 'else', 'enum', 'extern', 'false', 'final', + 'fn', 'for', 'if', 'impl', 'in', 'let', 'loop', 'macro', + 'match', 'mod', 'move', 'mut', 'offsetof', 'override', 'priv', 'proc', + 'pub', 'pure', 'ref', 'return', 'Self', 'self', 'sizeof', + 'static', 'struct', 'super', 'trait', 'true', 'type', 'typeof', + 'unsafe', 'unsized', 'use', 'virtual', 'where', 'while', 'yield' +] + +pattern WS = '\s\t\r\n' +pattern FIRSTNAMECHAR = '_a-zA-Z\x80-\xff' +pattern NAMECHAR = '$FIRSTNAMECHAR\d' +pattern OP = '!\$%&\(\)\*\+,-\/:;<=>\?@\[\]\^\{\}~|' + +state IN_SSL_DEFAULT: +/[$WS]+/: # stay +# comments +'//': paint(upto, SSL_DEFAULT), => IN_SSL_COMMENT_1 +'#': paint(upto, SSL_DEFAULT), => IN_SSL_COMMENT_1 +'/*': paint(upto, SSL_DEFAULT), => IN_SSL_COMMENT_2 + +# strings and lifetime literals +'"': paint(upto, SSL_DEFAULT), => IN_SSL_DSTRING +'\'': paint(upto, SSL_DEFAULT), => IN_SSL_SSTRING + +# identifiers and keywords +/[$FIRSTNAMECHAR][$NAMECHAR]*/: paint(upto, SSL_DEFAULT), => IN_SSL_IORO + +# numbers +/0[Xx][0-9a-fA-F]+/ : paint(upto, SSL_DEFAULT), paint(include, SSL_NUMBER) # Hex numbers +/[-+]?\d/ : paint(upto, SSL_DEFAULT), => IN_SSL_NUMBER_1 +/[-+]?\.\d/ : paint(upto, SSL_DEFAULT), => IN_SSL_NUMBER_2 + +# operators +/%(\\\/|\\*|in|o|x)?%/ : paint(upto, SSL_DEFAULT), paint(include, SSL_OPERATOR) +/[$OP]/ : paint(upto, SSL_DEFAULT), paint(include, SSL_OPERATOR) + +# === custom states === + + +# comments +state IN_SSL_COMMENT_1: +/[\r\n]/: paint(upto, SSL_COMMENT), => IN_SSL_DEFAULT + +state IN_SSL_COMMENT_2: +'*/': paint(include, SSL_COMMENTBLOCK), => IN_SSL_DEFAULT + +# strings and lifetime literals +state IN_SSL_DSTRING: +'"': paint(include, SSL_STRING), => IN_SSL_DEFAULT + +state IN_SSL_SSTRING: +'\'': paint(include, SSL_STRING), => IN_SSL_DEFAULT +/[$WS]+/: paint(upto, SSL_STRING), => IN_SSL_DEFAULT +/[$OP]+/: paint(upto, SSL_STRING), redo, => IN_SSL_DEFAULT + + +# identifiers and keywords +state IN_SSL_IORO: +'!': paint(include, SSL_OPERATOR), => IN_SSL_DEFAULT +/[$FIRSTNAMECHAR][$NAMECHAR]*/: # stay +/$/: paint(upto, SSL_IDENTIFIER), => IN_SSL_DEFAULT +/./: paint(upto, SSL_IDENTIFIER), redo, => IN_SSL_DEFAULT + +# numbers +state IN_SSL_NUMBER_1 : +/$/ : paint(upto, SSL_NUMBER), => IN_SSL_DEFAULT +'.' : => IN_SSL_NUMBER_2 +/[\d]/ : #stay +/[Ee][-+]?/ : => IN_SSL_NUMBER_3 +/./ : paint(upto, SSL_NUMBER), redo, => IN_SSL_DEFAULT + +state IN_SSL_NUMBER_2: +/$/ : paint(upto, SSL_NUMBER), => IN_SSL_DEFAULT +/[\d]/ : #stay +/[Ee][-+]?/ : => IN_SSL_NUMBER_3 +'.' : paint(upto, SSL_NUMBER), paint(include, SSL_OPERATOR), => IN_SSL_DEFAULT +/./ : paint(upto, SSL_NUMBER), redo, => IN_SSL_DEFAULT + +state IN_SSL_NUMBER_3: +/$/ : paint(upto, SSL_NUMBER), => IN_SSL_DEFAULT +/[^\d]/ : paint(upto, SSL_NUMBER), redo, => IN_SSL_DEFAULT From 5f3b43b87aacd4a874a5aecbcf9481a80a2c2332 Mon Sep 17 00:00:00 2001 From: Defman21 Date: Sat, 6 Jan 2018 20:19:47 +0300 Subject: [PATCH 2/3] Rust: linting Signed-off-by: Defman21 --- .../content/pref/pref-syntax-checking.js | 17 +++ .../content/pref/pref-syntax-checking.xul | 39 ++++++ src/chrome/komodo/locale/en-US/pref/pref.dtd | 5 + src/lint/Conscript | 1 + src/lint/koRustLinter.py | 128 ++++++++++++++++++ 5 files changed, 190 insertions(+) create mode 100644 src/lint/koRustLinter.py diff --git a/src/chrome/komodo/content/pref/pref-syntax-checking.js b/src/chrome/komodo/content/pref/pref-syntax-checking.js index 2a3f43b6e2..827e93a23f 100644 --- a/src/chrome/komodo/content/pref/pref-syntax-checking.js +++ b/src/chrome/komodo/content/pref/pref-syntax-checking.js @@ -428,6 +428,23 @@ function javaScriptInfo(languageName) { }; } +languageInfo.Rust = { + browseForRustcBinary: () => { + let rustc_binary = document.getElementById('rust.linter.binaries.rustc'); + let currentPath = rustc_binary.value; + let path = ko.filepicker.browseForExeFile(null, currentPath || ""); + if (path) + rustc_binary.value = path; + }, + browseForCargoBinary: () => { + let cargo_config = document.getElementById('rust.linter.binaries.cargo'); + let currentPath = cargo_config.value; + let path = ko.filepicker.browseForExeFile(null, currentPath || ""); + if (path) + cargo_config.value = path; + } +}; + function typescript_setup() { if (!('TypeScript' in dialog)) { dialog.TypeScript = {}; diff --git a/src/chrome/komodo/content/pref/pref-syntax-checking.xul b/src/chrome/komodo/content/pref/pref-syntax-checking.xul index 5aeb2b875e..f60679e587 100644 --- a/src/chrome/komodo/content/pref/pref-syntax-checking.xul +++ b/src/chrome/komodo/content/pref/pref-syntax-checking.xul @@ -71,6 +71,45 @@ + + + + + + &rustChecking.rustcBinary; + + +