* A Mode is, in the simplest case, a lexer (tokenizer) for your language — a function that takes a character stream as input, * advances it past a token, and returns a style for that token. More advanced modes can also handle indentation for the language.
| 1020 | * advances it past a token, and returns a style for that token. More advanced modes can also handle indentation for the language. |
| 1021 | */ |
| 1022 | interface Mode<T> { |
| 1023 | /** |
| 1024 | * This function should read one token from the stream it is given as an argument, optionally update its state, |
| 1025 | * and return a style string, or null for tokens that do not have to be styled. Multiple styles can be returned, separated by spaces. |
| 1026 | */ |
| 1027 | token(stream: StringStream, state: T): string; |
| 1028 | |
| 1029 | /** |
| 1030 | * A function that produces a state object to be used at the start of a document. |
| 1031 | */ |
| 1032 | startState?: () => T; |
| 1033 | /** |
| 1034 | * For languages that have significant blank lines, you can define a blankLine(state) method on your mode that will get called |
| 1035 | * whenever a blank line is passed over, so that it can update the parser state. |
| 1036 | */ |
| 1037 | blankLine?: (state: T) => void; |
| 1038 | /** |
| 1039 | * Given a state returns a safe copy of that state. |
| 1040 | */ |
| 1041 | copyState?: (state: T) => T; |
| 1042 | |
| 1043 | /** |
| 1044 | * The indentation method should inspect the given state object, and optionally the textAfter string, which contains the text on |
| 1045 | * the line that is being indented, and return an integer, the amount of spaces to indent. |
| 1046 | */ |
| 1047 | indent?: (state: T, textAfter: string) => number; |
| 1048 | |
| 1049 | /** The four below strings are used for working with the commenting addon. */ |
| 1050 | /** |
| 1051 | * String that starts a line comment. |
| 1052 | */ |
| 1053 | lineComment?: string; |
| 1054 | /** |
| 1055 | * String that starts a block comment. |
| 1056 | */ |
| 1057 | blockCommentStart?: string; |
| 1058 | /** |
| 1059 | * String that ends a block comment. |
| 1060 | */ |
| 1061 | blockCommentEnd?: string; |
| 1062 | /** |
| 1063 | * String to put at the start of continued lines in a block comment. |
| 1064 | */ |
| 1065 | blockCommentLead?: string; |
| 1066 | |
| 1067 | /** |
| 1068 | * Trigger a reindent whenever one of the characters in the string is typed. |
| 1069 | */ |
| 1070 | electricChars?: string |
| 1071 | /** |
| 1072 | * Trigger a reindent whenever the regex matches the part of the line before the cursor. |
| 1073 | */ |
| 1074 | electricinput?: RegExp |
| 1075 | } |
| 1076 | |
| 1077 | /** |
| 1078 | * A function that, given a CodeMirror configuration object and an optional mode configuration object, returns a mode object. |