StardustPL / Stardust

"A programming language that doesn't make me angry to use it."
https://StardustPL.GitHub.IO/
The Unlicense
4 stars 0 forks source link

Planning: Syntax #1

Open LB-- opened 9 years ago

LB-- commented 9 years ago

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.

// single-line comment
code code code // single-line comment

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.

/* in-line comment */
code /* in-line comment */ code

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.

code code
#
multi-line comment
#
code code

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.

#/
code code
#
code code code
#
code
#/

In the above example, code code and code are commented out, and code code code is not commented out.

/#/
code code
#
code code code
#
code
#/

In the above example, code code code is commented out, and code code and code 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.

Scope resolution operator. May be overridden.

Scope resolution operator. May not be overridden.

Access operator without side-effects. May be overridden.

Access operator without side-effects. May not be overridden.

Ellipses operator. May not be overridden. Special syntax rules apply.

,

Parameter separation operator. May not be overridden.

Access operator with side-effects. May be overridden.

Access operator with side effects. May not be overridden.

Parameter list encapsulation operators. May be overridden via ().

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.

Operator compound-assignment operator.

Addition/concatenation/union.

Subtraction/signed-difference/signed-intersection.

Multiplication/product/repeated-addition.

Power/exponentiation

Division/quotient.

Modulus/remainder-of-division/percent.

Equality test.

Equivalent to ~ ==.

<

Less-than test.

Equivalent to < || ==.

>

Equivalent to ~ <=.

>=

Equivalent to ~ <.

&

Logical/bitwise and.

Logical/bitwise or.

Logical exclusive-or, or numeric power/exponentiation (alias of **).

Logical/bitwise not.

Operator inversion operator.

Logical/bitwise inclusive-or.

^|

Logical/bitwise exclusive-or.

&&

Operator and operator.

||

Operator or operator.

LB-- commented 9 years ago
LB-- commented 8 years ago

Actually, I don't want to use # for comments - forget all that nonsense above. # will be used for other purposes.

LB-- commented 7 years ago

https://eev.ee/blog/2016/12/01/lets-stop-copying-c/