mirror of
https://github.com/emacs-twist/org-babel.git
synced 2024-12-14 11:07:30 +00:00
Merge pull request #1 from emacs-twist/fix-odd-arguments
Fix handling of source blocks with odd arguments
This commit is contained in:
commit
a20daf701c
3 changed files with 76 additions and 3 deletions
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
@ -19,3 +19,5 @@ jobs:
|
|||
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Run tests
|
||||
run: nix-instantiate --eval --strict test/test.nix
|
||||
- name: Test parameter parsing
|
||||
run: nix-instantiate --eval --strict test/testParams.nix
|
||||
|
|
|
@ -1,11 +1,36 @@
|
|||
with builtins;
|
||||
let
|
||||
takeWhile = p: xs:
|
||||
if length xs == 0
|
||||
then [ ]
|
||||
else if p (head xs)
|
||||
then [ (head xs) ] ++ takeWhile p (tail xs)
|
||||
else [ ];
|
||||
|
||||
dropWhile = p: xs:
|
||||
if length xs == 0
|
||||
then [ ]
|
||||
else if p (head xs)
|
||||
then dropWhile p (tail xs)
|
||||
else xs;
|
||||
|
||||
isKeyword = s: stringLength s > 0 && substring 0 1 s == ":";
|
||||
|
||||
notKeyword = s: !(isKeyword s);
|
||||
|
||||
toValue = xs:
|
||||
if length xs == 0
|
||||
then true
|
||||
else if length xs == 1
|
||||
then head xs
|
||||
else xs;
|
||||
|
||||
listToAttrs = xs:
|
||||
if length xs == 0
|
||||
then { }
|
||||
else if length xs == 1
|
||||
then throw "parseParamsString: Found an odd number of items: ${head xs}"
|
||||
else { ${head xs} = elemAt xs 1; } // listToAttrs (tail (tail xs));
|
||||
else {
|
||||
${head xs} = toValue (takeWhile notKeyword (tail xs));
|
||||
} // listToAttrs (dropWhile notKeyword (tail xs));
|
||||
|
||||
stripPat = "[[:space:]]+(.*)";
|
||||
|
||||
|
@ -20,6 +45,10 @@ let
|
|||
|
||||
go = m: [ (elemAt m 0) ] ++ parse (elemAt m 1);
|
||||
|
||||
# TODO: Handle expressions
|
||||
#
|
||||
# This will be hard, as it requires an elisp parser.
|
||||
# It is probably better to unsupport it.
|
||||
parse' = string:
|
||||
if string == ""
|
||||
then [ ]
|
||||
|
|
42
test/testParams.nix
Normal file
42
test/testParams.nix
Normal file
|
@ -0,0 +1,42 @@
|
|||
# nix-instantiate --eval --strict test/testParams.nix
|
||||
let
|
||||
pkgs = import <nixpkgs> {};
|
||||
parse = import ../nix/parseParamsString.nix;
|
||||
in
|
||||
pkgs.lib.runTests {
|
||||
testSimple = {
|
||||
expr = parse ":tangle no";
|
||||
expected = {
|
||||
":tangle" = "no";
|
||||
};
|
||||
};
|
||||
|
||||
testOdd = {
|
||||
expr = parse ":async";
|
||||
expected = {
|
||||
":async" = true;
|
||||
};
|
||||
};
|
||||
|
||||
testNonAlpha = {
|
||||
expr = parse ":session kernel-16577-ssh.json";
|
||||
expected = {
|
||||
":session" = "kernel-16577-ssh.json";
|
||||
};
|
||||
};
|
||||
|
||||
# This case is unsupported right now.
|
||||
#
|
||||
# testExpression = {
|
||||
# expr = parse ":value '(this is so annoying)";
|
||||
# expected = { };
|
||||
# };
|
||||
|
||||
testDoubleQuotes = {
|
||||
expr = parse ":caption \"Hello, I am Katja\"";
|
||||
expected = {
|
||||
":caption" = "Hello, I am Katja";
|
||||
};
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue