* Use `sdftable -s' to get warnings about the grammar.

* Several bug fixes in the grammar.
* Allow one-line comments (#... and //...) to end in EOF.
This commit is contained in:
Eelco Dolstra 2003-11-19 10:04:03 +00:00
parent 38946e1378
commit 2be8b5917a
3 changed files with 20 additions and 14 deletions

View file

@ -17,6 +17,6 @@ parse-table.h: nix.tbl
../bin2c/bin2c nixParseTable < $< > $@ || (rm $@ && exit 1) ../bin2c/bin2c nixParseTable < $< > $@ || (rm $@ && exit 1)
%.tbl: %.sdf %.tbl: %.sdf
../../externals/inst/bin/sdf2table -i $< -o $@ ../../externals/inst/bin/sdf2table -s -i $< -o $@
CLEANFILES = parse-table.h nix.tbl CLEANFILES = parse-table.h nix.tbl

View file

@ -17,7 +17,7 @@ imports Fix-Exprs Fix-Layout
module Fix-Exprs module Fix-Exprs
imports Fix-Lexicals URI imports Fix-Lexicals URI
exports exports
sorts Expr Bind Formal sorts Expr Formal Bind Binds BindSemi ExprList
context-free syntax context-free syntax
Id -> Expr {cons("Var")} Id -> Expr {cons("Var")}
@ -34,11 +34,11 @@ exports
Expr Expr -> Expr {cons("Call"), left} Expr Expr -> Expr {cons("Call"), left}
"{" {Formal ","}* "}" ":" Expr -> Expr {cons("Function"), right} "{" {Formal ","}* "}" ":" Expr -> Expr {cons("Function")}
Id -> Formal {cons("NoDefFormal")} Id -> Formal {cons("NoDefFormal")}
Id "?" Expr -> Formal {cons("DefFormal")} Id "?" Expr -> Formal {cons("DefFormal")}
"assert" Expr ";" Expr -> Expr {cons("Assert"), right} "assert" Expr ";" Expr -> Expr {cons("Assert")}
"rec" "{" Binds "}" -> Expr {cons("Rec")} "rec" "{" Binds "}" -> Expr {cons("Rec")}
"let" "{" Binds "}" -> Expr {cons("LetRec")} "let" "{" Binds "}" -> Expr {cons("LetRec")}
@ -87,7 +87,7 @@ exports
module Fix-Lexicals module Fix-Lexicals
exports exports
sorts Id Path sorts Id Int Str Path PathComp Bool
lexical syntax lexical syntax
[a-zA-Z\_][a-zA-Z0-9\_\']* -> Id [a-zA-Z\_][a-zA-Z0-9\_\']* -> Id
"rec" -> Id {reject} "rec" -> Id {reject}
@ -120,12 +120,17 @@ exports
module URI module URI
exports exports
sorts Uri sorts Uri Uhierpart Uopaquepart Uuricnoslash Unetpath Uabspath
Urelpath Urelsegment Uscheme Uauthority Uregname Userver
Uuserinfo Uhostport Uhost Uhostname Udomainlabel Utoplabel
UIPv4address Uport Upath Upathsegments Usegment Uparam
Upchar Uquery Ufragment Uuric Ureserved Uunreserved Umark
Uescaped Uhex Ualphanum Ualpha Ulowalpha Uupalpha Udigit
lexical syntax lexical syntax
Uscheme ":" (Uhierpath | Uopaquepath) -> Uri Uscheme ":" (Uhierpart | Uopaquepart) -> Uri
(Unetpath | Uabspath) ("?" Uquery)? -> Uhierpath (Unetpath | Uabspath) ("?" Uquery)? -> Uhierpart
Uuricnoslash Uuric* -> Uopaquepath Uuricnoslash Uuric* -> Uopaquepart
Uunreserved | Uescaped | [\;\?\:\@\&\=\+\$\,] -> Uuricnoslash Uunreserved | Uescaped | [\;\?\:\@\&\=\+\$\,] -> Uuricnoslash
@ -187,17 +192,18 @@ exports
module Fix-Layout module Fix-Layout
exports exports
sorts HashComment Asterisk Comment EOF
lexical syntax lexical syntax
[\ \t\n] -> LAYOUT [\ \t\n] -> LAYOUT
HashComment -> LAYOUT HashComment -> LAYOUT
Comment -> LAYOUT Comment -> LAYOUT
"#" ~[\n]* [\n] -> HashComment "#" ~[\n]* ([\n] | EOF) -> HashComment
"//" ~[\n]* [\n] -> HashComment "//" ~[\n]* ([\n] | EOF) -> HashComment
"/*" ( ~[\*] | Asterisk )* "*/" -> Comment "/*" ( ~[\*] | Asterisk )* "*/" -> Comment
[\*] -> Asterisk [\*] -> Asterisk
"" -> EOF
lexical restrictions lexical restrictions
Asterisk -/- [\/] Asterisk -/- [\/]
EOF -/- ~[]
context-free restrictions context-free restrictions
LAYOUT? -/- [\ \t\n] | [\#] LAYOUT? -/- [\ \t\n] | [\#]
syntax
HashComment <START> -> <START>

View file

@ -154,7 +154,7 @@ Expr parseExprFromFile(Path path)
if (!imploded) if (!imploded)
throw Error(format("cannot implode parse tree")); throw Error(format("cannot implode parse tree"));
debug(format("imploded parse tree of `%1%': %2%") printMsg(lvlVomit, format("imploded parse tree of `%1%': %2%")
% path % imploded); % path % imploded);
/* Finally, clean it up. */ /* Finally, clean it up. */