mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-26 07:04:27 +00:00
add shortcut ~@ for unquote-splice
This commit is contained in:
parent
5d6fbcc9cc
commit
d363700a39
@ -27,6 +27,8 @@ class Reader
|
|||||||
return $this->readSpecialForm($tokens, $index, 'quasiquote');
|
return $this->readSpecialForm($tokens, $index, 'quasiquote');
|
||||||
} elseif ($tokens[$index] == "~") {
|
} elseif ($tokens[$index] == "~") {
|
||||||
return $this->readSpecialForm($tokens, $index, 'unquote');
|
return $this->readSpecialForm($tokens, $index, 'unquote');
|
||||||
|
} elseif ($tokens[$index] == "~@") {
|
||||||
|
return $this->readSpecialForm($tokens, $index, 'unquote-splice');
|
||||||
} elseif ($tokens[$index] == '(') {
|
} elseif ($tokens[$index] == '(') {
|
||||||
return $this->readList($tokens, $index);
|
return $this->readList($tokens, $index);
|
||||||
} elseif ($tokens[$index] == '[') {
|
} elseif ($tokens[$index] == '[') {
|
||||||
|
@ -101,6 +101,14 @@ class Tokenizer
|
|||||||
// Other special characters
|
// Other special characters
|
||||||
$addCurrent();
|
$addCurrent();
|
||||||
$tokens[] = $c;
|
$tokens[] = $c;
|
||||||
|
} elseif ($c == '@') {
|
||||||
|
// If the last token was ~ then add @ to it
|
||||||
|
if (count($tokens) > 0 && $tokens[count($tokens) - 1] == '~') {
|
||||||
|
$tokens[count($tokens) - 1] .= $c;
|
||||||
|
} else {
|
||||||
|
// Otherwise treat it like normal character
|
||||||
|
$current .= $c;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// All other characters
|
// All other characters
|
||||||
$current .= $c;
|
$current .= $c;
|
||||||
|
@ -28,6 +28,7 @@ class ReaderTest extends TestCase
|
|||||||
["'", 'quote'],
|
["'", 'quote'],
|
||||||
['`', 'quasiquote'],
|
['`', 'quasiquote'],
|
||||||
['~', 'unquote'],
|
['~', 'unquote'],
|
||||||
|
['~@', 'unquote-splice'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +76,9 @@ class TokenizerTest extends TestCase
|
|||||||
// Other non-alphabet characters are symbols
|
// Other non-alphabet characters are symbols
|
||||||
["(aa!@#$%^&*-_=+bb<>,./?\\|cc)", ['(', "aa!@#$%^&*-_=+bb<>,./?\\|cc", ')']],
|
["(aa!@#$%^&*-_=+bb<>,./?\\|cc)", ['(', "aa!@#$%^&*-_=+bb<>,./?\\|cc", ')']],
|
||||||
|
|
||||||
|
// @ after ~ is single token, @ anywhere else is normal character
|
||||||
|
['aa@~@@bb', ['aa@', '~@', '@bb']],
|
||||||
|
|
||||||
// Strings
|
// Strings
|
||||||
['"abc"', ['"abc"']],
|
['"abc"', ['"abc"']],
|
||||||
['aa"bb"cc', ['aa', '"bb"', 'cc']],
|
['aa"bb"cc', ['aa', '"bb"', 'cc']],
|
||||||
|
Loading…
Reference in New Issue
Block a user