2008-03-20 16:59:33 +02:00
|
|
|
%% Note: this SDF grammar is no longer used in the Nix expression
|
|
|
|
%% parser and may not be up to date.
|
|
|
|
|
2005-07-16 17:07:35 +03:00
|
|
|
definition
|
|
|
|
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
%% Top level syntax.
|
|
|
|
|
|
|
|
module Nix
|
|
|
|
imports Nix-Exprs Nix-Layout
|
|
|
|
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
%% Expressions.
|
|
|
|
|
|
|
|
module Nix-Exprs
|
|
|
|
imports Nix-Lexicals
|
|
|
|
exports
|
2005-07-17 02:19:20 +03:00
|
|
|
sorts Expr Formal Bind ExprList
|
2005-07-16 17:07:35 +03:00
|
|
|
context-free start-symbols Expr
|
|
|
|
context-free syntax
|
|
|
|
|
2006-09-11 16:05:15 +03:00
|
|
|
Id -> Expr {cons("Var")}
|
|
|
|
Int -> Expr {cons("Int")}
|
|
|
|
Str -> Expr {cons("Str")}
|
|
|
|
Uri -> Expr {cons("Uri")}
|
|
|
|
Path -> Expr {cons("Path")}
|
2005-07-16 17:07:35 +03:00
|
|
|
|
|
|
|
"(" Expr ")" -> Expr {bracket}
|
|
|
|
|
|
|
|
Expr Expr -> Expr {cons("Call"), left}
|
|
|
|
|
|
|
|
Id ":" Expr -> Expr {cons("Function1")}
|
|
|
|
"{" {Formal ","}* "}" ":" Expr -> Expr {cons("Function")}
|
|
|
|
Id -> Formal {cons("NoDefFormal")}
|
|
|
|
Id "?" Expr -> Formal {cons("DefFormal")}
|
|
|
|
|
|
|
|
"assert" Expr ";" Expr -> Expr {cons("Assert")}
|
|
|
|
|
|
|
|
"with" Expr ";" Expr -> Expr {cons("With")}
|
|
|
|
|
2005-07-17 02:19:20 +03:00
|
|
|
"rec" "{" Bind* "}" -> Expr {cons("Rec")}
|
|
|
|
"let" "{" Bind* "}" -> Expr {cons("LetRec")}
|
|
|
|
"{" Bind* "}" -> Expr {cons("Attrs")}
|
2005-07-16 17:07:35 +03:00
|
|
|
|
|
|
|
Id "=" Expr ";" -> Bind {cons("Bind")}
|
|
|
|
"inherit" ("(" Expr ")")? Id* ";" -> Bind {cons("Inherit")}
|
|
|
|
|
|
|
|
"[" ExprList "]" -> Expr {cons("List")}
|
2006-09-11 16:05:15 +03:00
|
|
|
-> ExprList {cons("ExprNil")}
|
2005-07-16 17:07:35 +03:00
|
|
|
Expr ExprList -> ExprList {cons("ExprCons")}
|
|
|
|
|
|
|
|
Expr "." Id -> Expr {cons("Select")}
|
|
|
|
|
|
|
|
"if" Expr "then" Expr "else" Expr -> Expr {cons("If")}
|
|
|
|
|
|
|
|
Expr "==" Expr -> Expr {cons("OpEq"), non-assoc}
|
|
|
|
Expr "!=" Expr -> Expr {cons("OpNEq"), non-assoc}
|
|
|
|
|
|
|
|
"!" Expr -> Expr {cons("OpNot")}
|
|
|
|
Expr "&&" Expr -> Expr {cons("OpAnd"), right}
|
|
|
|
Expr "||" Expr -> Expr {cons("OpOr"), right}
|
|
|
|
Expr "->" Expr -> Expr {cons("OpImpl"), right}
|
|
|
|
|
|
|
|
Expr "//" Expr -> Expr {cons("OpUpdate"), right}
|
|
|
|
Expr "~" Expr -> Expr {cons("SubPath"), non-assoc}
|
|
|
|
Expr "?" Id -> Expr {cons("OpHasAttr")}
|
|
|
|
Expr "+" Expr -> Expr {cons("OpPlus"), left}
|
2006-09-11 16:05:15 +03:00
|
|
|
Expr "++" Expr -> Expr {cons("OpConcat"), right}
|
2005-07-16 17:07:35 +03:00
|
|
|
|
|
|
|
context-free priorities
|
|
|
|
|
|
|
|
Expr "." Id -> Expr
|
|
|
|
> Expr ExprList -> ExprList
|
|
|
|
> Expr Expr -> Expr
|
|
|
|
> Expr "~" Expr -> Expr
|
|
|
|
> Expr "?" Id -> Expr
|
2006-09-11 16:05:15 +03:00
|
|
|
> Expr "++" Expr -> Expr
|
2005-07-16 17:07:35 +03:00
|
|
|
> Expr "+" Expr -> Expr
|
|
|
|
> "!" Expr -> Expr
|
|
|
|
> Expr "//" Expr -> Expr
|
2006-09-11 16:05:15 +03:00
|
|
|
> { Expr "==" Expr -> Expr
|
|
|
|
Expr "!=" Expr -> Expr
|
|
|
|
}
|
2005-07-16 17:07:35 +03:00
|
|
|
> Expr "&&" Expr -> Expr
|
|
|
|
> Expr "||" Expr -> Expr
|
|
|
|
> Expr "->" Expr -> Expr
|
2005-07-16 18:41:27 +03:00
|
|
|
> "if" Expr "then" Expr "else" Expr -> Expr
|
2005-07-16 17:07:35 +03:00
|
|
|
> "assert" Expr ";" Expr -> Expr
|
|
|
|
> "with" Expr ";" Expr -> Expr
|
|
|
|
> Id ":" Expr -> Expr
|
|
|
|
> "{" {Formal ","}* "}" ":" Expr -> Expr
|
|
|
|
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
%% Lexical syntax.
|
|
|
|
|
|
|
|
module Nix-Lexicals
|
|
|
|
exports
|
2005-07-17 00:38:15 +03:00
|
|
|
sorts Id Int Str Path Uri
|
2005-07-16 17:07:35 +03:00
|
|
|
lexical syntax
|
|
|
|
[a-zA-Z\_][a-zA-Z0-9\_\']* -> Id
|
2005-07-16 23:43:58 +03:00
|
|
|
"rec" | "let" | "if" | "then" | "else" | "assert" | "with" | "inherit" -> Id {reject}
|
2005-07-16 17:07:35 +03:00
|
|
|
|
|
|
|
[0-9]+ -> Int
|
|
|
|
|
|
|
|
"\"" ~[\n\"]* "\"" -> Str
|
|
|
|
|
2005-07-17 00:38:15 +03:00
|
|
|
[a-zA-Z0-9\.\_\-\+]* ("/"[a-zA-Z0-9\.\_\-\+]+)+ -> Path
|
2005-07-16 17:07:35 +03:00
|
|
|
|
2006-09-11 16:05:15 +03:00
|
|
|
[a-zA-Z] [a-zA-Z0-9\+\-\.]* ":" [a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\']+ -> Uri
|
2005-07-16 17:07:35 +03:00
|
|
|
|
|
|
|
lexical restrictions
|
|
|
|
Id -/- [a-zA-Z0-9\_\']
|
|
|
|
Int -/- [0-9]
|
|
|
|
Path -/- [a-zA-Z0-9\.\_\-\+\/]
|
|
|
|
Uri -/- [a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\']
|
2005-07-16 23:43:58 +03:00
|
|
|
"rec" "let" "if" "then" "else" "assert" "with" "inherit" -/- [A-Za-z0-9\_\']
|
2005-07-16 17:07:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
%% Layout.
|
|
|
|
|
|
|
|
module Nix-Layout
|
|
|
|
exports
|
|
|
|
sorts HashComment Asterisk Comment
|
|
|
|
lexical syntax
|
|
|
|
[\ \t\n] -> LAYOUT
|
|
|
|
HashComment -> LAYOUT
|
|
|
|
Comment -> LAYOUT
|
|
|
|
"#" ~[\n]* -> HashComment
|
|
|
|
"/*" ( ~[\*] | Asterisk )* "*/" -> Comment
|
2006-03-23 18:37:49 +02:00
|
|
|
[\*] ~[\/] -> Asterisk
|
2005-07-16 17:07:35 +03:00
|
|
|
lexical restrictions
|
|
|
|
HashComment -/- ~[\n]
|
|
|
|
context-free restrictions
|
2006-09-11 16:05:15 +03:00
|
|
|
LAYOUT? -/- [\ \t\n\#]
|
|
|
|
LAYOUT? -/- [\/].[\*]
|