mirror of https://github.com/Wilfred/difftastic/
Merge commit '7aa24fe8616072fc1a659f72d5b60bd8c01fb5cc'
commit
db8797d6c2
@ -1,3 +1,8 @@
|
||||
1.0.0 (September 26, 2022)
|
||||
0.1.0 (June 16, 2023)
|
||||
* Add support for OTP 26 constructs
|
||||
* maybe
|
||||
* map comprehension
|
||||
|
||||
0.0.1 (September 26, 2022)
|
||||
|
||||
* Initial Release
|
||||
|
||||
@ -0,0 +1,228 @@
|
||||
;; Copyright (c) Facebook, Inc. and its affiliates.
|
||||
;;
|
||||
;; Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
;;
|
||||
;; Unless required by applicable law or agreed to in writing, software
|
||||
;; distributed under the License is distributed on an "AS IS" BASIS,
|
||||
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
;; See the License for the specific language governing permissions and
|
||||
;; limitations under the License.
|
||||
;; ---------------------------------------------------------------------
|
||||
|
||||
;; Based initially on the contents of https://github.com/WhatsApp/tree-sitter-erlang/issues/2 by @Wilfred
|
||||
;; and https://github.com/the-mikedavis/tree-sitter-erlang/blob/main/queries/highlights.scm
|
||||
;;
|
||||
;; The tests are also based on those in
|
||||
;; https://github.com/the-mikedavis/tree-sitter-erlang/tree/main/test/highlight
|
||||
;;
|
||||
|
||||
|
||||
;; First match wins in this file
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Attributes
|
||||
|
||||
;; module attribute
|
||||
(module_attribute
|
||||
name: (atom) @module)
|
||||
|
||||
;; behaviour
|
||||
(behaviour_attribute name: (atom) @module)
|
||||
|
||||
;; export
|
||||
|
||||
;; Import attribute
|
||||
(import_attribute
|
||||
module: (atom) @module)
|
||||
|
||||
;; export_type
|
||||
|
||||
;; optional_callbacks
|
||||
|
||||
;; compile
|
||||
(compile_options_attribute
|
||||
options: (tuple
|
||||
expr: (atom)
|
||||
expr: (list
|
||||
exprs: (binary_op_expr
|
||||
lhs: (atom)
|
||||
rhs: (integer)))))
|
||||
|
||||
;; file attribute
|
||||
|
||||
;; record
|
||||
(record_decl name: (atom) @type)
|
||||
(record_decl name: (macro_call_expr name: (var) @constant))
|
||||
(record_field name: (atom) @property)
|
||||
|
||||
;; type alias
|
||||
|
||||
;; opaque
|
||||
|
||||
;; Spec attribute
|
||||
(spec fun: (atom) @function)
|
||||
(spec
|
||||
module: (module name: (atom) @module)
|
||||
fun: (atom) @function)
|
||||
|
||||
;; callback
|
||||
(callback fun: (atom) @function)
|
||||
|
||||
;; wild attribute
|
||||
(wild_attribute name: (attr_name name: (atom) @keyword))
|
||||
|
||||
;; fun decl
|
||||
|
||||
;; include/include_lib
|
||||
|
||||
;; ifdef/ifndef
|
||||
(pp_ifdef name: (_) @keyword.directive)
|
||||
(pp_ifndef name: (_) @keyword.directive)
|
||||
|
||||
;; define
|
||||
(pp_define
|
||||
lhs: (macro_lhs
|
||||
name: (_) @keyword.directive
|
||||
args: (var_args args: (var))))
|
||||
(pp_define
|
||||
lhs: (macro_lhs
|
||||
name: (var) @constant))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Functions
|
||||
(fa fun: (atom) @function)
|
||||
(type_name name: (atom) @function)
|
||||
(call expr: (atom) @function)
|
||||
(function_clause name: (atom) @function)
|
||||
(internal_fun fun: (atom) @function)
|
||||
|
||||
;; This is a fudge, we should check that the operator is '/'
|
||||
;; But our grammar does not (currently) provide it
|
||||
(binary_op_expr lhs: (atom) @function rhs: (integer))
|
||||
|
||||
;; Others
|
||||
(remote_module module: (atom) @module)
|
||||
(remote fun: (atom) @function)
|
||||
(macro_call_expr name: (var) @keyword.directive args: (_) )
|
||||
(macro_call_expr name: (var) @constant)
|
||||
(macro_call_expr name: (atom) @keyword.directive)
|
||||
(record_field_name name: (atom) @property)
|
||||
(record_name name: (atom) @type)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Reserved words
|
||||
[ "after"
|
||||
"and"
|
||||
"band"
|
||||
"begin"
|
||||
"behavior"
|
||||
"behaviour"
|
||||
"bnot"
|
||||
"bor"
|
||||
"bsl"
|
||||
"bsr"
|
||||
"bxor"
|
||||
"callback"
|
||||
"case"
|
||||
"catch"
|
||||
"compile"
|
||||
"define"
|
||||
"div"
|
||||
"elif"
|
||||
"else"
|
||||
"end"
|
||||
"endif"
|
||||
"export"
|
||||
"export_type"
|
||||
"file"
|
||||
"fun"
|
||||
"if"
|
||||
"ifdef"
|
||||
"ifndef"
|
||||
"import"
|
||||
"include"
|
||||
"include_lib"
|
||||
"module"
|
||||
"of"
|
||||
"opaque"
|
||||
"optional_callbacks"
|
||||
"or"
|
||||
"receive"
|
||||
"record"
|
||||
"spec"
|
||||
"try"
|
||||
"type"
|
||||
"undef"
|
||||
"unit"
|
||||
"when"
|
||||
"xor"] @keyword
|
||||
|
||||
["andalso" "orelse"] @keyword.operator
|
||||
|
||||
;; Punctuation
|
||||
["," "." ";"] @punctuation.delimiter
|
||||
["(" ")" "{" "}" "[" "]" "<<" ">>"] @punctuation.bracket
|
||||
|
||||
;; Operators
|
||||
["!"
|
||||
"->"
|
||||
"<-"
|
||||
"#"
|
||||
"::"
|
||||
"|"
|
||||
":"
|
||||
"="
|
||||
"||"
|
||||
|
||||
"+"
|
||||
"-"
|
||||
"bnot"
|
||||
"not"
|
||||
|
||||
"/"
|
||||
"*"
|
||||
"div"
|
||||
"rem"
|
||||
"band"
|
||||
"and"
|
||||
|
||||
"+"
|
||||
"-"
|
||||
"bor"
|
||||
"bxor"
|
||||
"bsl"
|
||||
"bsr"
|
||||
"or"
|
||||
"xor"
|
||||
|
||||
"++"
|
||||
"--"
|
||||
|
||||
"=="
|
||||
"/="
|
||||
"=<"
|
||||
"<"
|
||||
">="
|
||||
">"
|
||||
"=:="
|
||||
"=/="
|
||||
] @operator
|
||||
|
||||
;;; Comments
|
||||
((var) @comment.discard
|
||||
(#match? @comment.discard "^_"))
|
||||
|
||||
(dotdotdot) @comment.discard
|
||||
(comment) @comment
|
||||
|
||||
;; Primitive types
|
||||
(string) @string
|
||||
(char) @constant
|
||||
(integer) @number
|
||||
(var) @variable
|
||||
(atom) @string.special.symbol
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,189 @@
|
||||
%% Copyright (c) Facebook, Inc. and its affiliates.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%% ---------------------------------------------------------------------
|
||||
|
||||
|
||||
%% Based on
|
||||
%% https://github.com/the-mikedavis/tree-sitter-erlang/blob/main/test/highlight/attributes.erl
|
||||
|
||||
-module(attributes).
|
||||
% ^ keyword
|
||||
% ^ punctuation.bracket
|
||||
% ^ module
|
||||
% ^ punctuation.bracket
|
||||
% ^ punctuation.delimiter
|
||||
|
||||
-module('lru').
|
||||
% ^ keyword
|
||||
% ^ module
|
||||
|
||||
-export([a_func/1,another_func/2]).
|
||||
% ^ keyword
|
||||
% ^ punctuation.bracket
|
||||
% ^ function
|
||||
% ^ operator
|
||||
% ^ number
|
||||
% ^ function
|
||||
|
||||
-export_type([a_type/1,another_type/2]).
|
||||
% ^ keyword
|
||||
% ^ punctuation.bracket
|
||||
% ^ function
|
||||
% ^ operator
|
||||
% ^ number
|
||||
% ^ function
|
||||
|
||||
-import(lists, [sort/1,map/2]).
|
||||
% ^ keyword
|
||||
% ^ module
|
||||
% ^ function
|
||||
% ^ operator
|
||||
% ^ number
|
||||
|
||||
-type t() :: integer()
|
||||
% ^ keyword
|
||||
% ^ function
|
||||
% ^ operator
|
||||
% ^ function
|
||||
| 0
|
||||
% ^ operator
|
||||
% ^ number
|
||||
| 0..1
|
||||
% ^ operator
|
||||
% ^ number
|
||||
% ^ number
|
||||
| $a..$b
|
||||
% ^ operator
|
||||
% ^ constant
|
||||
% ^ constant
|
||||
| [non_neg_integer(), ...]
|
||||
% ^ operator
|
||||
% ^ punctuation.bracket
|
||||
% ^ function
|
||||
% ^ comment.discard
|
||||
| #{mfa() => atom()}.
|
||||
% ^ operator
|
||||
% ^ operator
|
||||
% ^ punctuation.bracket
|
||||
|
||||
-opaque o() :: integer().
|
||||
% ^ keyword
|
||||
% ^ function
|
||||
% ^ operator
|
||||
% ^ function
|
||||
|
||||
-spec ok_this(Term) -> {ok, Term} when Term :: any().
|
||||
% ^ keyword
|
||||
% ^ function
|
||||
% ^ variable
|
||||
% ^ operator
|
||||
% ^ punctuation.bracket
|
||||
% ^ string.special.symbol
|
||||
% ^ punctuation.delimiter
|
||||
% ^ variable
|
||||
% ^ keyword
|
||||
% ^ variable
|
||||
% ^ operator
|
||||
% ^ function
|
||||
|
||||
-spec erlang:ok() -> ok.
|
||||
% ^ module
|
||||
% ^ function
|
||||
% ^ string.special.symbol
|
||||
|
||||
-ifdef(debug).
|
||||
% ^ keyword
|
||||
% ^ keyword.directive
|
||||
-ifdef(TEST).
|
||||
% ^ keyword
|
||||
% ^ keyword.directive
|
||||
-define(LOG(X), io:format("~80~n", [X])).
|
||||
% ^ keyword
|
||||
% ^ keyword.directive
|
||||
% ^ variable
|
||||
% ^ module
|
||||
% ^ function
|
||||
% ^ string
|
||||
% ^ variable
|
||||
|
||||
-define(SUB_PASS_TIMES, compile__sub_pass_times).
|
||||
% ^ keyword
|
||||
% ^ constant
|
||||
% ^ string.special.symbol
|
||||
-elif true.
|
||||
% ^ keyword
|
||||
-else.
|
||||
% ^ keyword
|
||||
-define(LOG(X), ok).
|
||||
% ^ keyword
|
||||
% ^ keyword.directive
|
||||
% ^ variable
|
||||
% ^ string.special.symbol
|
||||
-endif.
|
||||
% ^ keyword
|
||||
|
||||
-record(person, {name,
|
||||
% ^ keyword
|
||||
% ^ type
|
||||
% ^ property
|
||||
email_address="",
|
||||
% ^ property
|
||||
% ^ string
|
||||
ssn :: string(),
|
||||
% ^ property
|
||||
phone=1 :: integer()}).
|
||||
% ^ property
|
||||
|
||||
-record(?MODULE, {name}).
|
||||
% ^ constant
|
||||
% ^ property
|
||||
|
||||
-compile({no_auto_import,[min/2]}).
|
||||
% ^ keyword
|
||||
% % ^ string.special.symbol
|
||||
% ^ function
|
||||
|
||||
-include("file.hrl").
|
||||
% ^ keyword
|
||||
|
||||
-file("myfile.erl", 3).
|
||||
% ^ keyword
|
||||
|
||||
-callback name(Arguments) -> Result.
|
||||
% ^ keyword
|
||||
% ^ function
|
||||
|
||||
-optional_callbacks([a_callback/3]).
|
||||
% ^ keyword
|
||||
% ^ function
|
||||
|
||||
-ifndef(TEST).
|
||||
% ^ keyword
|
||||
% ^ keyword.directive
|
||||
|
||||
-behaviour(gen_server).
|
||||
% ^ keyword
|
||||
% ^ module
|
||||
-behavior(gen_server).
|
||||
% ^ keyword
|
||||
% ^ module
|
||||
|
||||
-dialyzer({nowarn_function, [compile/1]}).
|
||||
% ^ keyword
|
||||
% ^ string.special.symbol
|
||||
% ^ function
|
||||
|
||||
-record(garbage_collection, {}).
|
||||
%% ^ keyword
|
||||
%% ^ type
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,32 @@
|
||||
%% Copyright (c) Facebook, Inc. and its affiliates.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%% ---------------------------------------------------------------------
|
||||
|
||||
foo() ->
|
||||
?assertMatch({ok, _}, start()),
|
||||
%% ^ keyword.directive
|
||||
|
||||
?_assertEqual(a, a),
|
||||
%% ^ keyword.directive
|
||||
|
||||
State#state.config#config.pid
|
||||
%% ^ variable
|
||||
%% ^ operator
|
||||
%% ^ type
|
||||
%% ^ punctuation.delimiter
|
||||
%% ^ property
|
||||
%% ^ operator
|
||||
%% ^ type
|
||||
%% ^ property
|
||||
.
|
||||
Loading…
Reference in New Issue