From 77c6ab5c8435c9fcde7c4742ee0e5eb06341eeff Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 7 Jul 2022 21:23:06 -0400 Subject: Separate token and constant documentation into its own page --- docs/doc/syntax.html | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) (limited to 'docs/doc/syntax.html') diff --git a/docs/doc/syntax.html b/docs/doc/syntax.html index 94bace3c..ef6c1804 100644 --- a/docs/doc/syntax.html +++ b/docs/doc/syntax.html @@ -56,7 +56,7 @@ -Separator +Separator ⋄, and newline ? @@ -77,7 +77,7 @@ -

While all of BQN's grammar fits into this table somehow, it's not really the whole story because subexpressions including parentheses and blocks might behave like functions or modifiers.

+

While all of BQN's grammar fits into this table somehow, it's not really the whole story because subexpressions including parentheses and blocks might behave like functions or modifiers. See expressions and blocks.

Special glyphs

The following glyphs are used for BQN syntax. Primitives (built-in functions and modifiers) are not listed in this table, and have their own page. Digits, characters, and the underscore _ are used for numbers and variable names.

@@ -90,19 +90,19 @@ - + - + - + - + @@ -130,7 +130,7 @@ - + @@ -186,25 +186,16 @@
#CommentComment
'"Character or string literalCharacter or string literal
@Null characterNull character
¯∞πUsed in numeric literalsUsed in numeric literals
·
⋄, or newlineStatement or element separatorStatement or element separator
⟨⟩
-

Comments

-

A comment starts with a # that isn't part of a character or string literal, and continues to the end of the line.

-↗️
    '#' - 1  #This is the comment
-'"'
-
-

Constants

-

BQN has single-token notation for numbers, strings, and characters.

-

Numbers are written as decimals, allowing ¯ for the negative sign (because - is a function) and e or E for scientific notation. They must have digits before and after the decimal point (so, 0.5 instead of .5), and any exponent must be an integer. Two special numbers and π are supported, possibly with a minus sign. If complex numbers are supported (no implementation to date has them), then they can be written with the components separated by i or I.

-↗️
     ¯π  0.5  5e¯1  1.5E3      # A list of numbers
-⟨ ¯3.141592653589793 0.5 0.5 1500 ∞ ⟩
-
-

Strings—lists of characters—are written with double quotes "", and characters with single quotes '' with a single character in between. Only one character ever needs to be escaped: a double quote in a string is written twice. So """" is a one-character string of ", and if two string literals are next to each other, they have to be separated by a space. Character literals don't have even one escape, as the length is already known. Other than the double quote, character and string literals can contain anything: newlines, null characters, or any other Unicode.

-↗️
    ¨  "str"  "s't""r"  'c'  '''  '"'    # "" is an escape
-⟨ 3 5 1 1 1 ⟩
-
-    ¨  "a"  'a'    # A string is an array but a character isn't
-⟨ 1 0 ⟩
-
-

But including a null character in your source code is probably not a great idea for other reasons. The null character (code point 0) has a dedicated literal representation @. Null can be used with character arithmetic to directly convert between characters and numeric code points, which among many other uses allows tricky characters to be entered by code point: for example, a non-breaking space is @+160.

+

Tokens

+

Full documentation

+

BQN syntax is made up of tokens, which are mostly single characters. But there are a few exceptions:

+

Expressions

Full documentation

BQN expressions are composed of subjects, functions, and modifiers, with parentheses to group parts into subexpressions. Functions can be applied to subjects or grouped into trains, while modifiers can be applied to subjects or functions. The most important kinds of application are:

@@ -263,9 +254,7 @@

Assignment arrows , , and store expression results in variables: and create new variables while modifies existing ones. The general format is Name Value, where the two sides have the same role. Additionally, lhs F rhs is a shortened form of lhs lhs F rhs and lhs F expands to lhs F lhs.

The double arrow is used for functionality relating to namespaces. It has a few purposes: exporting assignment namevalue, plain export name, and aliasing aliasfieldnamespace. A block that uses it for export returns a namespace rather than the result of its last statement. The other namespace-related bit of syntax is field access ns.field.

Arrays and blocks

-

Arrays and code blocks can both be represented as sequences of expressions in source code. There are paired bracket representations, using ⟨⟩ for lists, [] for arrays, and {} for blocks, as well as a shortcut "stranding" notation using for lists.

-

Separators

-

The characters and , and newline are completely interchangeable and are used to separate expressions. An expression might be an element in a list or a line in a block. Empty sections—those that consist only of whitespace—are ignored. This means that any number of separators can be used between expressions, and that leading and trailing separators are also allowed. The expressions are evaluated in text order: left to right and top to bottom.

+

Arrays and code blocks can both be represented as sequences of expressions in source code. There are paired bracket representations, using ⟨⟩ for lists, [] for arrays, and {} for blocks, as well as a shortcut "stranding" notation using for lists. Elements within brackets are divided by separators: , or or a line break.

List and array notation

Full documentation

Lists (1-dimensional arrays) are enclosed in angle brackets ⟨⟩, with the results of the expressions in between being the list's elements. Lists of two elements or more can also be written with the ligature character . This character has higher binding strength than any part of an expression except . for namespace field access. If one of the elements is a compound expression, then it will need to be enclosed in parentheses.

-- cgit v1.2.3