Skip to content

Commit

Permalink
Merge branch 'main' into release/2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Sep 28, 2024
2 parents 210f82e + e5e144f commit dbb0eb4
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

patreon: inclyc
2 changes: 1 addition & 1 deletion libnixf/include/nixf/Basic/NodeKinds.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NODE(InterpolableParts)
/// \see Misc
NODE(Misc)
NODE(Dot)
NODE(Identifer)
NODE(Identifier)
NODE(AttrName)
NODE(AttrPath)
NODE(Binding)
Expand Down
2 changes: 1 addition & 1 deletion libnixf/include/nixf/Basic/Nodes/Basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Identifier : public Node {

public:
Identifier(LexerCursorRange Range, std::string Name)
: Node(NK_Identifer, Range), Name(std::move(Name)) {}
: Node(NK_Identifier, Range), Name(std::move(Name)) {}
[[nodiscard]] const std::string &name() const { return Name; }

[[nodiscard]] ChildVector children() const override { return {}; }
Expand Down
4 changes: 4 additions & 0 deletions libnixf/include/nixf/Basic/TokenKinds.inc
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@ TOK_BIN_OP(mul) // *
TOK_BIN_OP(div) // /
TOK_BIN_OP(concat) // ++

// [RFC 0418 Pipe operator](https://github.com/NixOS/rfcs/pull/148)
TOK_BIN_OP(pipe_into) // |>
TOK_BIN_OP(pipe_from) // <|

#endif // TOK_BIN_OP
14 changes: 10 additions & 4 deletions libnixf/src/Basic/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ class Diagnostic(TypedDict):
"severity": "Error",
"message": "extra `@` for lambda arg",
},
{
"sname": "parse-operator-noassoc",
"cname": "OperatorNotAssociative",
"severity": "Error",
"message": "operator is non-associative",
},
{
"sname": "let-dynamic",
"cname": "LetDynamic",
Expand Down Expand Up @@ -198,14 +204,14 @@ class Diagnostic(TypedDict):
{
"sname": "sema-unused-def-lambda-witharg-formal",
"cname": "UnusedDefLambdaWithArg_Formal",
"severity": "Warning",
"message": "argument `{}` in `@`-pattern is not used",
"severity": "Hint",
"message": "attribute `{}` of `@`-pattern argument is not used, but may be referenced from the argument",
},
{
"sname": "sema-unused-def-lambda-witharg-arg",
"cname": "UnusedDefLambdaWithArg_Arg",
"severity": "Hint",
"message": "attribute `{}` of `@`-pattern argument is not used, but may be referenced from the argument",
"severity": "Warning",
"message": "argument `{}` in `@`-pattern is not used",
},
{
"sname": "sema-extra-rec",
Expand Down
4 changes: 4 additions & 0 deletions libnixf/src/Parse/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ Token Lexer::lex() {
case '|':
if (consumePrefix("||"))
Tok = tok_op_or;
if (consumePrefix("|>"))
Tok = tok_op_pipe_into;
break;
case '!':
if (consumePrefix("!=")) {
Expand All @@ -538,6 +540,8 @@ Token Lexer::lex() {
case '<':
if (consumePrefix("<=")) {
Tok = tok_op_le;
} else if (consumePrefix("<|")) {
Tok = tok_op_pipe_from;
} else {
consume();
Tok = tok_op_lt;
Expand Down
30 changes: 19 additions & 11 deletions libnixf/src/Parse/ParseOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "Parser.h"

#include "nixf/Basic/Diagnostic.h"
#include "nixf/Basic/Nodes/Op.h"

#include <cassert>
Expand All @@ -16,6 +17,7 @@ namespace {

/// Binary operators:
///
/// %left |> | %right <|
/// %right ->
/// %left ||
/// %left &&
Expand All @@ -30,31 +32,35 @@ namespace {
/// %nonassoc NEGATE
std::pair<unsigned, unsigned> getBP(TokenKind Kind) {
switch (Kind) {
case tok_op_impl: // %right ->
case tok_op_pipe_from:
return {1, 2};
case tok_op_pipe_into:
return {2, 1};
case tok_op_impl: // %right ->
return {4, 3};
case tok_op_or: // %left ||
return {3, 4};
case tok_op_and: // %left &&
return {5, 6};
case tok_op_and: // %left &&
return {7, 8};
case tok_op_eq: // %nonassoc == !=
case tok_op_neq:
return {7, 7};
return {9, 9};
case tok_op_lt: // %nonassoc < > <= >=
case tok_op_le:
case tok_op_ge:
case tok_op_gt:
return {8, 8};
return {10, 10};
case tok_op_update: // %right //
return {10, 9};
// %left NOT - 11
return {12, 11};
// %left NOT - 13
case tok_op_add: // %left + -
case tok_op_negate:
return {12, 13};
case tok_op_mul: // %left * /
return {14, 15};
case tok_op_mul: // %left * /
return {16, 17};
case tok_op_div:
case tok_op_concat: // %right ++
return {17, 16};
return {19, 18};
// % op_negate
default:
__builtin_unreachable();
Expand Down Expand Up @@ -115,7 +121,9 @@ std::shared_ptr<Expr> Parser::parseExprOpBP(unsigned LeftRBP) {
if (LeftRBP > LBP)
return Prefix;
if (LeftRBP == LBP) {
// TODO: noassoc
// Report error, operator OP and expr_op is not associative.
Diags.emplace_back(Diagnostic::DK_OperatorNotAssociative,
Tok.range());
}
consume();
assert(LastToken && "consume() should have set LastToken");
Expand Down
2 changes: 1 addition & 1 deletion libnixf/test/Basic/Nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TEST(Node, Descend) {
std::vector<Diagnostic> Diag;
auto Root = parse(Src, Diag);

ASSERT_EQ(Root->descend({{0, 2}, {0, 2}})->kind(), Node::NK_Identifer);
ASSERT_EQ(Root->descend({{0, 2}, {0, 2}})->kind(), Node::NK_Identifier);
ASSERT_EQ(Root->descend({{0, 2}, {0, 4}})->kind(), Node::NK_Binding);
}

Expand Down
85 changes: 85 additions & 0 deletions libnixf/test/Parse/ParseOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Parser.h"

#include "nixf/Basic/Diagnostic.h"
#include "nixf/Basic/Nodes/Op.h"

namespace {
Expand Down Expand Up @@ -71,4 +72,88 @@ TEST(Parser, OpHasAttr_empty) {
ASSERT_EQ(Diags.size(), 0);
}

TEST(Parser, Op_NonAssociative) {
auto Src = R"(1 == 1 == 1)"sv;

std::vector<Diagnostic> Diags;
Parser P(Src, Diags);
auto AST = P.parseExpr();

ASSERT_TRUE(AST);
ASSERT_EQ(Diags.size(), 1);
ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_OperatorNotAssociative);
}

TEST(Parser, Op_PipeOperator_Forward) {
auto Src = R"(a |> b)"sv;

std::vector<Diagnostic> Diags;
Parser P(Src, Diags);
auto AST = P.parseExpr();

ASSERT_EQ(AST->kind(), Node::NK_ExprBinOp);
ASSERT_EQ(Diags.size(), 0);
}

TEST(Parser, Op_PipeOperator_Forward_LeftAssosiative) {
auto Src = R"(a |> b |> c)"sv;

std::vector<Diagnostic> Diags;
Parser P(Src, Diags);
auto AST = P.parseExpr();

ASSERT_TRUE(AST);

ASSERT_EQ(AST->kind(), Node::NK_ExprBinOp);

const auto &BinOp = static_cast<const ExprBinOp &>(*AST);
ASSERT_EQ(BinOp.lhs()->kind(), Node::NK_ExprVar);
ASSERT_EQ(Diags.size(), 0);
}

TEST(Parser, Op_PipeOperator_Backward) {
auto Src = R"(a <| b)"sv;

std::vector<Diagnostic> Diags;
Parser P(Src, Diags);
auto AST = P.parseExpr();

ASSERT_TRUE(AST);

ASSERT_EQ(AST->kind(), Node::NK_ExprBinOp);
ASSERT_EQ(Diags.size(), 0);
}

TEST(Parser, Op_PipeOperator_Forward_RightAssosiative) {
auto Src = R"(a <| b <| c)"sv;

std::vector<Diagnostic> Diags;
Parser P(Src, Diags);
auto AST = P.parseExpr();

ASSERT_TRUE(AST);

ASSERT_EQ(AST->kind(), Node::NK_ExprBinOp);

const auto &BinOp = static_cast<const ExprBinOp &>(*AST);
ASSERT_EQ(BinOp.lhs()->kind(), Node::NK_ExprBinOp);
ASSERT_EQ(BinOp.rhs()->kind(), Node::NK_ExprVar);
ASSERT_EQ(Diags.size(), 0);
}

TEST(Parser, Op_PipeOperator_NonAssociative) {
auto Src = R"(a <| b |> c)"sv;

std::vector<Diagnostic> Diags;
Parser P(Src, Diags);
auto AST = P.parseExpr();

ASSERT_TRUE(AST);

ASSERT_EQ(AST->kind(), Node::NK_ExprBinOp);

ASSERT_EQ(Diags.size(), 1);
ASSERT_EQ(Diags[0].kind(), nixf::Diagnostic::DK_OperatorNotAssociative);
}

} // namespace
2 changes: 1 addition & 1 deletion libnixf/test/Sema/ParentMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEST_F(ParentMapTest, Basic) {
PMA.runOnAST(*AST);

const Node *ID = AST->descend({{0, 0}, {0, 1}});
ASSERT_EQ(ID->kind(), Node::NK_Identifer);
ASSERT_EQ(ID->kind(), Node::NK_Identifier);

const Node *Var = PMA.upExpr(*ID);

Expand Down
2 changes: 1 addition & 1 deletion libnixf/test/Sema/VariableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ TEST_F(VLATest, ToDefLambda) {

ASSERT_TRUE(AST);
const Node *ID = AST->descend({{0, 1}, {0, 1}});
ASSERT_EQ(ID->kind(), Node::NK_Identifer);
ASSERT_EQ(ID->kind(), Node::NK_Identifier);

const auto *Def = VLA.toDef(*ID);
ASSERT_TRUE(Def);
Expand Down
10 changes: 10 additions & 0 deletions nixd/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,14 @@ In our option system, you need to specify which option set you'd like to use.
}
```

If you aren't a flakes user with standalone home-manager with a vanilla install then the following expression should make home-manager options appear:

```jsonc
{
"options": {
"home-manager": {
"expr": "(import <home-manager/modules> { configuration = ~/.config/home-manager/home.nix; pkgs = import <nixpkgs> {}; }).options"
}
}
}
```
4 changes: 3 additions & 1 deletion nixd/docs/editors/nvim-lsp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ let
'';

packages.myPlugins.start = with pkgs.vimPlugins; [
(nvim-treesitter.withPlugins (parsers: [ parsers.nix ]))
(nvim-treesitter.withPlugins (
parsers: builtins.attrValues { inherit (parsers) nix markdown markdown_inline; }
))
friendly-snippets
luasnip
nvim-cmp
Expand Down
2 changes: 1 addition & 1 deletion nixd/lib/Controller/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ nixd::Selector nixd::idioms::mkSelector(const nixf::ExprSelect &Sel,

std::pair<std::vector<std::string>, std::string>
nixd::getScopeAndPrefix(const Node &N, const ParentMapAnalysis &PM) {
if (N.kind() != Node::NK_Identifer)
if (N.kind() != Node::NK_Identifier)
return {};

// FIXME: impl scoped packages
Expand Down
4 changes: 2 additions & 2 deletions nixd/lspserver/include/lspserver/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum class JSONStreamStyle {
};

/// Parsed & classfied messages are dispatched to this handler class
/// LSP Servers should inherit from this hanlder and dispatch
/// LSP Servers should inherit from this handler and dispatch
/// notify/call/reply to implementations.
class MessageHandler {
public:
Expand Down Expand Up @@ -60,7 +60,7 @@ class InboundPort {
/// Dispatch messages to on{Notify,Call,Reply} ( \p Handlers)
/// Return values should be forwarded from \p Handlers
/// i.e. returns true to keep processing messages, or false to shut down.
bool dispatch(llvm::json::Value Message, MessageHandler &Hanlder);
bool dispatch(llvm::json::Value Message, MessageHandler &Handler);

void loop(MessageHandler &Handler);
};
Expand Down
2 changes: 1 addition & 1 deletion nixd/tools/nixd/test/hover/1.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ CHECK-NEXT: "jsonrpc": "2.0",
CHECK-NEXT: "result": {
CHECK-NEXT: "contents": {
CHECK-NEXT: "kind": "markdown",
CHECK-NEXT: "value": "`Identifer`"
CHECK-NEXT: "value": "`Identifier`"
CHECK-NEXT: },
CHECK-NEXT: "range": {
CHECK-NEXT: "end": {
Expand Down

0 comments on commit dbb0eb4

Please sign in to comment.