mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Add ".es" to recognised ECMAScript extensions
* Add ".es" to recognised JavaScript extensions * Add heuristic to differentiate Erlang from ECMAScript * Add test-case for .es heuristic
This commit is contained in:
committed by
Arfon Smith
parent
7c8bc8561d
commit
24b368a30c
@@ -128,6 +128,14 @@ module Linguist
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
disambiguate ".es" do |data|
|
||||||
|
if /^\s*(?:%%|main\s*\(.*?\)\s*->)/.match(data)
|
||||||
|
Language["Erlang"]
|
||||||
|
elsif /(?:\/\/|("|')use strict\1|export\s+default\s|\/\*.*?\*\/)/m.match(data)
|
||||||
|
Language["JavaScript"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
disambiguate ".for", ".f" do |data|
|
disambiguate ".for", ".f" do |data|
|
||||||
if /^: /.match(data)
|
if /^: /.match(data)
|
||||||
Language["Forth"]
|
Language["Forth"]
|
||||||
|
|||||||
@@ -1694,6 +1694,7 @@ JavaScript:
|
|||||||
- .js
|
- .js
|
||||||
- ._js
|
- ._js
|
||||||
- .bones
|
- .bones
|
||||||
|
- .es
|
||||||
- .es6
|
- .es6
|
||||||
- .frag
|
- .frag
|
||||||
- .gs
|
- .gs
|
||||||
|
|||||||
26
samples/Erlang/170-os-daemons.es
Executable file
26
samples/Erlang/170-os-daemons.es
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
#! /usr/bin/env escript
|
||||||
|
|
||||||
|
% 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.
|
||||||
|
|
||||||
|
loop() ->
|
||||||
|
loop(io:read("")).
|
||||||
|
|
||||||
|
loop({ok, _}) ->
|
||||||
|
loop(io:read(""));
|
||||||
|
loop(eof) ->
|
||||||
|
stop;
|
||||||
|
loop({error, Reason}) ->
|
||||||
|
throw({error, Reason}).
|
||||||
|
|
||||||
|
main([]) ->
|
||||||
|
loop().
|
||||||
1
samples/Erlang/release
Normal file → Executable file
1
samples/Erlang/release
Normal file → Executable file
@@ -119,4 +119,3 @@ execute_overlay([{copy, In, Out} | Rest], Vars, BaseDir, TargetDir) ->
|
|||||||
|
|
||||||
exit_code(ExitCode) ->
|
exit_code(ExitCode) ->
|
||||||
erlang:halt(ExitCode, [{flush, true}]).
|
erlang:halt(ExitCode, [{flush, true}]).
|
||||||
|
|
||||||
|
|||||||
104
samples/Erlang/single-context.es
Executable file
104
samples/Erlang/single-context.es
Executable file
@@ -0,0 +1,104 @@
|
|||||||
|
#! /usr/bin/env escript
|
||||||
|
% This file is part of Emonk released under the MIT license.
|
||||||
|
% See the LICENSE file for more information.
|
||||||
|
|
||||||
|
main([]) ->
|
||||||
|
start(64, 1000);
|
||||||
|
main([N]) ->
|
||||||
|
start(list_to_integer(N), 1000);
|
||||||
|
main([N, M]) ->
|
||||||
|
start(list_to_integer(N), list_to_integer(M)).
|
||||||
|
|
||||||
|
|
||||||
|
start(N, M) ->
|
||||||
|
code:add_pathz("test"),
|
||||||
|
code:add_pathz("ebin"),
|
||||||
|
{ok, Ctx} = emonk:create_ctx(),
|
||||||
|
{ok, undefined} = emonk:eval(Ctx, js()),
|
||||||
|
run(Ctx, N, M),
|
||||||
|
wait(N).
|
||||||
|
|
||||||
|
run(_, 0, _) ->
|
||||||
|
ok;
|
||||||
|
run(Ctx, N, M) ->
|
||||||
|
Self = self(),
|
||||||
|
Pid = spawn(fun() -> do_js(Self, Ctx, M) end),
|
||||||
|
io:format("Spawned: ~p~n", [Pid]),
|
||||||
|
run(Ctx, N-1, M).
|
||||||
|
|
||||||
|
wait(0) ->
|
||||||
|
ok;
|
||||||
|
wait(N) ->
|
||||||
|
receive
|
||||||
|
{finished, Pid} -> ok
|
||||||
|
end,
|
||||||
|
io:format("Finished: ~p~n", [Pid]),
|
||||||
|
wait(N-1).
|
||||||
|
|
||||||
|
do_js(Parent, _, 0) ->
|
||||||
|
Parent ! {finished, self()};
|
||||||
|
do_js(Parent, Ctx, M) ->
|
||||||
|
io:format("Running: ~p~n", [M]),
|
||||||
|
Test = random_test(),
|
||||||
|
{ok, [Resp]} = emonk:call(Ctx, <<"f">>, [Test]),
|
||||||
|
Sorted = sort(Resp),
|
||||||
|
true = Test == Sorted,
|
||||||
|
do_js(Parent, Ctx, M-1).
|
||||||
|
|
||||||
|
js() ->
|
||||||
|
<<"var f = function(x) {return [x];};">>.
|
||||||
|
|
||||||
|
random_test() ->
|
||||||
|
Tests = [
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
1,
|
||||||
|
-1,
|
||||||
|
3.1416,
|
||||||
|
-3.1416,
|
||||||
|
12.0e10,
|
||||||
|
1.234E+10,
|
||||||
|
-1.234E-10,
|
||||||
|
10.0,
|
||||||
|
123.456,
|
||||||
|
10.0,
|
||||||
|
<<"foo">>,
|
||||||
|
<<"foo", 5, "bar">>,
|
||||||
|
<<"">>,
|
||||||
|
<<"\n\n\n">>,
|
||||||
|
<<"\" \b\f\r\n\t\"">>,
|
||||||
|
{[]},
|
||||||
|
{[{<<"foo">>, <<"bar">>}]},
|
||||||
|
{[{<<"foo">>, <<"bar">>}, {<<"baz">>, 123}]},
|
||||||
|
[],
|
||||||
|
[[]],
|
||||||
|
[1, <<"foo">>],
|
||||||
|
{[{<<"foo">>, [123]}]},
|
||||||
|
{[{<<"foo">>, [1, 2, 3]}]},
|
||||||
|
{[{<<"foo">>, {[{<<"bar">>, true}]}}]},
|
||||||
|
{[
|
||||||
|
{<<"foo">>, []},
|
||||||
|
{<<"bar">>, {[{<<"baz">>, true}]}}, {<<"alice">>, <<"bob">>}
|
||||||
|
]},
|
||||||
|
[-123, <<"foo">>, {[{<<"bar">>, []}]}, null]
|
||||||
|
],
|
||||||
|
{_, [Test | _]} = lists:split(random:uniform(length(Tests)) - 1, Tests),
|
||||||
|
sort(Test).
|
||||||
|
|
||||||
|
sort({Props}) ->
|
||||||
|
objsort(Props, []);
|
||||||
|
sort(List) when is_list(List) ->
|
||||||
|
lstsort(List, []);
|
||||||
|
sort(Other) ->
|
||||||
|
Other.
|
||||||
|
|
||||||
|
objsort([], Acc) ->
|
||||||
|
{lists:sort(Acc)};
|
||||||
|
objsort([{K,V} | Rest], Acc) ->
|
||||||
|
objsort(Rest, [{K, sort(V)} | Acc]).
|
||||||
|
|
||||||
|
lstsort([], Acc) ->
|
||||||
|
lists:reverse(Acc);
|
||||||
|
lstsort([Val | Rest], Acc) ->
|
||||||
|
lstsort(Rest, [sort(Val) | Acc]).
|
||||||
13
samples/JavaScript/axios.es
Normal file
13
samples/JavaScript/axios.es
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
async getIndex(prefix) {
|
||||||
|
const {data} = await axios.get((prefix || "") + "/index.json");
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async getContent(path, prefix) {
|
||||||
|
const {data} = await axios.get((prefix || "") + "/" + path + ".json");
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
samples/JavaScript/index.es
Normal file
35
samples/JavaScript/index.es
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import config from "../webpack.config";
|
||||||
|
import webpackDevMiddleware from "webpack-dev-middleware";
|
||||||
|
import webpackHot from "webpack-hot-middleware";
|
||||||
|
import webpack from "webpack";
|
||||||
|
import express from "express";
|
||||||
|
|
||||||
|
app.use(webpackDevMiddleware(compiler, {
|
||||||
|
noInfo: false,
|
||||||
|
quiet: false,
|
||||||
|
publicPath: config.output.publicPath,
|
||||||
|
hot: true,
|
||||||
|
historyApiFallback: true
|
||||||
|
}));
|
||||||
|
|
||||||
|
app.get("/(:root).json", (req, resp) => {
|
||||||
|
resp.send(indexer.index(req.params.root));
|
||||||
|
});
|
||||||
|
|
||||||
|
export default function(){
|
||||||
|
const server = http.createServer(app);
|
||||||
|
|
||||||
|
server.listen(3000);
|
||||||
|
|
||||||
|
const wss = new WebSocketServer({server});
|
||||||
|
|
||||||
|
let id = 1;
|
||||||
|
wss.on("connection", (ws) => {
|
||||||
|
console.log("Hello", " world");
|
||||||
|
let wsId = id++;
|
||||||
|
sessions[wsId] = ws;
|
||||||
|
ws.on("close", () => {
|
||||||
|
delete sessions[wsId]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -84,6 +84,13 @@ class TestHeuristcs < Minitest::Test
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_es_by_heuristics
|
||||||
|
assert_heuristics({
|
||||||
|
"Erlang" => all_fixtures("Erlang", "*.es"),
|
||||||
|
"JavaScript" => all_fixtures("JavaScript", "*.es")
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
def test_f_by_heuristics
|
def test_f_by_heuristics
|
||||||
assert_heuristics({
|
assert_heuristics({
|
||||||
"FORTRAN" => all_fixtures("FORTRAN", "*.f") + all_fixtures("FORTRAN", "*.for"),
|
"FORTRAN" => all_fixtures("FORTRAN", "*.f") + all_fixtures("FORTRAN", "*.for"),
|
||||||
|
|||||||
Reference in New Issue
Block a user