Skip to content

Commit

Permalink
nixd/Parser: add identifier_or rules & diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Sep 18, 2023
1 parent d108ee5 commit f259e6f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
36 changes: 27 additions & 9 deletions nixd/lib/Syntax/Parser/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
nixd::syntax::InheritedAttribute *IA;
nixd::syntax::ListBody *LB;
nixd::syntax::IndString *IndString;
nixd::syntax::Variable *Variable;

// Tokens
nixd::syntax::StringToken STR;
Expand All @@ -56,7 +57,8 @@
%type <IndString> ind_string;
%type <ConcatStrings> string_parts_interpolated
%type <InterpExpr> string_parts_interp_expr
%type <Identifier> identifier attr
%type <Identifier> identifier attr identifier_or
%type <Variable> var_or
%type <IndStringParts> ind_string_parts
%type <Formals> formals
%type <Formal> formal
Expand Down Expand Up @@ -221,8 +223,11 @@ expr_select
N->Default = $5;
$$ = N;
}
| expr_simple OR_KW {
// TODO
| expr_simple var_or {
auto N = decorateNode(new Call, *yylocp, *Data);
N->Fn = $1;
N->Args = {$2};
$$ = N;
}
| expr_simple

Expand Down Expand Up @@ -385,6 +390,23 @@ uri
$$->S = std::string($1);
}

identifier_or
: OR_KW {
$$ = decorateNode(new Identifier, *yylocp, *Data);
$$->Symbol = Data->State.Symbols.create("or");

Diagnostic Diag;
Diag.Msg = "keyword `or` used as an identifier";
Diag.Kind = Diagnostic::Warning;
Diag.Range = $$->Range;
Data->Diags.emplace_back(std::move(Diag));
}

var_or: identifier_or {
$$ = decorateNode(new Variable, *yylocp, *Data);
$$->ID = $1;
}

identifier
: ID {
$$ = decorateNode(new Identifier, *yylocp, *Data);
Expand Down Expand Up @@ -459,12 +481,8 @@ attrpath


attr
: identifier { $$ = $1; }
| OR_KW {
auto Or = Data->State.Symbols.create("or");
$$ = decorateNode(new Identifier, *yylocp, *Data);
$$->Symbol = Or;
}
: identifier
| identifier_or



Expand Down
4 changes: 4 additions & 0 deletions nixd/tools/nixd-lint/test/identifier-or.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# RUN: nixd-lint %s | FileCheck %s

# CHECK: keyword `or` used as an identifier
map or [ ]

0 comments on commit f259e6f

Please sign in to comment.