@lvce-editor/shared-process 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- # Language Basics CSS
1
+ # Language Basics Css
2
2
 
3
3
  ## Contributing
4
4
 
@@ -104,12 +104,19 @@ export const initialLineState = {
104
104
  stack: [],
105
105
  }
106
106
 
107
+ /**
108
+ * @param {any} lineStateA
109
+ * @param {any} lineStateB
110
+ */
107
111
  export const isEqualLineState = (lineStateA, lineStateB) => {
108
112
  return lineStateA.state === lineStateB.state
109
113
  }
110
114
 
115
+ export const hasArrayReturn = true
116
+
111
117
  /**
112
118
  * @param {string} line
119
+ * @param {any} lineState
113
120
  */
114
121
  export const tokenizeLine = (line, lineState) => {
115
122
  let next = null
@@ -349,11 +356,9 @@ export const tokenizeLine = (line, lineState) => {
349
356
  console.log({ state, line })
350
357
  throw new Error('no')
351
358
  }
352
- index += next[0].length
353
- tokens.push({
354
- type: token,
355
- length: next[0].length,
356
- })
359
+ const tokenLength = next[0].length
360
+ index += tokenLength
361
+ tokens.push(token, tokenLength)
357
362
  }
358
363
  return {
359
364
  state,
@@ -1,33 +1,122 @@
1
+ /**
2
+ * @enum number
3
+ */
4
+ export const State = {
5
+ TopLevelContent: 1,
6
+ InsideLineComment: 2,
7
+ }
8
+
9
+ export const StateMap = {
10
+ [State.TopLevelContent]: 'TopLevelContent',
11
+ [State.InsideLineComment]: 'InsideLineComment',
12
+ }
13
+
1
14
  /**
2
15
  * @enum number
3
16
  */
4
17
  export const TokenType = {
5
- Text: 0,
6
- NewLine: 1,
18
+ CssSelector: 1,
19
+ Whitespace: 2,
20
+ None: 57,
21
+ Unknown: 881,
22
+ NewLine: 884,
23
+ Comment: 885,
24
+ Query: 886,
25
+ Text: 887,
7
26
  }
8
27
 
9
28
  export const TokenMap = {
29
+ [TokenType.CssSelector]: 'CssSelector',
30
+ [TokenType.Whitespace]: 'Whitespace',
31
+ [TokenType.None]: 'None',
32
+ [TokenType.Unknown]: 'Unknown',
33
+ [TokenType.NewLine]: 'NewLine',
34
+ [TokenType.Comment]: 'Comment',
35
+ [TokenType.Query]: 'Query',
10
36
  [TokenType.Text]: 'Text',
11
37
  }
12
38
 
39
+ const RE_LINE_COMMENT_START = /^#/
40
+ const RE_WHITESPACE = /^ +/
41
+ const RE_CURLY_OPEN = /^\{/
42
+ const RE_CURLY_CLOSE = /^\}/
43
+ const RE_PROPERTY_NAME = /^[a-zA-Z\-]+\b/
44
+ const RE_COLON = /^:/
45
+ const RE_PROPERTY_VALUE = /^[^;\}]+/
46
+ const RE_SEMICOLON = /^;/
47
+ const RE_COMMA = /^,/
48
+ const RE_ANYTHING = /^.*/
49
+ const RE_NUMERIC = /^(([0-9]+\.?[0-9]*)|(\.[0-9]+))/
50
+ const RE_ANYTHING_UNTIL_CLOSE_BRACE = /^[^\}]+/
51
+ const RE_BLOCK_COMMENT_START = /^\/\*/
52
+ const RE_BLOCK_COMMENT_END = /^\*\//
53
+ const RE_BLOCK_COMMENT_CONTENT = /^.+?(?=\*\/|$)/s
54
+ const RE_ROUND_OPEN = /^\(/
55
+ const RE_ROUND_CLOSE = /^\)/
56
+ const RE_PSEUDO_SELECTOR_CONTENT = /^[^\)]+/
57
+ const RE_SQUARE_OPEN = /^\[/
58
+ const RE_SQUARE_CLOSE = /^\]/
59
+ const RE_ATTRIBUTE_SELECTOR_CONTENT = /^[^\]]+/
60
+ const RE_QUERY = /^@[a-z\-]+/
61
+ const RE_STAR = /^\*/
62
+ const RE_QUERY_NAME = /^[a-z\-]+/
63
+ const RE_QUERY_CONTENT = /^[^\)]+/
64
+ const RE_COMBINATOR = /^[\+\>\~]/
65
+
13
66
  export const initialLineState = {
14
- state: 1,
67
+ state: State.TopLevelContent,
68
+ tokens: [],
69
+ stack: [],
15
70
  }
16
71
 
72
+ export const hasArrayReturn = true
73
+
74
+ /**
75
+ * @param {string} line
76
+ * @param {any} lineState
77
+ */
17
78
  export const tokenizeLine = (line, lineState) => {
18
- if (line.length === 0) {
19
- return {
20
- state: 1,
21
- tokens: [],
79
+ let next = null
80
+ let index = 0
81
+ let tokens = []
82
+ let token = TokenType.None
83
+ let state = lineState.state
84
+ while (index < line.length) {
85
+ const part = line.slice(index)
86
+ switch (state) {
87
+ case State.TopLevelContent:
88
+ if ((next = part.match(RE_LINE_COMMENT_START))) {
89
+ token = TokenType.Comment
90
+ state = State.InsideLineComment
91
+ } else if ((next = part.match(RE_WHITESPACE))) {
92
+ token = TokenType.Whitespace
93
+ state = State.TopLevelContent
94
+ } else if ((next = part.match(RE_ANYTHING))) {
95
+ token = TokenType.Text
96
+ state = State.TopLevelContent
97
+ } else {
98
+ part //?
99
+ throw new Error('no')
100
+ }
101
+ break
102
+ case State.InsideLineComment:
103
+ if ((next = part.match(RE_ANYTHING))) {
104
+ token = TokenType.Comment
105
+ state = State.TopLevelContent
106
+ } else {
107
+ throw new Error('no')
108
+ }
109
+ break
110
+ default:
111
+ console.log({ state, line })
112
+ throw new Error('no')
22
113
  }
114
+ const tokenLength = next[0].length
115
+ index += tokenLength
116
+ tokens.push(token, tokenLength)
23
117
  }
24
118
  return {
25
- state: 1,
26
- tokens: [
27
- {
28
- type: TokenType.Text,
29
- length: line.length,
30
- },
31
- ],
119
+ state,
120
+ tokens,
32
121
  }
33
122
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "builtin.language-basics-docker",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "name": "Language Basics Docker",
5
5
  "description": "Provides syntax highlighting and bracket matching in Dockerfile files.",
6
6
  "languages": [
@@ -44,6 +44,8 @@ const RE_ANYTHING = /^.*/
44
44
  const RE_KEYWORD =
45
45
  /^(?:ADD|ARG|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|HEALTHCHECK|LABEL|MAINTAINER|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR)\b/
46
46
 
47
+ export const hasArrayReturnValue = true
48
+
47
49
  /**
48
50
  * @param {string} line
49
51
  * @param {any} lineState
@@ -98,6 +98,8 @@ export const isLineStateEqual = (lineStateA, lineStateB) => {
98
98
  return lineStateA.state === lineStateB.state
99
99
  }
100
100
 
101
+ export const hasArrayReturn = true
102
+
101
103
  /**
102
104
  *
103
105
  * @param {string} line
@@ -287,11 +289,9 @@ export const tokenizeLine = (line, lineState) => {
287
289
  state
288
290
  throw new Error('no')
289
291
  }
290
- index += next[0].length
291
- tokens.push({
292
- type: token,
293
- length: next[0].length,
294
- })
292
+ const tokenLength = next[0].length
293
+ index += tokenLength
294
+ tokens.push(token, tokenLength)
295
295
  }
296
296
  return {
297
297
  state,
@@ -6,6 +6,7 @@ export const State = {
6
6
  InsideLineComment: 2,
7
7
  AfterPropertyName: 3,
8
8
  AfterPropertyNameAfterColon: 4,
9
+ AfterDash: 5,
9
10
  }
10
11
 
11
12
  export const StateMap = {
@@ -45,14 +46,14 @@ export const TokenMap = {
45
46
  [TokenType.Unknown]: 'Unknown',
46
47
  [TokenType.Whitespace]: 'Whitespace',
47
48
  [TokenType.Punctuation]: 'Punctuation',
48
- [TokenType.PropertyValueString]: 'PropertyValueString',
49
+ [TokenType.PropertyValueString]: 'String',
49
50
  }
50
51
 
51
52
  const RE_LINE_COMMENT_START = /^#/
52
53
  const RE_WHITESPACE = /^ +/
53
54
  const RE_CURLY_OPEN = /^\{/
54
55
  const RE_CURLY_CLOSE = /^\}/
55
- const RE_PROPERTY_NAME = /^[a-zA-Z\-]+(?=\s*:)/
56
+ const RE_PROPERTY_NAME = /^[a-zA-Z\-\_]+(?=\s*:)/
56
57
  const RE_PROPERTY_VALUE = /^[^;\}]+/
57
58
  const RE_SEMICOLON = /^;/
58
59
  const RE_COMMA = /^,/
@@ -75,6 +76,7 @@ const RE_QUERY_CONTENT = /^[^\)]+/
75
76
  const RE_COMBINATOR = /^[\+\>\~]/
76
77
  const RE_LANGUAGE_CONSTANT = /^(?:true|false)/
77
78
  const RE_COLON = /^:/
79
+ const RE_DASH = /^\-/
78
80
 
79
81
  export const initialLineState = {
80
82
  state: State.TopLevelContent,
@@ -111,6 +113,9 @@ export const tokenizeLine = (line, lineState) => {
111
113
  } else if ((next = part.match(RE_NUMERIC))) {
112
114
  token = TokenType.Numeric
113
115
  state = State.TopLevelContent
116
+ } else if ((next = part.match(RE_DASH))) {
117
+ token = TokenType.Punctuation
118
+ state = State.AfterDash
114
119
  } else if ((next = part.match(RE_ANYTHING))) {
115
120
  token = TokenType.Text
116
121
  state = State.TopLevelContent
@@ -155,6 +160,26 @@ export const tokenizeLine = (line, lineState) => {
155
160
  throw new Error('no')
156
161
  }
157
162
  break
163
+ case State.AfterDash:
164
+ if ((next = part.match(RE_WHITESPACE))) {
165
+ token = TokenType.Whitespace
166
+ state = State.AfterDash
167
+ } else if ((next = part.match(RE_PROPERTY_NAME))) {
168
+ token = TokenType.PropertyName
169
+ state = State.AfterPropertyName
170
+ } else if ((next = part.match(RE_LANGUAGE_CONSTANT))) {
171
+ token = TokenType.LanguageConstant
172
+ state = State.TopLevelContent
173
+ } else if ((next = part.match(RE_NUMERIC))) {
174
+ token = TokenType.Numeric
175
+ state = State.TopLevelContent
176
+ } else if ((next = part.match(RE_ANYTHING))) {
177
+ token = TokenType.PropertyValueString
178
+ state = State.TopLevelContent
179
+ } else {
180
+ throw new Error('no')
181
+ }
182
+ break
158
183
  default:
159
184
  console.log({ state, line })
160
185
  throw new Error('no')
@@ -165,10 +190,11 @@ export const tokenizeLine = (line, lineState) => {
165
190
  length: next[0].length,
166
191
  })
167
192
  }
193
+ if (state === State.AfterPropertyNameAfterColon) {
194
+ state = State.TopLevelContent
195
+ }
168
196
  return {
169
197
  state,
170
198
  tokens,
171
199
  }
172
200
  }
173
-
174
- tokenizeLine(`x: 11`, initialLineState) //?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -38,8 +38,8 @@
38
38
  "verror": "^1.10.1",
39
39
  "ws": "^8.8.1",
40
40
  "xdg-basedir": "^5.1.0",
41
- "@lvce-editor/pty-host": "0.4.0",
42
- "@lvce-editor/extension-host": "0.4.0"
41
+ "@lvce-editor/pty-host": "0.4.1",
42
+ "@lvce-editor/extension-host": "0.4.1"
43
43
  },
44
44
  "optionalDependencies": {
45
45
  "electron-clipboard-ex": "^1.3.3",