Skip to content

Commit

Permalink
parse function docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gareththegeek committed Sep 5, 2018
1 parent 6d46a8b commit 0012331
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion docs/developer/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,60 @@ The Parser API provides the following functions which allow redcode to be parsed

### parse(redcode: string): IParseResult

Parse a redcode document and return an IParseResult which consists of the tokenised program and any associated messages.
Parse a redcode document and return an `IParseResult` which consists of the tokenised program and any associated messages.

The `IParseResult` has the following structure:

```
{
metaData: {
name: string,
author: string,
strategy: string
},
tokens: [{
position: {
line: number,
char: number
},
lexeme: string,
category: number
}],
messages: [{
type: number;
position: {
line: number,
char: number
},
text: string
}],
data?: any
}
```

The token category number is an enumerated type with the following possible values:

|Value|Meaning|
|---|---|
|0|Label|
|1|Opcode|
|2|Preprocessor|
|3|Modifier|
|4|Mode|
|5|Number|
|6|Comma|
|7|Maths|
|8|EOL|
|9|Comment|
|10|Unknown|

The message type number is an enumerated type with the following possible values:

|Value|Meaning|
|---|---|
|0|Error|
|1|Warning|
|2|Info|

### serialise(tokens: IToken[]): string

Expand Down

0 comments on commit 0012331

Please sign in to comment.