diff --git a/nixd/lib/Syntax/Parser/Parser.y b/nixd/lib/Syntax/Parser/Parser.y index e396d5195..45cf84856 100644 --- a/nixd/lib/Syntax/Parser/Parser.y +++ b/nixd/lib/Syntax/Parser/Parser.y @@ -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; @@ -56,7 +57,8 @@ %type ind_string; %type string_parts_interpolated %type string_parts_interp_expr -%type identifier attr +%type identifier attr identifier_or +%type var_or %type ind_string_parts %type formals %type formal @@ -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 @@ -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); @@ -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 diff --git a/nixd/tools/nixd-lint/test/identifier-or.nix b/nixd/tools/nixd-lint/test/identifier-or.nix new file mode 100644 index 000000000..06a53c40d --- /dev/null +++ b/nixd/tools/nixd-lint/test/identifier-or.nix @@ -0,0 +1,4 @@ +# RUN: nixd-lint %s | FileCheck %s + +# CHECK: keyword `or` used as an identifier +map or [ ]