on master help sign in
Tweak syntax rules to deal with consecutive non-terminals better
commit422521fe00537e6c7c202243826d1da674061730 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateWed 27 Feb 2013, 16:19 (14 years ago) parent195e30b
3 files changed+14−10
src/Idris/Parser.hs+3−2 test/test013/test013.idr+2−2 tutorial/syntax.tex+9−6
src/Idris/Parser.hs+3−2
@@ -401,12 +401,13 @@ pSyntaxRule syn
401401 name _ = Nothing
402402
403403 -- Can't parse two full expressions (i.e. expressions with application) in a row
404− -- so change the first to a simple expression
404+ -- so change them both to a simple expression
405405
406406 mkSimple (Expr e : es) = SimpleExpr e : mkSimple' es
407407 mkSimple xs = mkSimple' xs
408408
409− mkSimple' (Expr e : Expr e1 : es) = SimpleExpr e : mkSimple' (Expr e1 : es)
409+ mkSimple' (Expr e : Expr e1 : es) = SimpleExpr e : SimpleExpr e1 :
410+ mkSimple es
410411 mkSimple' (e : es) = e : mkSimple' es
411412 mkSimple' [] = []
412413
test/test013/test013.idr+2−2
@@ -5,11 +5,11 @@ forLoop [] f = return ()
55forLoop (x :: xs) f = do f x
66 forLoop xs f
77
8−syntax for {x} "in" [xs] [body] = forLoop xs (\x => body)
8+syntax for {x} "in" [xs] ":" [body] = forLoop xs (\x => body)
99
1010main : IO ()
1111main = do putStrLn "Counting:"
12− for x in [1..10] do
12+ for x in [1..10]:
1313 putStrLn $ "Number " ++ show x
1414 putStrLn "Done!"
1515
tutorial/syntax.tex+9−6
@@ -48,10 +48,13 @@ also be used to include reserved words in syntax rules, such as \texttt{"let"} o
4848\end{itemize}
4949
5050\noindent
51−The limitations on the form of a syntax rule are that it must include at least one
52−symbol or keyword, and there must be no repeated variables standing for non-terminals.
53−Rules can use previously defined rules, but may not be recursive.
54−The following syntax extensions would therefore be valid:
51+The limitations on the form of a syntax rule are that it must include at least
52+one symbol or keyword, and there must be no repeated variables standing for
53+non-terminals. Any expression can be used, but if there are two non-terminals
54+in a row in a rule, only simple expressions may be used (that is, variables,
55+constants, or bracketed expressions). Rules can use previously defined rules,
56+but may not be recursive. The following syntax extensions would therefore be
57+valid:
5558
5659\begin{SaveVerbatim}{syntaxex}
5760
@@ -100,10 +103,10 @@ exampe, a \texttt{for} loop binds a variable on each iteration:
100103
101104\begin{SaveVerbatim}{forloop}
102105
103−syntax for {x} "in" [xs] [body] = forLoop xs (\x => body)
106+syntax for {x} "in" [xs] ":" [body] = forLoop xs (\x => body)
104107
105108main : IO ()
106−main = do for x in [1..10] do
109+main = do for x in [1..10]:
107110 putStrLn ("Number " ++ show x)
108111 putStrLn "Done!"
109112