Skip to content

Syntax matters #29

@AndreVanDelft

Description

@AndreVanDelft

I would like to see that the following syntactic rules related to Scala value expressions will all effective in the preprocessor. I am not sure to what extend they are already.

The goal is to support a lot of syntax, so that the user rarely needs to write parentheses.
E.g. while b and while !b should be allowed.
But there are several different kind of SubScript expressions where Scala values may occur.
Each kind may have its own restrictions on the Scala value expression syntax, in order not to have ambiguities withe the SubScript syntax.

There will be ambiguities anyway, mainly with [brackets], For those the solving rule should be that in if there is no white space before the opening bracket, then it belongs to the Scala value expression, else it is an bracketed script expression.

if expression

The if expression may be any Scala expression. The end is discoverable because of the mandatory then keyword.

while expression

The while expression may be a Scala expression that does not contain binary operators and infix method calls. As inversion prefix operators are allowed, we call this a ScalaSimplePrefixExpression.

colon-call parameters

A 'colon-call' is a script call of the form scriptName: param1, param2, param3.
Here the parameters may also be a ScalaSimplePrefixExpression

postfix tests

A parameter postfix test such as in key: ?c ?if !c.isUpper may also have a ScalaSimplePrefixExpression

annotations

Probably ScalaSimplePrefixExpression applies to @annotation:

script expression value terms

Script expression terms that are meant to denote a Scala expression, the
ScalaSimplePrefixExpression is almost sufficient. However, they should not start with an inversion prefix operator such as ~, !, -, because those are also prefixes for script expressions.
So we name this restricted kind of value a ScalaSimpleExpression

script expression value terms starting with ^

If there is a prefix caret then subsequent inversion prefix operators cannot do harm.
Hence ScalaSimplePrefixExpression again.

Examples of ScalaSimpleExpression

literals such as: null, true, 1, 1.0, 'a', "a", s"a", `a`, 'a
(anyScalaExpresion)
{anyScalaStatementSequence}
p
p.q
p(r)
p.q(r)
p.q[T](r,s)

Handling script expression value terms

Script expression value terms are handled according to their type:

  • Unit: method call, in a tiny code fragment
  • Script[T] for some T: script call. Q: Does this really work so nicely for all script calls?
  • some other type T: there must be an implicit conversion to Script[U] for some U; a script call results

Open issues

The colon-call syntax applies for script calls and method calls.
In script calls there are question marks allowed preceding parameters; and
even postfix tests for the parameters. We could also allow this extended parameter
syntax for method calls; it would be useful in libraries such as swing.Scripts.
Maybe they are already allowed there, I don't know.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions