Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nora Puchreiner
Nix
Commits
5d147e12
Commit
5d147e12
authored
11 years ago
by
Eelco Dolstra
Browse files
Options
Downloads
Patches
Plain Diff
Add a unary integer negation operator
This allows saying "-1" instead of "builtins.sub 0 1".
parent
159e621d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/libexpr/parser.y
+4
-2
4 additions, 2 deletions
src/libexpr/parser.y
tests/lang/eval-okay-arithmetic.exp
+1
-1
1 addition, 1 deletion
tests/lang/eval-okay-arithmetic.exp
tests/lang/eval-okay-arithmetic.nix
+6
-1
6 additions, 1 deletion
tests/lang/eval-okay-arithmetic.nix
with
11 additions
and
4 deletions
src/libexpr/parser.y
+
4
−
2
View file @
5d147e12
...
@@ -270,11 +270,12 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
...
@@ -270,11 +270,12 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
%left AND
%left AND
%nonassoc EQ NEQ
%nonassoc EQ NEQ
%right UPDATE
%right UPDATE
%left N
EG
%left N
OT
%left '+'
%left '+'
%right CONCAT
%right CONCAT
%nonassoc '?'
%nonassoc '?'
%nonassoc '~'
%nonassoc '~'
%nonassoc NEGATE
%%
%%
...
@@ -306,7 +307,8 @@ expr_if
...
@@ -306,7 +307,8 @@ expr_if
;
;
expr_op
expr_op
: '!' expr_op %prec NEG { $$ = new ExprOpNot($2); }
: '!' expr_op %prec NOT { $$ = new ExprOpNot($2); }
| '-' expr_op %prec NEGATE { $$ = new ExprApp(new ExprApp(new ExprVar(data->symbols.create("__sub")), new ExprInt(0)), $2); }
| expr_op EQ expr_op { $$ = new ExprOpEq($1, $3); }
| expr_op EQ expr_op { $$ = new ExprOpEq($1, $3); }
| expr_op NEQ expr_op { $$ = new ExprOpNEq($1, $3); }
| expr_op NEQ expr_op { $$ = new ExprOpNEq($1, $3); }
| expr_op AND expr_op { $$ = new ExprOpAnd($1, $3); }
| expr_op AND expr_op { $$ = new ExprOpAnd($1, $3); }
...
...
This diff is collapsed.
Click to expand it.
tests/lang/eval-okay-arithmetic.exp
+
1
−
1
View file @
5d147e12
18
5
4
184
3
This diff is collapsed.
Click to expand it.
tests/lang/eval-okay-arithmetic.nix
+
6
−
1
View file @
5d147e12
...
@@ -16,6 +16,11 @@ let {
...
@@ -16,6 +16,11 @@ let {
range = range_ [];
range = range_ [];
*/
*/
body
=
sum
(
range
1
50
)
+
123
+
456
;
x
=
12
;
body
=
sum
[
(
sum
(
range
1
50
))
(
123
+
456
)
(
0
+
-
10
+
-
(
-
11
)
+
-
x
)
];
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment