diff --git a/lib/linguist/samples.json b/lib/linguist/samples.json index d4248099..1478e7c5 100644 --- a/lib/linguist/samples.json +++ b/lib/linguist/samples.json @@ -384,8 +384,8 @@ ".gemrc" ] }, - "tokens_total": 362003, - "languages_total": 429, + "tokens_total": 363070, + "languages_total": 430, "tokens": { "ABAP": { "*/**": 1, @@ -12484,11 +12484,11 @@ "egrep": 1 }, "Erlang": { - "SHEBANG#!escript": 2, - "%": 13, - "-": 88, - "*": 3, - "erlang": 1, + "SHEBANG#!escript": 3, + "%": 134, + "-": 262, + "*": 9, + "erlang": 5, "smp": 1, "enable": 1, "sname": 1, @@ -12496,43 +12496,43 @@ "mnesia": 1, "debug": 1, "verbose": 1, - "main": 3, - "(": 172, - "[": 46, + "main": 4, + "(": 236, + "[": 66, "String": 2, - "]": 41, - ")": 166, + "]": 61, + ")": 230, "try": 2, "N": 6, "list_to_integer": 1, "F": 16, "fac": 4, - "io": 3, - "format": 3, + "io": 5, + "format": 7, "catch": 2, - "_": 45, + "_": 52, "usage": 3, - "end": 2, - ";": 43, - ".": 28, - "halt": 1, + "end": 3, + ";": 56, + ".": 37, + "halt": 2, "export": 2, "main/1": 1, "For": 1, "each": 1, "header": 1, - "file": 3, + "file": 6, "it": 2, "scans": 1, "thru": 1, "all": 1, "records": 1, - "and": 4, + "and": 8, "create": 1, "helper": 1, "functions": 2, "Helper": 1, - "are": 1, + "are": 3, "setters": 1, "getters": 1, "fields": 4, @@ -12550,20 +12550,20 @@ "<->": 5, "hrl": 1, "relative": 1, - "to": 1, + "to": 2, "current": 1, "dir": 1, - "OutDir": 2, + "OutDir": 4, "ModuleName": 3, "HeaderComment": 2, "ModuleDeclaration": 2, - "+": 208, + "+": 214, "<": 1, "Src": 10, "format_src": 8, - "lists": 6, + "lists": 11, "sort": 1, - "flatten": 5, + "flatten": 6, "read": 2, "generate_type_default_function": 2, "write_file": 1, @@ -12572,22 +12572,22 @@ "HeaderFile": 4, "epp": 1, "parse_file": 1, - "of": 2, - "{": 90, - "ok": 22, + "of": 9, + "{": 109, + "ok": 34, "Tree": 4, - "}": 90, + "}": 109, "parse": 2, - "error": 2, + "error": 4, "Error": 4, "catched_error": 1, - "end.": 2, - "|": 15, + "end.": 3, + "|": 25, "T": 24, "when": 29, "length": 6, "Type": 3, - "A": 4, + "A": 5, "B": 4, "NSrc": 4, "_Type": 1, @@ -12601,7 +12601,7 @@ "if": 1, "generate_setter_getter_function": 5, "generate_type_function": 3, - "true": 1, + "true": 3, "generate_fields_function": 2, "generate_fields_atom_function": 2, "parse_field_name": 5, @@ -12620,7 +12620,7 @@ "parse_field": 6, "AccFields": 6, "AccParentFields": 6, - "case": 1, + "case": 3, "Field": 2, "PField": 2, "parse_field_atom": 4, @@ -12630,7 +12630,7 @@ "to_setter_getter_function": 5, "setter": 2, "getter": 2, - "This": 1, + "This": 2, "is": 1, "auto": 1, "generated": 1, @@ -12640,7 +12640,7 @@ "t": 1, "edit": 1, "record_utils": 1, - "compile": 1, + "compile": 2, "export_all": 1, "include": 1, "abstract_message": 21, @@ -12671,12 +12671,254 @@ "ParentProperty": 6, "is_atom": 2, "set": 13, - "Value": 33, + "Value": 35, "NewObj": 20, "Obj#abstract_message": 7, "Obj#async_message": 3, "NewParentObject": 2, - "undefined.": 1 + "undefined.": 1, + "Mode": 1, + "coding": 1, + "utf": 1, + "tab": 1, + "width": 1, + "c": 2, + "basic": 1, + "offset": 1, + "indent": 1, + "tabs": 1, + "mode": 2, + "BSD": 1, + "LICENSE": 1, + "Copyright": 1, + "Michael": 2, + "Truog": 2, + "": 1, + "at": 1, + "gmail": 1, + "dot": 1, + "com": 1, + "All": 2, + "rights": 1, + "reserved.": 1, + "Redistribution": 1, + "use": 2, + "in": 3, + "source": 2, + "binary": 2, + "forms": 1, + "with": 2, + "or": 3, + "without": 2, + "modification": 1, + "permitted": 1, + "provided": 2, + "that": 1, + "the": 9, + "following": 4, + "conditions": 3, + "met": 1, + "Redistributions": 2, + "code": 2, + "must": 3, + "retain": 1, + "above": 2, + "copyright": 2, + "notice": 2, + "this": 4, + "list": 2, + "disclaimer.": 1, + "form": 1, + "reproduce": 1, + "disclaimer": 1, + "documentation": 1, + "and/or": 1, + "other": 1, + "materials": 2, + "distribution.": 1, + "advertising": 1, + "mentioning": 1, + "features": 1, + "software": 3, + "display": 1, + "acknowledgment": 1, + "product": 1, + "includes": 1, + "developed": 1, + "by": 1, + "The": 1, + "name": 1, + "author": 2, + "may": 1, + "not": 1, + "be": 1, + "used": 1, + "endorse": 1, + "promote": 1, + "products": 1, + "derived": 1, + "from": 1, + "specific": 1, + "prior": 1, + "written": 1, + "permission": 1, + "THIS": 2, + "SOFTWARE": 2, + "IS": 1, + "PROVIDED": 1, + "BY": 1, + "THE": 5, + "COPYRIGHT": 2, + "HOLDERS": 1, + "AND": 4, + "CONTRIBUTORS": 2, + "ANY": 4, + "EXPRESS": 1, + "OR": 8, + "IMPLIED": 2, + "WARRANTIES": 2, + "INCLUDING": 3, + "BUT": 2, + "NOT": 2, + "LIMITED": 2, + "TO": 2, + "OF": 8, + "MERCHANTABILITY": 1, + "FITNESS": 1, + "FOR": 2, + "PARTICULAR": 1, + "PURPOSE": 1, + "ARE": 1, + "DISCLAIMED.": 1, + "IN": 3, + "NO": 1, + "EVENT": 1, + "SHALL": 1, + "OWNER": 1, + "BE": 1, + "LIABLE": 1, + "DIRECT": 1, + "INDIRECT": 1, + "INCIDENTAL": 1, + "SPECIAL": 1, + "EXEMPLARY": 1, + "CONSEQUENTIAL": 1, + "DAMAGES": 1, + "PROCUREMENT": 1, + "SUBSTITUTE": 1, + "GOODS": 1, + "SERVICES": 1, + "LOSS": 1, + "USE": 2, + "DATA": 1, + "PROFITS": 1, + "BUSINESS": 1, + "INTERRUPTION": 1, + "HOWEVER": 1, + "CAUSED": 1, + "ON": 1, + "THEORY": 1, + "LIABILITY": 2, + "WHETHER": 1, + "CONTRACT": 1, + "STRICT": 1, + "TORT": 1, + "NEGLIGENCE": 1, + "OTHERWISE": 1, + "ARISING": 1, + "WAY": 1, + "OUT": 1, + "EVEN": 1, + "IF": 1, + "ADVISED": 1, + "POSSIBILITY": 1, + "SUCH": 1, + "DAMAGE.": 1, + "sys": 2, + "RelToolConfig": 5, + "target_dir": 2, + "TargetDir": 14, + "overlay": 2, + "OverlayConfig": 4, + "consult": 1, + "Spec": 2, + "reltool": 2, + "get_target_spec": 1, + "make_dir": 1, + "eexist": 1, + "exit_code": 3, + "eval_target_spec": 1, + "root_dir": 1, + "process_overlay": 2, + "shell": 3, + "Command": 3, + "Arguments": 3, + "CommandSuffix": 2, + "reverse": 4, + "os": 1, + "cmd": 1, + "io_lib": 2, + "boot_rel_vsn": 2, + "Config": 2, + "_RelToolConfig": 1, + "rel": 2, + "_Name": 1, + "Ver": 1, + "proplists": 1, + "lookup": 1, + "Ver.": 1, + "minimal": 2, + "parsing": 1, + "for": 1, + "handling": 1, + "mustache": 11, + "syntax": 1, + "Body": 2, + "Context": 11, + "Result": 10, + "_Context": 1, + "KeyStr": 6, + "mustache_key": 4, + "C": 4, + "Rest": 10, + "Key": 2, + "list_to_existing_atom": 1, + "dict": 2, + "find": 1, + "support": 1, + "based": 1, + "on": 1, + "rebar": 1, + "overlays": 1, + "BootRelVsn": 2, + "OverlayVars": 2, + "from_list": 1, + "erts_vsn": 1, + "system_info": 1, + "version": 1, + "rel_vsn": 1, + "hostname": 1, + "net_adm": 1, + "localhost": 1, + "BaseDir": 7, + "get_cwd": 1, + "execute_overlay": 6, + "_Vars": 1, + "_BaseDir": 1, + "_TargetDir": 1, + "mkdir": 1, + "Out": 4, + "Vars": 7, + "filename": 3, + "join": 3, + "copy": 1, + "In": 2, + "InFile": 3, + "OutFile": 2, + "filelib": 1, + "is_file": 1, + "ExitCode": 2, + "flush": 1 }, "fish": { "#": 18, @@ -39027,7 +39269,7 @@ "edn": 227, "Elm": 628, "Emacs Lisp": 1756, - "Erlang": 1861, + "Erlang": 2928, "fish": 636, "Forth": 1516, "GAS": 133, @@ -39128,7 +39370,7 @@ "edn": 1, "Elm": 3, "Emacs Lisp": 2, - "Erlang": 4, + "Erlang": 5, "fish": 3, "Forth": 7, "GAS": 1, @@ -39209,5 +39451,5 @@ "Xtend": 2, "YAML": 1 }, - "md5": "044f21ee2f8688cbafbbea5e5b664823" + "md5": "93478efbbf3cf2d97da26c6b2257429a" } \ No newline at end of file diff --git a/samples/Erlang/release.script! b/samples/Erlang/release.script! new file mode 100644 index 00000000..9b06a6dd --- /dev/null +++ b/samples/Erlang/release.script! @@ -0,0 +1,122 @@ +#!/usr/bin/env escript +%%! +%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*- +% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et: +%%% +%%%------------------------------------------------------------------------ +%%% BSD LICENSE +%%% +%%% Copyright (c) 2013, Michael Truog +%%% All rights reserved. +%%% +%%% Redistribution and use in source and binary forms, with or without +%%% modification, are permitted provided that the following conditions are met: +%%% +%%% * Redistributions of source code must retain the above copyright +%%% notice, this list of conditions and the following disclaimer. +%%% * Redistributions in binary form must reproduce the above copyright +%%% notice, this list of conditions and the following disclaimer in +%%% the documentation and/or other materials provided with the +%%% distribution. +%%% * All advertising materials mentioning features or use of this +%%% software must display the following acknowledgment: +%%% This product includes software developed by Michael Truog +%%% * The name of the author may not be used to endorse or promote +%%% products derived from this software without specific prior +%%% written permission +%%% +%%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +%%% CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +%%% INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +%%% OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +%%% DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +%%% CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +%%% SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +%%% BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +%%% SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +%%% WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +%%% NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +%%% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH +%%% DAMAGE. +%%%------------------------------------------------------------------------ + +-author('mjtruog [at] gmail (dot) com'). + +-mode(compile). + +main(_) -> + {ok, + [{sys, _} = RelToolConfig, + {target_dir, TargetDir}, + {overlay, OverlayConfig}]} = file:consult("reltool.config"), + {ok, Spec} = reltool:get_target_spec([RelToolConfig]), + case file:make_dir(TargetDir) of + ok -> + ok; + {error, eexist} -> + io:format("release already exists? (~p)~n", [TargetDir]), + exit_code(1) + end, + ok = reltool:eval_target_spec(Spec, code:root_dir(), TargetDir), + ok = process_overlay(RelToolConfig, TargetDir, OverlayConfig), + exit_code(0). + +shell(Command, Arguments) -> + CommandSuffix = " && echo 0 || echo 1", + case lists:reverse(os:cmd(lists:flatten( + io_lib:format(Command ++ CommandSuffix, Arguments)))) of + [_, $0 | _] -> + ok; + [_, $1 | _] -> + io:format("\"~s\" failed!~n", [io_lib:format(Command, Arguments)]), + error + end. + +boot_rel_vsn({sys, Config} = _RelToolConfig) -> + {rel, _Name, Ver, _} = proplists:lookup(rel, Config), + Ver. + +%% minimal parsing for handling mustache syntax +mustache(Body, Context) -> + mustache(Body, "", Context). +mustache([], Result, _Context) -> + lists:reverse(Result); +mustache([${, ${ | KeyStr], Result, Context) -> + mustache_key(KeyStr, "", Result, Context); +mustache([C | Rest], Result, Context) -> + mustache(Rest, [C | Result], Context). +mustache_key([$}, $} | Rest], KeyStr, Result, Context) -> + Key = erlang:list_to_existing_atom(lists:reverse(KeyStr)), + {ok, Value} = dict:find(Key, Context), + mustache(Rest, lists:reverse(Value) ++ Result, Context); +mustache_key([C | Rest], KeyStr, Result, Context) -> + mustache_key(Rest, [C | KeyStr], Result, Context). + +%% support minimal overlay based on rebar overlays +process_overlay(RelToolConfig, TargetDir, OverlayConfig) -> + BootRelVsn = boot_rel_vsn(RelToolConfig), + OverlayVars = + dict:from_list([{erts_vsn, "erts-" ++ erlang:system_info(version)}, + {rel_vsn, BootRelVsn}, + {target_dir, TargetDir}, + {hostname, net_adm:localhost()}]), + {ok, BaseDir} = file:get_cwd(), + execute_overlay(OverlayConfig, OverlayVars, BaseDir, TargetDir). + +execute_overlay([], _Vars, _BaseDir, _TargetDir) -> + ok; +execute_overlay([{mkdir, Out} | Rest], Vars, BaseDir, TargetDir) -> + OutDir = mustache(filename:join(TargetDir, Out), Vars), + ok = shell("mkdir -p ~s", [OutDir]), + execute_overlay(Rest, Vars, BaseDir, TargetDir); +execute_overlay([{copy, In, Out} | Rest], Vars, BaseDir, TargetDir) -> + InFile = mustache(filename:join(BaseDir, In), Vars), + OutFile = mustache(filename:join(TargetDir, Out), Vars), + true = filelib:is_file(InFile), + ok = shell("cp -R ~s ~s", [InFile, OutFile]), + execute_overlay(Rest, Vars, BaseDir, TargetDir). + +exit_code(ExitCode) -> + erlang:halt(ExitCode, [{flush, true}]). +