dot access on aliases
This commit is contained in:
@@ -129,7 +129,26 @@ class Reader {
|
||||
};
|
||||
|
||||
// Because macro keys are sorted by length and peekChars(0) returns "", this will be used as the default reader macro:
|
||||
readTable[""] = (stream:Stream, k) -> Symbol(nextToken(stream, "a symbol name"));
|
||||
readTable[""] = (stream:Stream, k) -> {
|
||||
var position = stream.position();
|
||||
var token = nextToken(stream, "a symbol name");
|
||||
// Process dot-access on alias identifiers
|
||||
return if (token.indexOf(".") != -1) {
|
||||
try {
|
||||
Std.parseFloat(token);
|
||||
Symbol(token);
|
||||
} catch (err) {
|
||||
var tokenParts = token.split(".");
|
||||
var fieldExp = Symbol(tokenParts.shift());
|
||||
while (tokenParts.length > 0) {
|
||||
fieldExp = FieldExp(tokenParts.shift(), fieldExp.withPos(position));
|
||||
}
|
||||
fieldExp;
|
||||
}
|
||||
} else {
|
||||
Symbol(token);
|
||||
};
|
||||
}
|
||||
|
||||
return readTable;
|
||||
}
|
||||
|
@@ -309,6 +309,10 @@ class BasicTestCase extends Test {
|
||||
function testLetThrow() {
|
||||
_testLetThrow();
|
||||
}
|
||||
|
||||
function testDotAccessOnAlias() {
|
||||
_testDotAccessOnAlias();
|
||||
}
|
||||
}
|
||||
|
||||
class BasicObject {
|
||||
|
@@ -540,3 +540,10 @@
|
||||
(Assert.fail)}
|
||||
(catch [:String e]
|
||||
(Assert.equals "the error we want" e))))
|
||||
|
||||
// Test dot-access on identifiers aliases
|
||||
(var objWithField (object field 5))
|
||||
(var float 0.5) // This should still read as a float, not a dot access on a variable called 0
|
||||
(defAlias &ident owf objWithField)
|
||||
(function _testDotAccessOnAlias []
|
||||
(Assert.equals 5 owf.field))
|
@@ -44,14 +44,12 @@
|
||||
// TODO make an async annotation that throws an error if the promise is not wrapped in awaitLet or awaitBegin or returned by an async function?
|
||||
// but in some cases it doesn't matter and there are so many edge cases.
|
||||
(function insertAt [:vscode.Position pos text]
|
||||
(.edit activeTextEditor
|
||||
(activeTextEditor.edit
|
||||
(lambda [e]
|
||||
(e.insert pos text))))
|
||||
|
||||
(function insert [text]
|
||||
// TODO this let is because identifier alias dot access is broken:
|
||||
(let [editor activeTextEditor]
|
||||
(insertAt editor.selection.active text)))
|
||||
(insertAt activeTextEditor.selection.active text)))
|
||||
|
||||
/**
|
||||
* State
|
||||
|
Reference in New Issue
Block a user