The PJS library can be required via:
The syntax of PJS is as follows:
|decl||=||(function id (id ...) source-elt ...)|
||||(var var-init ...+)|
||||(if expr stmt)|
||||(if expr stmt stmt)|
||||(do stmt expr)|
||||(while expr stmt)|
||||(for (var var-init ...+) expr expr stmt)|
||||(for expr expr expr stmt)|
||||(for (var id) in expr stmt)|
||||(for id in expr stmt)|
||||(with expr stmt)|
||||(switch expr case-clause ...)|
||||(label id stmt)|
||||(try stmt catch-clause finally-clause)|
||||(try stmt catch-clause)|
||||(try stmt finally-clause)|
|block-stmt||=||(block source-elt ...)|
||||(regexp string boolean boolean)|
||||(array array-elt ...)|
||||(object [id expr] ...)|
||||(field-ref expr expr)|
||||(field expr id)|
||||(new expr expr ...)|
||||(prefix prefix-op expr)|
||||(postfix expr postfix-op)|
||||(infix-op expr expr expr ...)|
||||(assign-op expr expr)|
||||(if expr expr expr)|
||||(function id (id ...) source-elt ...)|
||||(function (id ...) source-elt ...)|
||||(begin expr ...+)|
|case-clause||=||(default stmt ...)|
||||(case expr stmt ...)|
|catch-clause||=||(catch id stmt)|
The set of recognized operators is:
prefix-op : ++, --, +, -, ~, !
infix-op : *, /, %, +, -, <, <<, >, >>, >>>, <=, >=, ==, !=, ===, !==, &, ^, \|, &&, \|\|
postfix-op : ++, --
assign-op : =, *=, /=, %=, +=, -=, <<=, >>=, >>>=, &=, ^=, \|=
or = \|\|
and = &&
bitwise-and = &
bitwise-ior = \|
bitwise-not = ~
bitwise-xor = ^
The grammar as presented contains several ambiguities.
(function (array) (return (array 1 2 3)))
the inner occurrence of array is parsed as a variable reference rather than an array constructor.
Operators may be disambiguated with the use of the special form #%keyword. For example, (#%keyword . array) unconditionally refers to the initial binding of array, regardless of the current environment. The above example can then be rewritten as
(function (array) (return ((#%keyword . array) 1 2 3)))
Expression statements introduce a few minor ambiguities into the PJS syntax. These include function declarations vs. named function expressions and if statements vs. if expressions. These are always resolved in favor of the declaration or statement form rather than the expression form, since in both cases the expression form is less likely to occur.
The expression form operator #%expression forces its argument to be parsed as an expression. For example, the expression (#%expression (if x y z)) is parsed as a conditional expression rather than a conditional statement.
The PJS syntax provides several additional syntactic conveniences.
Similar to the Java Dot Notation originally introduced by JScheme, PJS permits the use of dotted identifiers as a short-hand for the obvious corresponding chains of object field references. Unlike in JScheme, it is impossible to bind a variable with a dot in its name, so dotted identifiers are always unambiguously decoded as field references.
For example, the identifier document.body.innerHTML is equivalent to the expression (field (field document body) innerHTML).
The PJS library provides procedures that operate on either syntax objects or S-expressions. The syntax object procedures maintain source location information.
stx : syntax?
stx : syntax?
stx : syntax?
(expression->syntax expr) → syntax?
expr : Expression?
(statement->syntax stmt) → syntax?
stmt : Statement?
(source-element->syntax elt) → syntax?
elt : SourceElement?
elts : (listof SourceElement?)