Add a real Pygments lexer for Wren (finally!).

This commit is contained in:
Bob Nystrom
2015-09-22 07:59:54 -07:00
parent 36f7d74183
commit 505b48fdac
34 changed files with 294 additions and 198 deletions
+13 -13
View File
@@ -5,7 +5,7 @@ A list is a compound object that holds a collection of elements identified by
integer index. You can create a list by placing a sequence of comma-separated
expressions inside square brackets:
:::dart
:::wren
[1, "banana", true]
Here, we've created a list of three elements. Notice that the elements don't
@@ -17,21 +17,21 @@ You can access an element from a list by calling the [subscript
operator](expressions.html#subscript-operators) on it with the index of the
element you want. Like most languages, indexes start at zero:
:::dart
:::wren
var hirsute = ["sideburns", "porkchops", "'stache", "goatee"]
hirsute[0] // "sideburns".
hirsute[1] // "porkchops".
Negative indices counts backwards from the end:
:::dart
:::wren
hirsute[-1] // "goatee".
hirsute[-2] // "'stache".
It's a runtime error to pass an index outside of the bounds of the list. If you
don't know what those bounds are, you can find out using count:
:::dart
:::wren
hirsute.count // 4.
## Slices and ranges
@@ -39,7 +39,7 @@ don't know what those bounds are, you can find out using count:
Sometimes you want to copy a chunk of elements from a list. You can do that by
passing a [range](values.html#ranges) to the subscript operator, like so:
:::dart
:::wren
hirsute[1..2] // ["porkchops", "'stache"].
This returns a new list containing the elements of the original list whose
@@ -49,7 +49,7 @@ and do what you expect.
Negative bounds also work like they do when passing a single number, so to copy
a list, you can just do:
:::dart
:::wren
hirsute[0..-1]
## Adding elements
@@ -57,20 +57,20 @@ a list, you can just do:
Lists are *mutable*, meaning their contents can be changed. You can swap out an
existing element in the list using the subscript setter:
:::dart
:::wren
hirsute[1] = "muttonchops"
System.print(hirsute[1]) // muttonchops.
It's an error to set an element that's out of bounds. To grow a list, you can
use `add` to append a single item to the end:
:::dart
:::wren
hirsute.add("goatee")
System.print(hirsute.count) // 4.
You can insert a new element at a specific position using `insert`:
:::dart
:::wren
hirsute.insert(2, "soul patch")
The first argument is the index to insert at, and the second is the value to
@@ -81,7 +81,7 @@ It's valid to "insert" after the last element in the list, but only *right*
after it. Like other methods, you can use a negative index to count from the
back. Doing so counts back from the size of the list *after* it's grown by one:
:::dart
:::wren
var letters = ["a", "b", "c"]
letters.insert(3, "d") // OK: inserts at end.
System.print(letters) // ["a", "b", "c", "d"]
@@ -94,18 +94,18 @@ The opposite of `insert` is `removeAt`. It removes a single element from a
given position in the list. All following items are shifted up to fill in the
gap:
:::dart
:::wren
var letters = ["a", "b", "c", "d"]
letters.removeAt(1)
System.print(letters) // ["a", "c", "d"]
The `removeAt` method returns the removed item:
:::dart
:::wren
System.print(letters.removeAt(1)) // "c"
If you want to remove everything from the list, you can clear it:
:::dart
:::wren
hirsute.clear()
System.print(hirsute) // []