Add stdlib documentation

This commit is contained in:
Bartłomiej Pluta
2019-09-17 00:29:31 +02:00
parent 231ce4c4c5
commit 1d01d1c373
8 changed files with 1090 additions and 6 deletions

View File

@@ -1684,7 +1684,7 @@ using `--tokens` flag, for example:
```
$ smnp --tokens --dry-run -c "[1, 2, 3] as i ^ println(\"Current: \" + i.toString());"
[Current(0): {OPEN_SQUARE, '[', (0, 0)}
{OPEN_SQUARE, '[', (0, 0)}, {INTEGER, '1', (0, 1)}, {COMMA, ',', (0, 2)}, {INTEGER, '2', (0, 4)}, {COMMA, ',', (0, 5)}, {INTEGER, '3', (0, 7)}, {CLOSE_SQUARE, ']', (0, 8)}, {AS, 'as', (0, 10)}, {IDENTIFIER, 'i', (0, 13)}, {DASH, '^', (0, 15)}, {IDENTIFIER, 'println', (0, 17)}, {OPEN_PAREN, '(', (0, 24)}, {STRING, 'Current: ', (0, 25)}, {PLUS, '+', (0, 37)}, {IDENTIFIER, 'i', (0, 39)}, {DOT, '.', (0, 40)}, {IDENTIFIER, 'toString', (0, 41)}, {OPEN_PAREN, '(', (0, 49)}, {CLOSE_PAREN, ')', (0, 50)}, {CLOSE_PAREN, ')', (0, 51)}, {SEMICOLON, ';', (0, 52)}]
{OPEN_SQUARE, '[', (0, 0)}, {INTEGER, '1', (0, 1)}, {COMMA, ',', (0, 2)}, {INTEGER, '2', (0, 4)}, {COMMA, ',', (0, 5)}, {INTEGER, '3', (0, 7)}, {CLOSE_SQUARE, ']', (0, 8)}, {AS, 'as', (0, 10)}, {IDENTIFIER, 'i', (0, 13)}, {CARET, '^', (0, 15)}, {IDENTIFIER, 'println', (0, 17)}, {OPEN_PAREN, '(', (0, 24)}, {STRING, 'Current: ', (0, 25)}, {PLUS, '+', (0, 37)}, {IDENTIFIER, 'i', (0, 39)}, {DOT, '.', (0, 40)}, {IDENTIFIER, 'toString', (0, 41)}, {OPEN_PAREN, '(', (0, 49)}, {CLOSE_PAREN, ')', (0, 50)}, {CLOSE_PAREN, ')', (0, 51)}, {SEMICOLON, ';', (0, 52)}]
```
Tokenizer tries to match input with all available patterns, sticking

1084
STDLIB.md Normal file

File diff suppressed because it is too large Load Diff

BIN
img/plots/c.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
img/plots/spectrum.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -113,11 +113,11 @@ def LoopParser(input):
return Parser.allOf(
ExpressionWithoutLoopParser,
Parser.optional(loopParameters),
Parser.terminal(TokenType.DASH, createNode=Operator.withValue),
Parser.terminal(TokenType.CARET, createNode=Operator.withValue),
StatementParser,
Parser.optional(loopFilter),
createNode=Loop.loop,
name="dash-loop"
name="caret-loop"
)(input)

View File

@@ -47,7 +47,7 @@ def getValueAccordingToType(value, type):
raise ValueError()
raise RuntimeException(f"Type {type.value.name.lower()} is not suuported", None)
raise RuntimeException(f"Type {type.value.name.lower()} is not supported", None)
except ValueError:
raise RuntimeException(f"Invalid value '{value}' for type {type.value.name.lower()}", None)

View File

@@ -36,7 +36,7 @@ tokenizers = (
defaultTokenizer(TokenType.SLASH),
defaultTokenizer(TokenType.MINUS),
defaultTokenizer(TokenType.PLUS),
defaultTokenizer(TokenType.DASH),
defaultTokenizer(TokenType.CARET),
defaultTokenizer(TokenType.DOTS),
defaultTokenizer(TokenType.AMP),
defaultTokenizer(TokenType.DOT),

View File

@@ -21,7 +21,7 @@ class TokenType(Enum):
SLASH = '/'
MINUS = '-'
PLUS = '+'
DASH = '^'
CARET = '^'
DOTS = '...'
AMP = '&'
DOT = '.'