Skip to content

Commit 71e48d8

Browse files
author
half-arch
committed
fix: clipboard module and pipeline with keyword properties
- Add clipboard.in and clipboard.out as aliases for clipboard.get - Allow keywords (in, out, on, off, etc.) as property names after '.' - Move clipboard module assembly to after InitializeClipboardBuiltins() Test results: clipboard => {get, set, clear, in, out} clipboard.out => <builtin_function> "test" | clipboard.in => works (no error) "test" | upper => TEST
1 parent e91f80a commit 71e48d8

4 files changed

Lines changed: 44 additions & 12 deletions

File tree

src/havel-lang/lexer/Lexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const std::unordered_map<std::string, TokenType> Lexer::KEYWORDS = {
3434
{"enum", TokenType::Enum},
3535
{"on", TokenType::On},
3636
{"off", TokenType::Off},
37+
{"out", TokenType::Out},
3738
{"when", TokenType::When},
3839
{"mode", TokenType::Mode},
3940
{"repeat", TokenType::Repeat},

src/havel-lang/lexer/Lexer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ enum class TokenType {
6161
Enum, // enum
6262
On,
6363
Off,
64+
Out, // for clipboard.out etc.
6465
When,
6566
Mode,
6667
Repeat, // repeat

src/havel-lang/parser/Parser.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,12 +2664,39 @@ Parser::parseMemberExpression(std::unique_ptr<havel::ast::Expression> object) {
26642664
auto dotTok = at(); // Save token location before consuming
26652665
advance(); // consume '.'
26662666

2667-
// Property names can be identifiers or certain keywords (like 'config')
2667+
// Property names can be identifiers or certain keywords
2668+
// Many keywords should be allowed as property names (e.g., clipboard.in, clipboard.out)
26682669
if (at().type != havel::TokenType::Identifier &&
26692670
at().type != havel::TokenType::Config &&
26702671
at().type != havel::TokenType::Devices &&
26712672
at().type != havel::TokenType::Modes &&
2672-
at().type != havel::TokenType::Mode) {
2673+
at().type != havel::TokenType::Mode &&
2674+
at().type != havel::TokenType::In &&
2675+
at().type != havel::TokenType::Out &&
2676+
at().type != havel::TokenType::On &&
2677+
at().type != havel::TokenType::Off &&
2678+
at().type != havel::TokenType::When &&
2679+
at().type != havel::TokenType::Loop &&
2680+
at().type != havel::TokenType::For &&
2681+
at().type != havel::TokenType::While &&
2682+
at().type != havel::TokenType::If &&
2683+
at().type != havel::TokenType::Else &&
2684+
at().type != havel::TokenType::Return &&
2685+
at().type != havel::TokenType::Ret &&
2686+
at().type != havel::TokenType::Fn &&
2687+
at().type != havel::TokenType::Let &&
2688+
at().type != havel::TokenType::Break &&
2689+
at().type != havel::TokenType::Continue &&
2690+
at().type != havel::TokenType::Switch &&
2691+
at().type != havel::TokenType::Case &&
2692+
at().type != havel::TokenType::Default &&
2693+
at().type != havel::TokenType::Match &&
2694+
at().type != havel::TokenType::Struct &&
2695+
at().type != havel::TokenType::Enum &&
2696+
at().type != havel::TokenType::Try &&
2697+
at().type != havel::TokenType::Catch &&
2698+
at().type != havel::TokenType::Finally &&
2699+
at().type != havel::TokenType::Throw) {
26732700
failAt(at(), "Expected property name after '.'");
26742701
}
26752702

src/havel-lang/runtime/Interpreter.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4787,16 +4787,6 @@ void Interpreter::InitializeSystemBuiltins() {
47874787
return HavelValue(arr);
47884788
}));
47894789

4790-
// Expose as module objects
4791-
auto clip = std::make_shared<std::unordered_map<std::string, HavelValue>>();
4792-
if (auto v = environment->Get("clipboard.get"))
4793-
(*clip)["get"] = *v;
4794-
if (auto v = environment->Get("clipboard.set"))
4795-
(*clip)["set"] = *v;
4796-
if (auto v = environment->Get("clipboard.clear"))
4797-
(*clip)["clear"] = *v;
4798-
environment->Define("clipboard", HavelValue(clip));
4799-
48004790
// Create audio module
48014791
auto audioMod =
48024792
std::make_shared<std::unordered_map<std::string, HavelValue>>();
@@ -5910,6 +5900,19 @@ void Interpreter::InitializeClipboardBuiltins() {
59105900

59115901
environment->Define("clipboardmanager", HavelValue(clipMgrObj));
59125902
}
5903+
5904+
// Assemble clipboard module object (after all functions are defined)
5905+
auto clip = std::make_shared<std::unordered_map<std::string, HavelValue>>();
5906+
if (auto v = environment->Get("clipboard.get")) {
5907+
(*clip)["get"] = *v;
5908+
(*clip)["in"] = *v; // Alias for get
5909+
(*clip)["out"] = *v; // Alias for get (returns current clipboard content)
5910+
}
5911+
if (auto v = environment->Get("clipboard.set"))
5912+
(*clip)["set"] = *v;
5913+
if (auto v = environment->Get("clipboard.clear"))
5914+
(*clip)["clear"] = *v;
5915+
environment->Define("clipboard", HavelValue(clip));
59135916
}
59145917

59155918
void Interpreter::InitializeTextBuiltins() {

0 commit comments

Comments
 (0)