mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 05:14:45 +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');
|
||||
} elseif ($tokens[$index] == "~") {
|
||||
return $this->readSpecialForm($tokens, $index, 'unquote');
|
||||
} elseif ($tokens[$index] == "~@") {
|
||||
return $this->readSpecialForm($tokens, $index, 'unquote-splice');
|
||||
} elseif ($tokens[$index] == '(') {
|
||||
return $this->readList($tokens, $index);
|
||||
} elseif ($tokens[$index] == '[') {
|
||||
|
@ -101,6 +101,14 @@ class Tokenizer
|
||||
// Other special characters
|
||||
$addCurrent();
|
||||
$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 {
|
||||
// All other characters
|
||||
$current .= $c;
|
||||
|
@ -28,6 +28,7 @@ class ReaderTest extends TestCase
|
||||
["'", 'quote'],
|
||||
['`', 'quasiquote'],
|
||||
['~', 'unquote'],
|
||||
['~@', 'unquote-splice'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -76,6 +76,9 @@ class TokenizerTest extends TestCase
|
||||
// Other non-alphabet characters are symbols
|
||||
["(aa!@#$%^&*-_=+bb<>,./?\\|cc)", ['(', "aa!@#$%^&*-_=+bb<>,./?\\|cc", ')']],
|
||||
|
||||
// @ after ~ is single token, @ anywhere else is normal character
|
||||
['aa@~@@bb', ['aa@', '~@', '@bb']],
|
||||
|
||||
// Strings
|
||||
['"abc"', ['"abc"']],
|
||||
['aa"bb"cc', ['aa', '"bb"', 'cc']],
|
||||
|
Loading…
Reference in New Issue
Block a user