Created
September 16, 2023 03:21
-
-
Save inclyc/7242bcbf7d98d92ea8f3b5292c647756 to your computer and use it in GitHub Desktop.
The grammar of Nix language, official implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start: expr; | |
expr: expr_function; | |
expr_function | |
: identifier ':' expr_function | |
| '{' formals '}' ':' expr_function | |
| '{' formals '}' '@' identifier ':' expr_function | |
| ASSERT expr ';' expr_function | |
| WITH expr ';' expr_function | |
| LET binds IN expr_function | |
| expr_if | |
; | |
expr_if | |
: IF expr THEN expr ELSE expr { } | |
| expr_op | |
; | |
expr_op | |
: '!' expr_op %prec NOT | |
| '-' expr_op %prec NEGATE | |
| expr_op EQ expr_op | |
| expr_op NEQ expr_op | |
| expr_op '<' expr_op | |
| expr_op LEQ expr_op | |
| expr_op '>' expr_op | |
| expr_op GEQ expr_op | |
| expr_op AND expr_op | |
| expr_op OR expr_op | |
| expr_op IMPL expr_op | |
| expr_op UPDATE expr_op | |
| expr_op '?' attrpath | |
| expr_op '+' expr_op | |
| expr_op '-' expr_op | |
| expr_op '*' expr_op | |
| expr_op '/' expr_op | |
| expr_op CONCAT expr_op | |
| expr_app | |
; | |
expr_app | |
: expr_app expr_select | |
| expr_select | |
; | |
expr_select | |
: expr_simple '.' attrpath | |
| expr_simple '.' attrpath OR_KW expr_select | |
| expr_simple OR_KW | |
| expr_simple | |
; | |
expr_simple | |
: identifier | |
| INT | |
| FLOAT | |
| '"' string_parts '"' | |
| IND_STRING_OPEN ind_string_parts IND_STRING_CLOSE | |
| path_start PATH_END | |
| path_start string_parts_interpolated PATH_END | |
| SPATH | |
| URI | |
| '(' expr ')' | |
| LET '{' binds '}' | |
| REC '{' binds '}' | |
| '{' binds '}' | |
| '[' expr_list ']' | |
; | |
string_parts | |
: STR | |
| string_parts_interpolated | |
| | |
; | |
string_parts_interpolated | |
: string_parts_interpolated STR | |
| string_parts_interpolated DOLLAR_CURLY expr '}' | |
| DOLLAR_CURLY expr '}' | |
| STR DOLLAR_CURLY expr '}' | |
; | |
path_start | |
: PATH | |
| HPATH | |
; | |
ind_string_parts | |
: ind_string_parts IND_STR | |
| ind_string_parts DOLLAR_CURLY expr '}' | |
| | |
; | |
identifier | |
: ID | |
; | |
binds | |
: binds attrpath '=' expr ';' | |
| binds INHERIT attrs ';' | |
| binds INHERIT '(' expr ')' attrs ';' | |
| | |
; | |
attrs | |
: attrs attr | |
| attrs string_attr | |
| | |
; | |
attrpath | |
: attrpath '.' attr | |
| attrpath '.' string_attr | |
| attr | |
| string_attr | |
; | |
attr | |
: identifier | |
| OR_KW | |
; | |
string_attr | |
: '"' string_parts '"' | |
| DOLLAR_CURLY expr '}' | |
; | |
expr_list | |
: expr_list expr_select | |
| | |
; | |
formals | |
: formal ',' formals | |
| formal | |
| | |
| ELLIPSIS | |
; | |
formal | |
: identifier | |
| identifier '?' expr | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment