diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 1e37eb7..55b4e53 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -8,17 +8,11 @@ // A task runner that calls a custom npm script that compiles the extension. { - "version": "0.1.0", + "version": "2.0.0", // we want to run npm "command": "npm", - // the command is a shell script - "isShellCommand": true, - - // show the output window only if unrecognized errors occur. - "showOutput": "silent", - // we run the custom script "compile" as defined in package.json "args": ["run", "compile", "--loglevel", "silent"], @@ -26,5 +20,24 @@ "isBackground": true, // use the standard tsc in watch mode problem matcher to find compile problems in the output. - "problemMatcher": "$tsc-watch" + "problemMatcher": "$tsc-watch", + "tasks": [ + { + "label": "npm", + "type": "shell", + "command": "npm", + "args": [ + "run", + "compile", + "--loglevel", + "silent" + ], + "isBackground": true, + "problemMatcher": "$tsc-watch", + "group": { + "_id": "build", + "isDefault": false + } + } + ] } \ No newline at end of file diff --git a/README.md b/README.md index cf50984..ddf3603 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This extension adds [Hy language](https://www.github.com/hylang/hy) support to VS Code. Features (presently) include basic syntax highlighting and the ability to evaluate expressions by sending them to a Hy REPL. -![](https://raw.githubusercontent.com/xuqinghan/vscode-hy/master/images/syntax_hy.PNG) +![](https://raw.githubusercontent.com/hylang/vscode-hy/master/images/syntax_hy.PNG) Features: - [x] Basic syntax highlighting diff --git a/package.json b/package.json index 15e7dd1..6a499a4 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,21 @@ { - "name": "vscode-hy", - "displayName": "vscode-hy", + "name": "vscode-hy-official", + "displayName": "vscode-hy (hylang official)", "description": "Hy language support for VSCode", "keywords": [ "hy", "syntax" ], - "version": "0.0.4", - "publisher": "xuqinghan", + "version": "0.0.2", + "publisher": "hylang", "icon": "images/hy-logo-small.png", "main": "./out/src/hyMain", "license": "MIT", "author": { - "name": "Qinghan Xu" + "name": "Caleb Figgers" }, "engines": { - "vscode": "^1.11.0" + "vscode": "^1.34.0" }, "categories": [ "Programming Languages", @@ -30,12 +30,12 @@ ], "repository": { "type": "git", - "url": "https://github.com/xuqinghan/vscode-hy.git" + "url": "https://github.com/hylang/vscode-hy.git" }, "bugs": { - "url": "https://github.com/xuqinghan/vscode-hy/issues" + "url": "https://github.com/hylang/vscode-hy/issues" }, - "homepage": "https://github.com/xuqinghan/vscode-hy", + "homepage": "https://github.com/hylang/vscode-hy", "contributes": { "languages": [ { @@ -54,7 +54,7 @@ { "language": "hy", "scopeName": "source.hy", - "path": "./syntaxes/hy.tmLanguage" + "path": "./syntaxes/hy.tmLanguage.json" } ], "commands": [ @@ -95,16 +95,11 @@ "test": "node ./node_modules/vscode/bin/test" }, "devDependencies": { - "typescript": "^4.0.0", - "vscode": "^1.0.0", - "mocha": "^2.3.3", + "@types/mocha": "^2.2.32", "@types/node": "^12.12.0", "@types/vscode": "^1.34.0", - "@types/mocha": "^2.2.32" - }, - "__metadata": { - "id": "ed3bed5c-7cc7-40fd-9452-e53599e890a3", - "publisherDisplayName": "xuqinghan", - "publisherId": "b8f9b3d2-b308-4194-a789-ed1843c40998" + "mocha": "^10.1.0", + "typescript": "^4.0.0", + "vscode": "^1.0.0" } -} \ No newline at end of file +} diff --git a/syntaxes/hy.tmLanguage b/syntaxes/hy.tmLanguage deleted file mode 100644 index 0ea9be5..0000000 --- a/syntaxes/hy.tmLanguage +++ /dev/null @@ -1,786 +0,0 @@ - - - - - comment - - The foldings do not currently work the way I want them to. This - may be a limitation of the way they are applied rather than the - regexps in use. Nonetheless, the foldings will end on the last - identically indented blank line following an s-expression. Not - ideal perhaps, but it works. Also, the #illegal pattern never - matches an unpaired ( as being illegal. Why?! -- Rob Rix - - Ok, hopefully this grammar works better on quoted stuff now. It - may break for fancy macros, but should generally work pretty - smoothly. -- Jacob Rus - - I have attempted to get this under control but because of the way folding - and indentation interact in Textmate, I am not sure if it is possible. In the - meantime, I have implemented Python-style folding anchored at newlines. - Additionally, I have made some minor improvements to the numeric constant - highlighting. Next up is square bracket expressions, I guess, but that - should be trivial. -- ozy` - - fileTypes - - hy - - keyEquivalent - ^~S - name - Hy - patterns - - - include - #comment - - - include - #block-comment - - - include - #sexp - - - include - #string - - - include - #language-functions - - - include - #quote - - - include - #illegal - - - repository - - comment - - begin - (^[ \t]+)?(?=;) - beginCaptures - - 1 - - name - punctuation.whitespace.comment.leading.hy - - - end - (?!\G) - patterns - - - begin - ; - beginCaptures - - 0 - - name - punctuation.definition.comment.hy - - - end - \n - name - comment.line.semicolon.hy - - - - block-comment - - begin - \#\| - contentName - comment - end - \|\# - name - comment - patterns - - - include - #block-comment - name - comment - - - - constants - - patterns - - - match - #[t|f] - name - constant.language.boolean.hy - - - match - (?<=[\(\s])((#e|#i)?[0-9]+(\.[0-9]+)?|(#x)[0-9a-fA-F]+|(#o)[0-7]+|(#b)[01]+)(?=[\s;()'",\[\]]) - name - constant.numeric.hy - - - - illegal - - match - [()\[\]] - name - invalid.illegal.parenthesis.hy - - language-functions - - patterns - - - match - (?x) - (?<=(\s|\(|\[)) # preceded by space or ( - ( do|or|and|else|quasiquote|begin|if|case|set!| - cond|let|unquote|define|let\*|unquote-splicing|delay| - letrec| - #hy - =|!=|>=|<=|>|<| - .|->|->>|and|as->|assert|assoc|break|comment|cond| - dfor|setv|defclass|defn| - continue|do|doc|#doc| - defn/a|defmain|defmacro|defmacro/g!|defmacro!| - deftag|del|doto|eval-and-compile|eval-when-compile| - first|for|gensym|get|gfor|global|if|if\*|if-not| - lif|lif-not|import|fn|fn/a|last|lfor|nonlocal| - not|or|print|quasiquote|quote|require| - rest|return|sfor|cut|raise|try|unless| - unpack-iterable|unpack-mapping|unquote| - unquote-splice|when|while|with|with/a| - with-decorator|#@|with-gensyms|xor|yield|yield-from - ) - (?=(\s|\()) - name - keyword.control.hy - - - comment - - These functions run a test, and return a boolean - answer. - - match - (?x) - (?<=(\s|\()) # preceded by space or ( - ( char-alphabetic|char-lower-case|char-numeric| - char-ready|char-upper-case|char-whitespace| - (?:char|string)(?:-ci)?(?:=|<=?|>=?)| - atom|boolean|bound-identifier=|char|complex| - identifier|integer|symbol|free-identifier=|inexact| - eof-object|exact|list|(?:input|output)-port|pair| - real|rational|zero|vector|negative|odd|null|string| - eq|equal|eqv|even|number|positive|procedure - ) - (\?) # name ends with ? sign - (?=(\s|\()) # followed by space or ( - - name - support.function.boolean-test.hy - - - comment - - These functions change one type into another. - - match - (?x) - (?<=(\s|\()) # preceded by space or ( - ( char->integer|exact->inexact|inexact->exact| - integer->char|symbol->string|list->vector| - list->string|identifier->symbol|vector->list| - string->list|string->number|string->symbol| - number->string - ) - (?=(\s|\()) # followed by space or ( - - name - support.function.convert-type.hy - - - comment - - These functions are potentially dangerous because - they have side-effects which could affect other - parts of the program. - - match - (?x) - (?<=(\s|\()) # preceded by space or ( - ( set-(?:car|cdr)| # set car/cdr - (?:vector|string)-(?:fill|set) # fill/set string/vector - ) - (!) # name ends with ! sign - (?=(\s|\()) # followed by space or ( - - name - support.function.with-side-effects.hy - - - comment - - +, -, *, /, =, >, etc. - - match - (?x) - (?<=(\s|\()) # preceded by space or ( - ( >=?|<=?|=|[*/+-]) - (?=(\s|\()) # followed by space or ( - - name - keyword.operator.arithmetic.hy - - - match - (?x) - (?<=(\s|\()) # preceded by space or ( - ( - #hy build in - .|->|->>|and|as->|assert|assoc|break|comment| - cond|continue|do|doc|#doc|dfor|setv|defclass| - defn|defn/a|defmain|defmacro|defmacro/g!|defmacro!| - deftag|del|doto|eval-and-compile|eval-when-compile| - first|for|gensym|get|gfor|global|if|if*|if-not| - import|fn|fn/a|last|lfor|nonlocal|not|or|print| - quasiquote|quote|require|rest|return|sfor|cut|raise| - try|unless|unpack-iterable|unpack-mapping|unquote| - unquote-splice|when|while|with|with/a|with-decorator| - with-gensyms|xor|yield|yield-from|#*| - - #hy core - butlast|coll?|comp|complement|constantly|dec| - disassemble|empty?|eval|every?|exec|float?| - fraction|even?|identity|inc|instance?|integer?| - interleave|interpose|iterable?|iterator?|juxt| - keyword|keyword?|macroexpand|macroexpand-1|mangle| - merge-with|name|neg?|none?|nth|numeric?|odd?| - partition|pos?|second|some|string?|symbol?|zero?| - #hy Sequence - cycle|distinct|drop|drop-last|drop-while|filter| - flatten|iterate|read|read-str|remove|repeat| - repeatedly|take|take-nth|take-while|unmangle| - - #py keyword and built-in https://docs.python.org/3/library/functions.html - False|None|True|as|in|is|lambda|nonlocal|not|pass| - abs|all|any|ascii|bin|bool|bytearray|bytes|callable| - chr|classmethod|compile|complex|delattr|dict|dir|divmod| - enumerate|eval|exec|filter|float|format|frozenset|getattr| - globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass| - iter|len|list|locals|map|max|memoryview|min|next|object|oct|open| - ord|pow|print|property|range|repr|reversed|round|set|setattr|slice| - sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__| - - # unary math operators - abs|acos|angle|asin|assoc|assq|assv|atan|ceiling| - cos|floor|round|sin|sqrt|tan| - (?:real|imag)-part|numerator|denominator - - # other math operators - modulo|exp|expt|remainder|quotient|lcm| - - # ports / files - call-with-(?:input|output)-file| - (?:close|current)-(?:input|output)-port| - with-(?:input|output)-from-file| - open-(?:input|output)-file| - - # char-«foo» - char-(?:downcase|upcase|ready)| - - # make-«foo» - make-(?:polar|promise|rectangular|string|vector) - - # string-«foo», vector-«foo» - string(?:-(?:append|copy|length|ref))?| - vector(?:-length|-ref) - ) - (?=(\s|\()) # followed by space or ( - - name - support.function.general.hy - - - - quote - - comment - - We need to be able to quote any kind of item, which creates - a tiny bit of complexity in our grammar. It is hopefully - not overwhelming complexity. - - Note: the first two matches are special cases. quoted - symbols, and quoted empty lists are considered constant.other - - - patterns - - - captures - - 1 - - name - punctuation.section.quoted.symbol.hy - - - match - (?x) - (')\s* - ([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*) - - name - constant.other.symbol.hy - - - captures - - 1 - - name - punctuation.section.quoted.empty-list.hy - - 2 - - name - meta.expression.hy - - 3 - - name - punctuation.section.expression.begin.hy - - 4 - - name - punctuation.section.expression.end.hy - - - match - (?x) - (')\s* - ((\()\s*(\))) - - name - constant.other.empty-list.schem - - - begin - (')\s* - beginCaptures - - 1 - - name - punctuation.section.quoted.hy - - - comment - quoted double-quoted string or s-expression - end - (?=[\s()])|(?<=\n) - name - string.other.quoted-object.hy - patterns - - - include - #quoted - - - - - - quote-sexp - - begin - (?<=\()\s*(quote)\b\s* - beginCaptures - - 1 - - name - keyword.control.quote.hy - - - comment - - Something quoted with (quote «thing»). In this case «thing» - will not be evaluated, so we are considering it a string. - - contentName - string.other.quote.hy - end - (?=[\s)])|(?<=\n) - patterns - - - include - #quoted - - - - quoted - - patterns - - - include - #string - - - begin - (\() - beginCaptures - - 1 - - name - punctuation.section.expression.begin.hy - - - end - (\)) - endCaptures - - 1 - - name - punctuation.section.expression.end.hy - - - name - meta.expression.hy - patterns - - - include - #quoted - - - - - include - #quote - - - include - #illegal - - - - sexp - - begin - (\() - beginCaptures - - 1 - - name - punctuation.section.expression.begin.hy - - - end - (\))(\n)? - endCaptures - - 1 - - name - punctuation.section.expression.end.hy - - 2 - - name - meta.after-expression.hy - - - name - meta.expression.hy - patterns - - - include - #comment - - - begin - (?x) - (?<=\() # preceded by ( - (defn) # defn - (\s+) #function name - ([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*)\s+ - \[ # list of parameters - ((?: - ([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*|[._]) - \s+ - )*(?: - ([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*|[._]) - )?) - (\]) - - captures - - 1 - - name - keyword.control.hy - - 2 - - name - punctuation.definition.function.hy - - 3 - - name - entity.name.function.hy - - 4 - - name - variable.parameter.function.hy - - 7 - - name - punctuation.definition.function.hy - - - end - (?=\)) - name - meta.declaration.procedure.hy - patterns - - - include - #comment - - - include - #sexp - - - include - #illegal - - - - - begin - (?x) - (?<=\() # preceded by ( - (fn)\s+ - (\[) # opening paren - ((?: - ([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*|[._]) - \s+ - )*(?: - ([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*|[._]) - )?) - (\]) # closing paren - - captures - - 1 - - name - keyword.control.hy - - 2 - - name - punctuation.definition.variable.hy - - 3 - - name - variable.parameter.hy - - 6 - - name - punctuation.definition.variable.hy - - - comment - - Not sure this one is quite correct. That \s* is - particularly troubling - - end - (?=\)) - name - meta.declaration.procedure.hy - patterns - - - include - #comment - - - include - #sexp - - - include - #illegal - - - - - begin - (?<=\()(defn)\s([[:alnum:]][[:alnum:]!$%&*+-./:<=>?@^_~]*)\s*.*? - captures - - 1 - - name - keyword.control.hy - - 2 - - name - variable.other.hy - - - end - (?=\)) - name - meta.declaration.variable.hy - patterns - - - include - #comment - - - include - #sexp - - - include - #illegal - - - - - include - #quote-sexp - - - include - #quote - - - include - #language-functions - - - include - #string - - - include - #constants - - - match - (?<=[\(\s])(#\\)(space|newline|tab)(?=[\s\)]) - name - constant.character.named.hy - - - match - (?<=[\(\s])(#\\)x[0-9A-F]{2,4}(?=[\s\)]) - name - constant.character.hex-literal.hy - - - match - (?<=[\(\s])(#\\).(?=[\s\)]) - name - constant.character.escape.hy - - - comment - - the . in (a . b) which conses together two elements - a and b. (a b c) == (a . (b . (c . nil))) - - match - (?<=[ ()])\.(?=[ ()]) - name - punctuation.separator.cons.hy - - - include - #sexp - - - include - #illegal - - - - string - - begin - (") - beginCaptures - - 1 - - name - punctuation.definition.string.begin.hy - - - end - (") - endCaptures - - 1 - - name - punctuation.definition.string.end.hy - - - name - string.quoted.double.hy - patterns - - - match - \\. - name - constant.character.escape.hy - - - - - scopeName - source.hy - uuid - 3EC2CFD0-909C-4692-AC29-1A60ADBC161E - - diff --git a/syntaxes/hy.tmLanguage.json b/syntaxes/hy.tmLanguage.json new file mode 100644 index 0000000..04fd3e6 --- /dev/null +++ b/syntaxes/hy.tmLanguage.json @@ -0,0 +1,80 @@ +{ + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "hy", + "patterns": [ + { + "include": "#all" + } + ], + "repository": { + "all":{ + "patterns": [ + { + "include": "#comment" + }, + { + "include":"#constants" + }, + { + "include": "#keywords" + }, + { + "include": "#strings" + }, + { + "include": "#operators" + }, + { + "include": "#keysym" + }, + { + "include": "#symbol" + } + ] + }, + "comment": { + "patterns": [{ + "name":"comment.line.hy", + "match": "(;).*$" + }] + }, + "constants": { + "patterns": [{ + "name": "constant.numeric.hy", + "match": "(?<=[\\{\\[\\(\\s])([0-9]+(\\.[0-9]+)?|(#x)[0-9a-fA-F]+|(#o)[0-7]+|(#b)[01]+)(?=[\\s;()'\",\\[\\]\\{\\}])" + }] + }, + "keywords": { + "patterns": [{ + "name": "keyword.control.hy", + "match": "\\b(\\.|->|->>|and|as->|assert|assoc|break|comment|cond|continue|do|doc|#doc|dfor|setv|defclass|defn|defn\\/a|defmain|defmacro|defmacro\\/g!|defmacro!|deftag|del|doto|eval-and-compile|eval-when-compile|first|for|gensym|get|gfor|global|if|if\\*|if-not|import|fn|fn\\/a|last|lfor|nonlocal|not|or|print|quasiquote|quote|require|rest|return|sfor|cut|raise|try|unless|unpack-iterable|unpack-mapping|unquote|unquote-splice|when|while|with|with\\/a|with-decorator|with-gensyms|xor|yield|yield-from|butlast|coll\\?|comp|complement|constantly|dec|disassemble|empty\\?|eval|every\\?|exec|float\\?|fraction|even\\?|identity|inc|instance\\?|integer\\?|interleave|interpose|iterable\\?|iterator\\?|juxt|keyword|keyword\\?|macroexpand|macroexpand-1|mangle|merge-with|name|neg\\?|none\\?|nth|numeric\\?|odd\\?|partition|pos\\?|second|some|string\\?|symbol\\?|zero\\?|cycle|distinct|drop|drop-last|drop-while|filter|flatten|iterate|read|read-str|remove|repeat|repeatedly|take|take-nth|take-while|unmangle|False|None|True|as|in|is|lambda|nonlocal|not|pass|abs|all|any|ascii|bin|bool|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__|abs|acos|angle|asin|assoc|assq|assv|atan|ceiling|cos|floor|round|sin|sqrt|tan|(?:real|imag)-part|numerator|denominatormodulo|exp|expt|remainder|quotient|lcm|call-with-(?:input|output)-file|(?:close|current)-(?:input|output)-port|with-(?:input|output)-from-file|open-(?:input|output)-file|char-(?:downcase|upcase|ready)|make-(?:polar|promise|rectangular|string|vector)|string(?:-(?:append|copy|length|ref))|vector(?:-length|-ref))[\\s\\)]" + }] + }, + "operators":{ + "patterns": [{ + "name": "keyword.control.hy", + "match": "(?<=\\()\\s*([+\\/*-])" + }] + }, + "strings": { + "name": "string.quoted.double.hy", + "begin": "\"", + "end": "\"", + "patterns": [ + { + "name": "constant.character.escape.hy", + "match": "\\\\." + } + ] + }, + "keysym": { + "name": "variable.other.constant", + "match": "(?*]):[\\.:\\w_\\-=!@\\$%^&?\\/<>*]*" + }, + "symbol": { + "name": "variable.other.hy", + "match": "(?*#])[\\.a-zA-Z_\\-=!@\\$%^*#][\\.:\\w_\\-=!@\\$%^&?/<>*#]*" + } + }, + "scopeName": "source.hy" +} \ No newline at end of file diff --git a/test/syntax-sample.hy b/test/syntax-sample.hy new file mode 100644 index 0000000..0866e93 --- /dev/null +++ b/test/syntax-sample.hy @@ -0,0 +1,27 @@ +(defn greet [name] + "A simple greeting" + (print "hello from hy," name)) ; Symbols just white + +(defmacro hello [person] + `(print "Hello there," ~person)) + +(+ "hello " "world") ; = > "hello world" + +(setv mylist [1 2 3 4]) +(setv π 3.13159) + +(defn nospace [arg] (+ 1 arg)) +( defn withspace [arg] (+ 1 arg)) + +(defmacro nospace [arg] (+ 1 arg)) +( defmacro nospace [arg] (+ 1 arg)) + +(str thing) ; Python built-ins not color-coding + +(range 4 5) ; Python built-ins not color-coding + +(defmacro example [#* args] + (str (+ #* args))) + +(setv dict {:a 1 :b 2 :c 3}) +(get dict :a)