diff --git a/builder/parser.nix b/builder/parser.nix index feea4f9..eb6f75e 100644 --- a/builder/parser.nix +++ b/builder/parser.nix @@ -3,7 +3,7 @@ # in normalised form. let - inherit (builtins) elemAt mapAttrs split foldl' match filter typeOf; + inherit (builtins) elemAt mapAttrs split foldl' match filter typeOf hasAttr length; # Strip lines with comments & other junk stripStr = s: elemAt (split "^ *" (elemAt (split " *$" s) 0)) 2; @@ -16,9 +16,6 @@ let # Strip leading tabs characters (lines: map (l: elemAt (match "(\t)?(.*)" l) 1) lines) - # Strip comment lines - (filter (l: match "[ \t]*//.*" l != null)) - # Filter empty lines (filter (l: l != "")) ]; @@ -40,21 +37,40 @@ let in { - data = acc.data // ( + data = (acc.data // ( if directive == "" && rest == ")" then { } - else if inDirective != null && rest == "(" then { + else if inDirective != null && rest == "(" && ! hasAttr inDirective acc.data then { ${inDirective} = { }; - } else if inDirective != null then { + } + else if rest == "(" || rest == ")" then { } + else if inDirective != null then { ${inDirective} = acc.data.${inDirective} // { ${directive} = rest; }; - } else { + } else if directive == "replace" then + ( + let + segments = split " => " rest; + getSegment = elemAt segments; + in + assert length segments == 3; { + replace = acc.data.replace // { + ${getSegment 0} = "=> ${getSegment 2}"; + }; + } + ) + else { ${directive} = rest; } + ) ); inherit inDirective; }) { inDirective = null; - data = { }; + data = { + require = { }; + replace = { }; + exclude = { }; + }; } lines ).data; @@ -98,14 +114,14 @@ let data // { replace = mapAttrs - (n: v: + (_: v: let m = match "=> ([^ ]+) (.+)" v; m2 = match "=> (.*+)" v; in if m != null then { goPackagePath = elemAt m 0; - version = parseVersion (elemAt m 1); + version = elemAt m 1; } else { path = elemAt m2 0; }) @@ -113,12 +129,6 @@ let } ); - parseRequire = data: ( - data // { - require = mapAttrs (n: v: parseVersion v) data.require; - } - ); - splitString = sep: s: filter (t: t != [ ]) (split sep s); in @@ -128,5 +138,4 @@ foldl' (acc: f: f acc) (splitString "\n" contents) [ parseLines normaliseDirectives parseReplace - parseRequire ]