UNPKG

3.43 kBPlain TextView Raw
1/*---------------------------------------------------------------------------------------------
2 * Copyright (c) Microsoft Corporation. All rights reserved.
3 * Licensed under the MIT License. See License.txt in the project root for license information.
4 *--------------------------------------------------------------------------------------------*/
5
6/*
7 * Interface types for Monarch language definitions
8 * These descriptions are really supposed to be JSON values but if using typescript
9 * to describe them, these type definitions can help check the validity.
10 */
11
12export interface IState {
13 clone(): IState;
14 equals(other: IState): boolean;
15}
16
17/**
18 * A Monarch language definition
19 */
20export interface IMonarchLanguage {
21 /**
22 * map from string to ILanguageRule[]
23 */
24 tokenizer: { [name: string]: IMonarchLanguageRule[] };
25 /**
26 * is the language case insensitive?
27 */
28 ignoreCase?: boolean;
29 /**
30 * if no match in the tokenizer assign this token class (default 'source')
31 */
32 defaultToken?: string;
33 /**
34 * for example [['{','}','delimiter.curly']]
35 */
36 brackets?: IMonarchLanguageBracket[];
37 /**
38 * start symbol in the tokenizer (by default the first entry is used)
39 */
40 start?: string;
41 /**
42 * attach this to every token class (by default '.' + name)
43 */
44 tokenPostfix?: string;
45}
46
47/**
48 * A rule is either a regular expression and an action
49 * shorthands: [reg,act] == { regex: reg, action: act}
50 * and : [reg,act,nxt] == { regex: reg, action: act{ next: nxt }}
51 */
52export type IShortMonarchLanguageRule1 = [RegExp, IMonarchLanguageAction];
53
54export type IShortMonarchLanguageRule2 = [RegExp, IMonarchLanguageAction, string];
55
56export interface IExpandedMonarchLanguageRule {
57 /**
58 * match tokens
59 */
60 regex?: string | RegExp;
61 /**
62 * action to take on match
63 */
64 action?: IMonarchLanguageAction;
65
66 /**
67 * or an include rule. include all rules from the included state
68 */
69 include?: string;
70}
71
72export type IMonarchLanguageRule = IShortMonarchLanguageRule1
73 | IShortMonarchLanguageRule2
74 | IExpandedMonarchLanguageRule;
75
76/**
77 * An action is either an array of actions...
78 * ... or a case statement with guards...
79 * ... or a basic action with a token value.
80 */
81export type IShortMonarchLanguageAction = string;
82
83export interface IExpandedMonarchLanguageAction {
84 /**
85 * array of actions for each parenthesized match group
86 */
87 group?: IMonarchLanguageAction[];
88 /**
89 * map from string to ILanguageAction
90 */
91 cases?: Object;
92 /**
93 * token class (ie. css class) (or "@brackets" or "@rematch")
94 */
95 token?: string;
96 /**
97 * the next state to push, or "@push", "@pop", "@popall"
98 */
99 next?: string;
100 /**
101 * switch to this state
102 */
103 switchTo?: string;
104 /**
105 * go back n characters in the stream
106 */
107 goBack?: number;
108 /**
109 * @open or @close
110 */
111 bracket?: string;
112 /**
113 * switch to embedded language (using the mimetype) or get out using "@pop"
114 */
115 nextEmbedded?: string;
116 /**
117 * log a message to the browser console window
118 */
119 log?: string;
120}
121
122export type IMonarchLanguageAction = IShortMonarchLanguageAction
123 | IExpandedMonarchLanguageAction
124 | IShortMonarchLanguageAction[]
125 | IExpandedMonarchLanguageAction[];
126
127/**
128 * This interface can be shortened as an array, ie. ['{','}','delimiter.curly']
129 */
130export interface IMonarchLanguageBracket {
131 /**
132 * open bracket
133 */
134 open: string;
135 /**
136 * closing bracket
137 */
138 close: string;
139 /**
140 * token class
141 */
142 token: string;
143}
\No newline at end of file