Open LB-- opened 9 years ago
expression
- evaluated at compile time or runtime (whenever convenient/possible)[expression]
- evaluated at compile time{expression}
- evaluated at runtimeActually, I don't want to use #
for comments - forget all that nonsense above. #
will be used for other purposes.
Spacing and Indentation
Only tabs
\t
will be allowed for primary indentation. Lines starting with one or more spaces are not allowed. After primary indentation, tabs are no longer allowed. Primary indentation ends at the first non-tab character. The number of tabs of primary indentation on a line must match the previous line, be one deeper than the previous line, or be less than the previous line.After primary indentation, optional secondary indentation is allowed in the form of one or more spaces. If a line contains secondary indentation, the previous line must have either no secondary indentation or else identical secondary indentation.
Newline characters
Only
\n
is a line delimiter -\r
has no meaning and may only occur next to\n
.\r
is illegal in all other cases. The newline character\n
is not considered part of the line or part of the code and only serves to delimit lines of code. It cannot be escaped.A line starts after primary and/or secondary indentation. Indentation is not considered part of the line and only serves to indicate the depth of the line. Thus, it is guaranteed that a line never starts with one or more tabs and/or spaces.
Comments
There are a variety of comment types supported.
Single-line
Traditional C/C++/Java-style single-line comments are supported by two forward slashes
//
anywhere on a line. Before this point all spacing and indentation rules still apply. Unlike C-style single-line comments however, they cannot be extended to the next line by ending with a backslash\
- they only ever comment the rest of the line. Single-line comments at the start of the line must be preceded by appropriate primary and/or secondary indentation. Single-line comments anywhere else on a line must be preceded by one or more spaces, and must be followed by one or more spaces.Nesting is supported as a side-effect.
In-line
In-line comments are supported via
/*
to begin the comment and*/
to end the comment./*
must be preceded by either primary and/or secondary indentation if at the start of a line or otherwise must be preceded by one or more spaces anywhere else in the line, and must be followed by one or more spaces.*/
must have a space after it unless at the end of the line, but must always be preceeded by one or more spaces. Both/*
and*/
must occur on the same line - they do not represent multi-line comments.Nesting is supported by design.
Multi-line
Multi-line comments are represented by two single hash symbols
#
on lines by themselves. They must be at the start of the line after primary and/or secondary indentation and must be the last character on the line. A#
only matches another#
at the same level of indentation, so nesting is supported via increased indentation. Indentation may not decrease within a multi-line comment - all indentation rules still apply within a multi-line comment.Nesting is supported as described.
Multi-line-toggle
Multi-line-toggle comments are represented by a pair of
#/
on lines by themselves. They follow the same rules as multi-line comments and may be the begin or end of a multi-line comment, but they allow for regular multi-line comment indicators#
to occur between pairs of#/
to toggle between comment and code. A begin#/
may be preceded by a slash to create/#/
which will inverse the toggling of commented and uncommented code.In the above example,
code code
andcode
are commented out, andcode code code
is not commented out.In the above example,
code code code
is commented out, andcode code
andcode
are not commented out.Nesting is supported as with multi-line comments.
Tokens
Tokens are the parts of a line delimited by one or more spaces. The above definitions already comply with tokenizing. In special circumstances, tokens may also be delimited by
;
,:
,::
,.
,..
,...
,,
,->
,-->
,(
, and)
.Operators
Operators may consist of any characters, except they must not start or end with
;
,:
,::
,.
,..
,...
,,
,->
,-->
,(
,)
, or()
, as these are reserved for the special operators. All non-special operators must be surrounded by one or more spaces on each side.Special
Special operators have special rules regarding usage and identification.
;
Expression separation operator. May not be overridden.
a;
- result is voida; b
- result is b:
Scope resolution operator. May be overridden.
:b
- result is b from global scopea:b
- result is b from a::
Scope resolution operator. May not be overridden.
::b
- result is b from global scopea::b
- result is b from a.
Access operator without side-effects. May be overridden.
.
- result is nearest enclosing class instance.b
- result is b from nearest enclosing class instancea.b
- result is b from a..
Access operator without side-effects. May not be overridden.
..
- result is nearest enclosing class instance..b
- result is b from nearest enclosing class instancea..b
- result is b from a...
Ellipses operator. May not be overridden. Special syntax rules apply.
,
Parameter separation operator. May not be overridden.
,
- result is void and voida,
- result is a and void, b
- result is void and ba, b
- result is a and ba, b, c, ...
- result is a and b and c, etc.->
Access operator with side-effects. May be overridden.
->
- result is nearest enclosing class instance->b
- result is b from nearest enclosing class instancea->b
- result is b from a-->
Access operator with side effects. May not be overridden.
-->
- result is nearest enclosing class instance-->b
- result is b from nearest enclosing class instancea-->b
- result is b from a(
,)
,()
Parameter list encapsulation operators. May be overridden via
()
.()
result contains void(a)
result contains a (e.g. comma-separated parameters via,
)Predefined
There are predefined operators which follow normal operator rules and are treated as though they are user-defined. All predefined operators may be overridden.
:=
Value assignment.
a := b
- typically copies the value of b over a=
Operator compound-assignment operator.
a (op =) b
- typically equivalent toa := (a op b)
+
Addition/concatenation/union.
+ b
- result is typically ba + b
- result is typically sum/concatenation/union of a and b-
Subtraction/signed-difference/signed-intersection.
- b
- result is typically the opposite/inverse of b, or akin tob * -1
a - b
- result is typically signed-difference/signed-intersection of a and b*
Multiplication/product/repeated-addition.
a * b
- result is typically a added b times**
Power/exponentiation
a ** b
- result is typically a multiplied by a, b times/
Division/quotient.
a / b
- result is typically a divided by b%
Modulus/remainder-of-division/percent.
a %
- result is typicallya / 100.0
% b
- result is typicallyb * 100.0
a % b
- result is typically a modulo b or remainder of division of a by b==
Equality test.
a == b
- true if a and b are indistinguishable!=
Equivalent to
~ ==
.<
Less-than test.
a < b
- true if a would occur before b in natural sort order<=
Equivalent to
< || ==
.>
Equivalent to
~ <=
.>=
Equivalent to
~ <
.&
Logical/bitwise and.
a & b
- for numeric types, typically performs a bitwise-and operationa & b
- for boolean types, typically performs short-circuit logical-and|
Logical/bitwise or.
a | b
- for numeric types, typically performs a bitwise-or operationa | b
- for boolean types, typically performs short-circuit logical-or^
Logical exclusive-or, or numeric power/exponentiation (alias of
**
).a ^ b
- for numeric types, typically equivalent toa ** b
a ^ b
- for boolean types, typically performs logical exclusive-or!
Logical/bitwise not.
! a
- for numeric types, typically performs bitwise-not! a
- for boolean types, typically performs logical-not~
Operator inversion operator.
a (~ op) b
- typically equivalent to!(a op b)
&|
Logical/bitwise inclusive-or.
^|
Logical/bitwise exclusive-or.
&&
Operator and operator.
||
Operator or operator.