summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md24
-rw-r--r--src/Parser/Expr.hs20
-rw-r--r--src/Parser/Statement.hs2
3 files changed, 17 insertions, 29 deletions
diff --git a/README.md b/README.md
index 2294396..afb4338 100644
--- a/README.md
+++ b/README.md
@@ -325,20 +325,15 @@ parameter passed without a keyword. This is done in order to avoid the need to
remember parameter order and to make the behavior of each call as clear as
possible, even without looking up the documentation.
-To make the syntax unambiguous, the keywordless parameter can be passed as the
-last parameter, as a literal (number, string, etc.), or using parentheses. So this is ok:
+To make the syntax unambiguous, the keywordless parameter can be passed as
+a literal (number, string, etc.), or using parentheses. So this is ok:
```
expect /something/ from p
```
-but if the regular expression is stored in a variable, the parameter needs to move to the end:
-```
-let re = /something/
-expect from p re
-```
-
-or be enclosed in parentheses:
+but if the regular expression is stored in a variable, the parameter needs to
+be enclosed in parentheses:
```
expect (re) from p
```
@@ -352,12 +347,12 @@ expect /$re/ from p
Custom functions can be defined on the top level using `def` keyword, and with
the parameters either followed by `=` sign to return a value:
```
-def twice x = 2 * x
+def quadruple of x = 4 * x
```
or followed by `:` to define test block:
```
-def greet p:
+def say_hello to p:
send "hello" to p
expect /hi/ from p
```
@@ -366,9 +361,14 @@ Those then can be invoked elsewhere:
```
test:
spawn as p
- greet p
+ say_hello to p
```
+When defining a function, the unnamed parameter, if any, must be enclosed in
+parentheses:
+```
+def twice (x) = 2 * x
+```
Optional dependencies
diff --git a/src/Parser/Expr.hs b/src/Parser/Expr.hs
index 5ff3f15..d8d96eb 100644
--- a/src/Parser/Expr.hs
+++ b/src/Parser/Expr.hs
@@ -415,22 +415,10 @@ functionArguments check param lit promote = do
[ T.pack "multiple unnamed parameters" ]
parseArgs False
- ,do off <- stateOffset <$> getParserState
- x <- identifier
- choice
- [do off' <- stateOffset <$> getParserState
- y <- pparam <|> (promote off' =<< identifier)
- checkAndInsert off' (Just (ArgumentKeyword x)) y $ parseArgs allowUnnamed
-
- ,if allowUnnamed
- then do
- y <- promote off x
- checkAndInsert off Nothing y $ return M.empty
- else do
- registerParseError $ FancyError off $ S.singleton $ ErrorFail $ T.unpack $ T.concat
- [ T.pack "multiple unnamed parameters" ]
- return M.empty
- ]
+ ,do x <- identifier
+ off <- stateOffset <$> getParserState
+ y <- pparam <|> (promote off =<< identifier)
+ checkAndInsert off (Just (ArgumentKeyword x)) y $ parseArgs allowUnnamed
,do return M.empty
]
diff --git a/src/Parser/Statement.hs b/src/Parser/Statement.hs
index 4bed1ef..7765b12 100644
--- a/src/Parser/Statement.hs
+++ b/src/Parser/Statement.hs
@@ -129,7 +129,7 @@ instance ExprType a => ParamType (TypedVarName a) where
instance ExprType a => ParamType (Expr a) where
parseParam _ = do
off <- stateOffset <$> getParserState
- SomeExpr e <- literal <|> variable <|> between (symbol "(") (symbol ")") someExpr
+ SomeExpr e <- literal <|> between (symbol "(") (symbol ")") someExpr
unifyExpr off Proxy e
showParamType _ = "<" ++ T.unpack (textExprType @a Proxy) ++ ">"