-
Notifications
You must be signed in to change notification settings - Fork 1
LangSpecs
Flatscript allows single-line comments whose content follows a #
mark and ends at the line feed.
For example
# this comment possess a whole line
foo: bar + baz # this comment starts after a statement
No multi-line comment supported.
Flatscript uses indentation to indicate blocks of code in scopes.
For example, a typical if
-else
branch is written as
if some_predicate
console.log('consequence')
else
console.log('alternative')
Those two console.log(...)
are in two separated code blocks. The first one executes when some_predicate()
returns something that if
consider as true, while the second executes otherwise.
When a line contains an incomplete statement, the next line is considered as the succession.
For example
if foo < baz && # a
fox < bar # b
console.log(foo, bar # c
, baz) # d
Line (a) and (b) are considered as one line because the predicate expression is not completed after a binary operator &&
. Line (c) and (b) are also considered as one line because a closing parenthesis is needed to complete the function call syntax.
Identifiers are used to represent a function or a class, or a name to a value or a constant. In Flatscript, an identifier
- starts with a underscore
_
or an alphabeta-zA-Z
- followed by any number of underscores, alphabets, or numeric digits
0-9
- except for keywords, which are mentioned below
Please note that the dollar mark $
is not an identifier in Flatscript so that jQuery
the identifier should be used instead.
The following are keywords
func ifnot if else return extern export typeof true false try catch throw
class this super ctor break continue for enum include
And the following are reserved words
from finally with yield while gen delete
Keywords or reserved words are unable to use them as declare references, function names, class names or property names.
An identifier starts with two underscores and also ends up with two underscores is a macro that is not allowed to be a reference name, a function name or a class name, but could be used as a property name.
Flatscript generates Javascript code, but is unable to make any modification to Javascript runtime. Therefore please note that
- the compiler is unable to check whether an object owns a property of a certain name
- the compiler is unable to determine the type of an object or whether an object is callable, or whether the number of arguments passed to a function call is the same as the number of its parameter
- the Javascript built-in function
eval
requires a string of valid Javascript, and still have a chance to fail because Flatscript compiler may change local reference names or even elimilate some of them for optimization
The following are the individual syntax topics that we suggest look over before using the language.
And topics about details of the compiler