on master help sign in
Tweak syntax rules to deal with consecutive non-terminals better
422521fEdwin Brady
src/Idris/Parser.hs+3−2
@@ -401,12 +401,13 @@ pSyntaxRule syn
401 name _ = Nothing
401 name _ = Nothing
402
402
403 -- Can't parse two full expressions (i.e. expressions with application) in a row
403 -- 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
405
405
406 mkSimple (Expr e : es) = SimpleExpr e : mkSimple' es
406 mkSimple (Expr e : es) = SimpleExpr e : mkSimple' es
407 mkSimple xs = mkSimple' xs
407 mkSimple xs = mkSimple' xs
408
408
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
410 mkSimple' (e : es) = e : mkSimple' es
411 mkSimple' (e : es) = e : mkSimple' es
411 mkSimple' [] = []
412 mkSimple' [] = []
412
413
test/test013/test013.idr+2−2
@@ -5,11 +5,11 @@ forLoop [] f = return ()
5forLoop (x :: xs) f = do f x
5forLoop (x :: xs) f = do f x
6 forLoop xs f
6 forLoop xs f
7
7
8−syntax for {x} "in" [xs] [body] = forLoop xs (\x => body)
8+syntax for {x} "in" [xs] ":" [body] = forLoop xs (\x => body)
9
9
10main : IO ()
10main : IO ()
11main = do putStrLn "Counting:"
11main = do putStrLn "Counting:"
12− for x in [1..10] do
12+ for x in [1..10]:
13 putStrLn $ "Number " ++ show x
13 putStrLn $ "Number " ++ show x
14 putStrLn "Done!"
14 putStrLn "Done!"
15
15
tutorial/syntax.tex+9−6
@@ -48,10 +48,13 @@ also be used to include reserved words in syntax rules, such as \texttt{"let"} o
48\end{itemize}
48\end{itemize}
49
49
50\noindent
50\noindent
51−The limitations on the form of a syntax rule are that it must include at least one
51+The limitations on the form of a syntax rule are that it must include at least
52−symbol or keyword, and there must be no repeated variables standing for non-terminals.
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,
53−Rules can use previously defined rules, but may not be recursive.
55+constants, or bracketed expressions). Rules can use previously defined rules,
54−The following syntax extensions would therefore be valid:
56+but may not be recursive. The following syntax extensions would therefore be
57+valid:
55
58
56\begin{SaveVerbatim}{syntaxex}
59\begin{SaveVerbatim}{syntaxex}
57
60
@@ -100,10 +103,10 @@ exampe, a \texttt{for} loop binds a variable on each iteration:
100
103
101\begin{SaveVerbatim}{forloop}
104\begin{SaveVerbatim}{forloop}
102
105
103−syntax for {x} "in" [xs] [body] = forLoop xs (\x => body)
106+syntax for {x} "in" [xs] ":" [body] = forLoop xs (\x => body)
104
107
105main : IO ()
108main : IO ()
106−main = do for x in [1..10] do
109+main = do for x in [1..10]:
107 putStrLn ("Number " ++ show x)
110 putStrLn ("Number " ++ show x)
108 putStrLn "Done!"
111 putStrLn "Done!"
109
112