circuitscript 0.0.22 → 0.0.25

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.
Files changed (180) hide show
  1. package/dist/cjs/BaseVisitor.js +487 -0
  2. package/dist/cjs/SemanticTokenVisitor.js +218 -0
  3. package/dist/cjs/SymbolValidatorVisitor.js +233 -0
  4. package/dist/cjs/antlr/CircuitScriptLexer.js +302 -0
  5. package/dist/cjs/antlr/CircuitScriptParser.js +5128 -0
  6. package/dist/cjs/antlr/CircuitScriptVisitor.js +7 -0
  7. package/dist/cjs/draw_symbols.js +819 -0
  8. package/dist/cjs/execute.js +778 -0
  9. package/{src/export.ts → dist/cjs/export.js} +34 -56
  10. package/dist/cjs/fonts.js +4 -0
  11. package/dist/cjs/geometry.js +450 -0
  12. package/dist/cjs/globals.js +60 -0
  13. package/dist/cjs/helpers.js +269 -0
  14. package/dist/cjs/index.js +31 -0
  15. package/{src/layout.ts → dist/cjs/layout.js} +421 -1002
  16. package/dist/cjs/lexer.js +111 -0
  17. package/dist/cjs/logger.js +17 -0
  18. package/dist/cjs/main.js +82 -0
  19. package/dist/cjs/objects/ClassComponent.js +145 -0
  20. package/dist/cjs/objects/ExecutionScope.js +135 -0
  21. package/dist/cjs/objects/Frame.js +22 -0
  22. package/{src/objects/Net.ts → dist/cjs/objects/Net.js} +9 -24
  23. package/dist/cjs/objects/ParamDefinition.js +42 -0
  24. package/dist/cjs/objects/PinDefinition.js +31 -0
  25. package/dist/cjs/objects/PinTypes.js +11 -0
  26. package/dist/cjs/objects/Wire.js +9 -0
  27. package/dist/cjs/objects/types.js +15 -0
  28. package/dist/cjs/parser.js +70 -0
  29. package/dist/cjs/regenerate-tests.js +23 -0
  30. package/dist/cjs/render.js +155 -0
  31. package/{src/server.ts → dist/cjs/server.js} +15 -21
  32. package/dist/cjs/sizing.js +105 -0
  33. package/{src/utils.ts → dist/cjs/utils.js} +25 -35
  34. package/dist/cjs/validate.js +81 -0
  35. package/dist/cjs/visitor.js +844 -0
  36. package/dist/esm/BaseVisitor.mjs +488 -0
  37. package/dist/esm/SemanticTokenVisitor.mjs +215 -0
  38. package/dist/esm/SymbolValidatorVisitor.mjs +222 -0
  39. package/dist/esm/antlr/CircuitScriptLexer.mjs +276 -0
  40. package/dist/esm/antlr/CircuitScriptParser.mjs +5038 -0
  41. package/{build/src/antlr/CircuitScriptVisitor.js → dist/esm/antlr/CircuitScriptVisitor.mjs} +8 -3
  42. package/{build/src/draw_symbols.js → dist/esm/draw_symbols.mjs} +78 -33
  43. package/{build/src/execute.js → dist/esm/execute.mjs} +59 -60
  44. package/{build/src/export.js → dist/esm/export.mjs} +2 -2
  45. package/{build/src/geometry.js → dist/esm/geometry.mjs} +31 -15
  46. package/dist/esm/helpers.mjs +252 -0
  47. package/dist/esm/index.mjs +15 -0
  48. package/{build/src/layout.js → dist/esm/layout.mjs} +19 -11
  49. package/{build/src/lexer.js → dist/esm/lexer.mjs} +10 -10
  50. package/{build/src/main.js → dist/esm/main.mjs} +9 -14
  51. package/{build/src/objects/ClassComponent.js → dist/esm/objects/ClassComponent.mjs} +6 -3
  52. package/{build/src/objects/ExecutionScope.js → dist/esm/objects/ExecutionScope.mjs} +1 -0
  53. package/{build/src/objects/PinDefinition.js → dist/esm/objects/PinDefinition.mjs} +1 -1
  54. package/dist/esm/objects/types.mjs +12 -0
  55. package/dist/esm/parser.mjs +64 -0
  56. package/{build/src/regenerate-tests.js → dist/esm/regenerate-tests.mjs} +1 -1
  57. package/{build/src/render.js → dist/esm/render.mjs} +7 -24
  58. package/{build/src/sizing.js → dist/esm/sizing.mjs} +22 -8
  59. package/{src/main.ts → dist/esm/validate.mjs} +31 -62
  60. package/dist/esm/visitor.mjs +838 -0
  61. package/dist/types/BaseVisitor.d.ts +69 -0
  62. package/dist/types/SemanticTokenVisitor.d.ts +36 -0
  63. package/dist/types/SymbolValidatorVisitor.d.ts +61 -0
  64. package/{build/src → dist/types}/antlr/CircuitScriptLexer.d.ts +28 -27
  65. package/dist/types/antlr/CircuitScriptParser.d.ts +719 -0
  66. package/{build/src → dist/types}/antlr/CircuitScriptVisitor.d.ts +69 -59
  67. package/{build/src → dist/types}/draw_symbols.d.ts +11 -2
  68. package/{build/src → dist/types}/execute.d.ts +6 -9
  69. package/{build/src → dist/types}/geometry.d.ts +5 -1
  70. package/dist/types/helpers.d.ts +40 -0
  71. package/dist/types/index.d.ts +15 -0
  72. package/{build/src → dist/types}/layout.d.ts +10 -10
  73. package/{build/src → dist/types}/lexer.d.ts +2 -2
  74. package/{build/src → dist/types}/objects/ClassComponent.d.ts +2 -2
  75. package/{build/src → dist/types}/objects/ExecutionScope.d.ts +4 -1
  76. package/{build/src → dist/types}/objects/PinDefinition.d.ts +1 -1
  77. package/{build/src → dist/types}/objects/types.d.ts +5 -0
  78. package/dist/types/parser.d.ts +25 -0
  79. package/{build/src → dist/types}/render.d.ts +1 -1
  80. package/{build/src → dist/types}/sizing.d.ts +3 -1
  81. package/dist/types/validate.d.ts +2 -0
  82. package/dist/types/visitor.d.ts +80 -0
  83. package/libs/lib.cst +0 -2
  84. package/package.json +38 -15
  85. package/.editorconfig +0 -15
  86. package/.eslintignore +0 -1
  87. package/.eslintrc.json +0 -27
  88. package/.gitlab-ci.yml +0 -81
  89. package/.prettierignore +0 -8
  90. package/.prettierrc +0 -16
  91. package/__tests__/expectedResults.ts +0 -657
  92. package/__tests__/helpers.ts +0 -82
  93. package/__tests__/parseScripts.ts +0 -593
  94. package/__tests__/renderData/script1.cst +0 -58
  95. package/__tests__/renderData/script1.cst.svg +0 -1
  96. package/__tests__/renderData/script2.cst +0 -16
  97. package/__tests__/renderData/script2.cst.svg +0 -1
  98. package/__tests__/renderData/script3.cst +0 -30
  99. package/__tests__/renderData/script3.cst.svg +0 -1
  100. package/__tests__/renderData/script4.cst +0 -54
  101. package/__tests__/renderData/script4.cst.svg +0 -1
  102. package/__tests__/renderData/script5.cst +0 -23
  103. package/__tests__/renderData/script5.cst.svg +0 -1
  104. package/__tests__/renderData/script6.cst +0 -28
  105. package/__tests__/renderData/script6.cst.svg +0 -1
  106. package/__tests__/renderData/script7.cst +0 -26
  107. package/__tests__/renderData/script7.cst.svg +0 -1
  108. package/__tests__/renderData/script8.cst +0 -37
  109. package/__tests__/renderData/script8.cst.svg +0 -1
  110. package/__tests__/testCLI.ts +0 -68
  111. package/__tests__/testMathOps.ts +0 -36
  112. package/__tests__/testMergeWires.ts +0 -141
  113. package/__tests__/testParse.ts +0 -263
  114. package/__tests__/testRender.ts +0 -38
  115. package/build/src/antlr/CircuitScriptLexer.js +0 -287
  116. package/build/src/antlr/CircuitScriptParser.d.ts +0 -674
  117. package/build/src/antlr/CircuitScriptParser.js +0 -4841
  118. package/build/src/helpers.d.ts +0 -1
  119. package/build/src/helpers.js +0 -73
  120. package/build/src/objects/types.js +0 -6
  121. package/build/src/parser.js +0 -69
  122. package/build/src/visitor.d.ts +0 -133
  123. package/build/src/visitor.js +0 -1154
  124. package/documentation.md +0 -238
  125. package/examples/example_arduino_uno.cst +0 -1146
  126. package/examples/example_garden_pump.cst +0 -567
  127. package/examples/lib.cst +0 -185
  128. package/jest.config.js +0 -23
  129. package/refresh.html +0 -42
  130. package/server.cjs +0 -50
  131. package/src/antlr/CircuitScript.g4 +0 -209
  132. package/src/antlr/CircuitScriptLexer.ts +0 -317
  133. package/src/antlr/CircuitScriptParser.ts +0 -4979
  134. package/src/antlr/CircuitScriptVisitor.ts +0 -420
  135. package/src/draw_symbols.ts +0 -1085
  136. package/src/execute.ts +0 -1227
  137. package/src/fonts.ts +0 -1
  138. package/src/geometry.ts +0 -638
  139. package/src/globals.ts +0 -67
  140. package/src/helpers.ts +0 -114
  141. package/src/lexer.ts +0 -151
  142. package/src/logger.ts +0 -17
  143. package/src/objects/ClassComponent.ts +0 -223
  144. package/src/objects/ExecutionScope.ts +0 -201
  145. package/src/objects/Frame.ts +0 -20
  146. package/src/objects/ParamDefinition.ts +0 -49
  147. package/src/objects/PinDefinition.ts +0 -49
  148. package/src/objects/PinTypes.ts +0 -7
  149. package/src/objects/Wire.ts +0 -19
  150. package/src/objects/types.ts +0 -66
  151. package/src/parser.ts +0 -106
  152. package/src/regenerate-tests.ts +0 -25
  153. package/src/render.ts +0 -260
  154. package/src/sizing.ts +0 -96
  155. package/src/visitor.ts +0 -1691
  156. package/tsconfig.json +0 -27
  157. package/tsconfig.release.json +0 -8
  158. /package/{build/src/fonts.js → dist/esm/fonts.mjs} +0 -0
  159. /package/{build/src/globals.js → dist/esm/globals.mjs} +0 -0
  160. /package/{build/src/logger.js → dist/esm/logger.mjs} +0 -0
  161. /package/{build/src/objects/Frame.js → dist/esm/objects/Frame.mjs} +0 -0
  162. /package/{build/src/objects/Net.js → dist/esm/objects/Net.mjs} +0 -0
  163. /package/{build/src/objects/ParamDefinition.js → dist/esm/objects/ParamDefinition.mjs} +0 -0
  164. /package/{build/src/objects/PinTypes.js → dist/esm/objects/PinTypes.mjs} +0 -0
  165. /package/{build/src/objects/Wire.js → dist/esm/objects/Wire.mjs} +0 -0
  166. /package/{build/src/server.js → dist/esm/server.mjs} +0 -0
  167. /package/{build/src/utils.js → dist/esm/utils.mjs} +0 -0
  168. /package/{build/src → dist/types}/export.d.ts +0 -0
  169. /package/{build/src → dist/types}/fonts.d.ts +0 -0
  170. /package/{build/src → dist/types}/globals.d.ts +0 -0
  171. /package/{build/src → dist/types}/logger.d.ts +0 -0
  172. /package/{build/src → dist/types}/main.d.ts +0 -0
  173. /package/{build/src → dist/types}/objects/Frame.d.ts +0 -0
  174. /package/{build/src → dist/types}/objects/Net.d.ts +0 -0
  175. /package/{build/src → dist/types}/objects/ParamDefinition.d.ts +0 -0
  176. /package/{build/src → dist/types}/objects/PinTypes.d.ts +0 -0
  177. /package/{build/src → dist/types}/objects/Wire.d.ts +0 -0
  178. /package/{build/src → dist/types}/regenerate-tests.d.ts +0 -0
  179. /package/{build/src → dist/types}/server.d.ts +0 -0
  180. /package/{build/src → dist/types}/utils.d.ts +0 -0
package/examples/lib.cst DELETED
@@ -1,185 +0,0 @@
1
- // Circuitscript default lib
2
-
3
- def net(net_name):
4
- return create component:
5
- pins: 1
6
- display: create graphic:
7
- hline: -15, 0, 30
8
- vpin: 1, 0, 10, -10, display_pin_id=0
9
- label: "net_name", 0, -5, net_name, fontSize=10, anchor="middle"
10
- type: "net"
11
- params:
12
- __is_net: 1
13
- net_name: net_name
14
- priority: 10
15
-
16
- def supply(net_name):
17
- return create component:
18
- pins: 1
19
- display: create graphic:
20
- hline: -15, 0, 30
21
- vpin: 1, 0, 10, -10, display_pin_id=0
22
- label: "net_name", 0, -5, net_name, fontSize=10, anchor="middle"
23
- type: "net"
24
- params:
25
- __is_net: 1
26
- net_name: net_name
27
- priority: 20
28
-
29
- def label(value):
30
- return create component:
31
- pins: 1
32
- display: create graphic:
33
- label: "value", 0, -2, "?", fontSize=10, anchor="left"
34
- pin: 1, 0, 0, 0, 0, display_pin_id=0
35
- type: "label"
36
- params:
37
- __is_net: 1
38
- net_name: value
39
- value: value
40
- priority: 5
41
-
42
- def res(value):
43
- width = 40
44
- height = 20
45
-
46
- return create component:
47
- pins: 2
48
- display: create graphic:
49
- rect: 0, 0, width, height
50
- hpin: 1, -width/2 - 20, 0, 20
51
- hpin: 2, width/2 + 20, 0, -20
52
- label: ("value", 0, 1, value, fontSize=10, anchor="middle", vanchor="middle")
53
- label: ("refdes", -width/2, -height/2 -5 , "?", fontSize=10, anchor="left")
54
- type: "res"
55
- params:
56
- value: value
57
- size: "0402"
58
- footprint: "Resistor_SMD:R_0402_1005Metric"
59
-
60
- def cap(value):
61
- width = 20
62
- height = 40
63
-
64
- return create component:
65
- pins: 2
66
- display: create graphic:
67
- hline: -width/2, -3, width
68
- hline: -width/2, 3, width
69
- vpin: 1, 0, -height/2, 20-3
70
- vpin: 2, 0, height/2, -20+3
71
- label: "refdes", width/2+2, 0, "?", fontSize = 10, anchor="left"
72
- label: "value", width/2+2, 5, value, fontSize = 10, anchor = "left", vanchor="top"
73
- type: "cap"
74
- params:
75
- value: value
76
- size: "0402"
77
- footprint: "Capacitor_SMD:C_0402_1005Metric"
78
-
79
- def ind(value):
80
- width = 40
81
- height = 20
82
-
83
- return create component:
84
- pins: 2
85
- type: "ind"
86
- display: create graphic:
87
- arc: -15, 0, 5, 180, 360
88
- arc: -5, 0, 5, 180, 360
89
- arc: 5, 0, 5, 180, 360
90
- arc: 15, 0, 5, 180, 360
91
- hpin: 1, -width/2 - 20, 0, 20
92
- hpin: 2, width/2 + 20, 0, -20
93
- label: ("value", 0, 10, value, fontSize=10, anchor="middle", vanchor="middle")
94
- label: ("refdes", -width/2, -height/2 -5 , "?", fontSize=10, anchor="left")
95
- params:
96
- value: value
97
-
98
- def diode():
99
- width = 20
100
- height = 20
101
-
102
- # Diode is drawn horizontally
103
- # -|>|-
104
- return create component:
105
- pins: 2
106
- type: "diode"
107
- display: create graphic:
108
- triangle: -width/2, 0, width/2, 0, height
109
- vline: width/2, -height/2, height
110
- hpin: 1, -width/2-20, 0, 20 # anode
111
- hpin: 2, width/2 + 20, 0, -20 # cathode
112
- label: "refdes", width/2 + 5, 5, "?", fontSize=10, anchor="left", vanchor="top"
113
-
114
- def led(color):
115
- width = 20
116
- height = 20
117
-
118
- return create component:
119
- pins:
120
- 1: "cathode"
121
- 2: "anode"
122
- type: "diode"
123
- display: create graphic:
124
- triangle: -width/2, 0, width/2, 0, height
125
- vline: width/2, -height/2, height
126
- path: ("M", 0, 8, "L", 5, 18,
127
- "M", 3, 8, "L", 8, 18)
128
- hpin: 1, -width/2-20, 0, 20 # anode
129
- hpin: 2, width/2 + 20, 0, -20 # cathode
130
- label: "refdes", width/2 + 5, 5, "?", fontSize=10, anchor="left", vanchor="top"
131
- label: "color", width/2 + 5, 25, color
132
- params:
133
- size: "0603"
134
- footprint: "LED_SMD:LED_0603_1608Metric_Pad1.05x0.95mm_HandSolder"
135
-
136
-
137
- def cgnd():
138
- net_name = "gnd"
139
- return create component:
140
- pins: 1
141
- display: create graphic:
142
- hline: -15, 0, 30
143
- hline: -10, 5, 20
144
- hline: -5, 10, 10
145
- vpin: 1, 0, -10, 10, display_pin_id=0
146
- label: "net_name", 0, 22, net_name, fontSize=10, anchor="middle"
147
- type: "net"
148
- params:
149
- __is_net: 1
150
- net_name: net_name
151
- priority: 100
152
-
153
- def dgnd():
154
- height = 10
155
- width = 20
156
-
157
- net_name = "GND"
158
- return create component:
159
- pins: 1
160
- display: create graphic:
161
- triangle: 0, 0, 0, height, width
162
- vpin: 1, 0, -10, 10, display_pin_id=0
163
- label: "net_name", 0, height + 10, net_name, fontSize=10, anchor="middle"
164
- type: "net"
165
- params:
166
- __is_net: 1
167
- net_name: net_name
168
- priority: 100
169
-
170
- def marker_point():
171
- return create component:
172
- pins: 1
173
- display: create graphic:
174
- hline: -5, 0, 10
175
- vline: 0, -5, 10
176
- pin: 1, 0, 0, 0, 0, display_pin_id=0
177
- type: "net"
178
-
179
- def arrow_point():
180
- return create component:
181
- pins: 1
182
- display: create graphic:
183
- path: ("M", 15, -5, "L", 20, 0, "L", 15, 5)
184
- hpin: 1, 0, 0, 20
185
- type: "net"
package/jest.config.js DELETED
@@ -1,23 +0,0 @@
1
- export default {
2
- testEnvironment: 'node',
3
- preset: 'ts-jest/presets/default-esm',
4
- transform: {
5
- '^.+\\.m?[tj]s?$': ['ts-jest', {
6
- useESM: true,
7
- diagnostics: false
8
- }],
9
- },
10
- moduleNameMapper: {
11
- '^(\\.{1,2}/.*)\\.(m)?js$': '$1',
12
- },
13
- testMatch: [
14
- "<rootDir>/__tests__/test**.(ts|tsx)",
15
- ],
16
- coverageDirectory: 'coverage',
17
- collectCoverageFrom: [
18
- 'src/**/*.ts',
19
- 'src/**/*.mts',
20
- '!src/**/*.d.ts',
21
- '!src/**/*.d.mts',
22
- ],
23
- };
package/refresh.html DELETED
@@ -1,42 +0,0 @@
1
- <!DOCTYPE html>
2
-
3
- <head>
4
- <title>Circuitscript - Refresh</title>
5
- <style>
6
- @font-face{
7
- font-family: Inter;
8
- src: url('fonts/Inter-Regular.ttf');
9
- }
10
- @font-face {
11
- font-family: Inter-Bold;
12
- src: url('fonts/Inter-Bold.ttf');
13
- }
14
- body {
15
- padding: 0;
16
- margin: 0;
17
- font-family: Arial;
18
- }
19
- </style>
20
- </head>
21
-
22
- <body>
23
- <div id="main"/>
24
- </body>
25
-
26
- <script>
27
-
28
- const socket = new WebSocket("ws://localhost:3000");
29
- socket.addEventListener("open", (event) => {
30
- socket.send("hello");
31
- });
32
-
33
- socket.addEventListener("message", (event) => {
34
- console.log((new Date()).toISOString(), 'got update', event.data.length);
35
-
36
- if (event.data.length > 0){
37
- document.getElementById('main').innerHTML = event.data;
38
- }
39
- });
40
-
41
- </script>
42
- </html>
package/server.cjs DELETED
@@ -1,50 +0,0 @@
1
- const express = require('express')
2
- const ws = require('ws');
3
- const fs = require('fs');
4
-
5
- const app = express()
6
-
7
- const wsServer = new ws.Server({ noServer: true });
8
- wsServer.on('connection', socket => {
9
-
10
- const fileName = 'output.svg';
11
-
12
- function emitFile(){
13
- fs.readFile(fileName, 'utf8', (err, data) => {
14
- if (err) {
15
- throw err;
16
- }
17
- console.log((new Date()).toISOString(), 'send data');
18
- socket.send(data);
19
- });
20
- }
21
-
22
- let emitTimeout = null;
23
- fs.watch(fileName, (event, targetFile) => {
24
- if (event === 'change') {
25
- console.log((new Date()).toISOString(), 'file changed!');
26
-
27
- // emit the change
28
- clearInterval(emitTimeout);
29
- emitTimeout = setTimeout(() => {
30
- emitFile();
31
- }, 200);
32
- }
33
- });
34
-
35
- socket.on('message', message => {
36
- console.log(message.toString());
37
- emitFile();
38
- });
39
- });
40
-
41
- app.use(express.static('./'))
42
-
43
- const server = app.listen(3000);
44
- server.on('upgrade', (request, socket, head) => {
45
- wsServer.handleUpgrade(request, socket, head, socket => {
46
- wsServer.emit('connection', socket, request);
47
- });
48
- });
49
-
50
- console.log('server started at port 3000');
@@ -1,209 +0,0 @@
1
- grammar CircuitScript;
2
-
3
- // Generate with: antlr4 -Dlanguage=Python3 CircuitScript.g4 -no-listener -visitor
4
- // Generate with: antlr4 -Dlanguage=TypeScript CircuitScript.g4 -no-listener -visitor
5
-
6
- tokens { INDENT, DEDENT }
7
-
8
- // Keywords
9
- Break: 'break';
10
- Branch: 'branch';
11
- Create: 'create';
12
- Component: 'component';
13
- Graphic: 'graphic';
14
- Wire: 'wire';
15
- Pin: 'pin';
16
- Add: 'add';
17
- At: 'at';
18
- To: 'to';
19
- Point: 'point';
20
- Join: 'join';
21
- Parallel: 'parallel';
22
-
23
- Return: 'return';
24
- Define: 'def';
25
- Import: 'import';
26
-
27
- If: 'if';
28
- Not: '!';
29
-
30
- Equals: '==';
31
- NotEquals: '!=';
32
- Addition: '+';
33
- Minus: '-';
34
- Divide: '/';
35
- Multiply: '*';
36
-
37
-
38
- script: (expression | NEWLINE)+ EOF;
39
-
40
- // These expressions are related to circuit building only
41
- expression: add_component_expr
42
- | to_component_expr
43
- | at_component_expr
44
- | assignment_expr
45
- | property_set_expr
46
- | property_set_expr2
47
- | double_dot_property_set_expr
48
- | break_keyword
49
- | function_def_expr
50
- | wire_expr
51
- | import_expr
52
- | frame_expr
53
- | atom_expr
54
-
55
- | at_block
56
- | path_blocks
57
- | point_expr
58
- ;
59
-
60
- path_blocks: path_block_inner+;
61
- path_block_inner:
62
- (Branch | Join | Parallel | Point) ':' NEWLINE INDENT (NEWLINE | expression)+ DEDENT;
63
-
64
- property_set_expr2:
65
- atom_expr ':' NEWLINE INDENT ( NEWLINE | assignment_expr2)+ DEDENT;
66
- assignment_expr2: (ID | INTEGER_VALUE) ':' value_expr;
67
-
68
- data_expr_with_assignment: (data_expr | assignment_expr) pin_select_expr?;
69
-
70
- add_component_expr: Add data_expr_with_assignment ID?;
71
-
72
- component_select_expr: data_expr_with_assignment | pin_select_expr;
73
- pin_select_expr: Pin (INTEGER_VALUE | STRING_VALUE);
74
- // This does not have the 'pin' word
75
- pin_select_expr2: INTEGER_VALUE | STRING_VALUE;
76
-
77
- at_component_expr: At ((component_select_expr ID?) | Point); // ID? is for orientation
78
- // at_component_expr_next: 'at' component_select_expr (',' component_select_expr)*;
79
-
80
- to_component_expr: To ((component_select_expr (',' component_select_expr)* ID?) | Point); // ID? is for orientation
81
- // pin_select_expr_next: 'pin' INTEGER_VALUE (',' INTEGER_VALUE)?;
82
-
83
- at_to_multiple_expr: At component_select_expr To component_select_expr (',' component_select_expr)* ':' NEWLINE INDENT (NEWLINE | at_to_multiple_line_expr) + DEDENT;
84
- at_to_multiple_line_expr: pin_select_expr2 ':' at_to_multiple_line_expr_to_pin (',' at_to_multiple_line_expr_to_pin)*;
85
-
86
- at_to_multiple_line_expr_to_pin: (INTEGER_VALUE | NOT_CONNECTED);
87
-
88
- at_block: at_component_expr ':' NEWLINE INDENT (NEWLINE | at_block_expressions) + DEDENT;
89
- at_block_expressions: expression | at_block_pin_expr;
90
-
91
- // Expression to allow direct pin assignment
92
- at_block_pin_expr: pin_select_expr2 ':' (at_block_pin_expression_simple | at_block_pin_expression_complex);
93
-
94
- at_block_pin_expression_simple: (expression | NOT_CONNECTED);
95
- at_block_pin_expression_complex: NEWLINE INDENT ( NEWLINE | expression)+ DEDENT;
96
-
97
- break_keyword: Break;
98
-
99
- assignment_expr: atom_expr '=' data_expr;
100
- keyword_assignment_expr: ID '=' data_expr;
101
-
102
- parameters: (data_expr (',' data_expr)* (',' keyword_assignment_expr)*)
103
- | (keyword_assignment_expr (',' keyword_assignment_expr)*);
104
-
105
- property_set_expr: atom_expr '=' data_expr;
106
- double_dot_property_set_expr: '..' ID '=' data_expr;
107
-
108
- data_expr:
109
- '(' data_expr ')' #RoundedBracketsExpr
110
- | (value_expr | atom_expr) #ValueAtomExpr
111
- | unary_operator data_expr #UnaryOperatorExpr
112
- | data_expr (Multiply | Divide) data_expr #MultiplyExpr
113
- | data_expr (Addition | Minus) data_expr #AdditionExpr
114
- | data_expr binary_operator data_expr #BinaryOperatorExpr
115
- | create_component_expr #DataExpr
116
- | create_graphic_expr #DataExpr
117
- ;
118
-
119
- binary_operator: Equals
120
- | NotEquals
121
- ;
122
-
123
- unary_operator: Not | Minus;
124
-
125
- value_expr: ('-'?
126
- (NUMERIC_VALUE
127
- | DECIMAL_VALUE
128
- | INTEGER_VALUE
129
- | STRING_VALUE
130
- | PERCENTAGE_VALUE
131
- | BOOLEAN_VALUE))
132
- | blank_expr;
133
-
134
- function_def_expr: Define ID '(' function_args_expr? ')' ':' NEWLINE INDENT (NEWLINE | function_expr)+ DEDENT;
135
- function_expr: expression | function_return_expr;
136
-
137
- function_args_expr:
138
- ID (',' ID)* (',' ID '=' value_expr)*
139
- | ID '=' value_expr (',' ID '=' value_expr)*
140
- ;
141
-
142
- atom_expr: net_namespace_expr? ID trailer_expr*;
143
- trailer_expr: '(' parameters? ')'
144
- | '.' ID;
145
-
146
- net_namespace_expr: '+'? '/' data_expr?;
147
-
148
- function_return_expr: Return data_expr ;
149
-
150
- create_component_expr: Create Component ':' NEWLINE INDENT (NEWLINE | property_expr)+ DEDENT;
151
- create_graphic_expr: Create Graphic ':' NEWLINE INDENT (NEWLINE | sub_expr)+ DEDENT;
152
-
153
- sub_expr: (ID | Pin) ':' (parameters | '(' parameters ')');
154
-
155
- property_expr: property_key_expr ':' property_value_expr;
156
- property_key_expr: ID | INTEGER_VALUE | STRING_VALUE;
157
- property_value_expr: NEWLINE INDENT (NEWLINE | property_expr)+ DEDENT # nested_properties
158
- | data_expr (',' data_expr)* # single_line_property
159
- ;
160
-
161
- blank_expr: '[' INTEGER_VALUE ']';
162
-
163
- wire_expr: Wire ID (INTEGER_VALUE | ID)*;
164
- point_expr: Point ID;
165
- import_expr: Import ID;
166
-
167
- frame_expr: 'frame' ':' NEWLINE INDENT (NEWLINE | expression)+ DEDENT;
168
-
169
-
170
- OPEN_PAREN : '(' {this.openBrace();};
171
- CLOSE_PAREN : ')' {this.closeBrace();};
172
-
173
- // A place holder to indicate that a pin is not connected
174
- NOT_CONNECTED: 'nc' | 'NC';
175
-
176
- BOOLEAN_VALUE: 'true' | 'false';
177
-
178
- ID: [_a-zA-Z][_a-zA-Z0-9]*;
179
-
180
- // This value takes a number with an alphabet at the end to indicate
181
- // the multipler to the number
182
-
183
- fragment DecimalIntegerLiteral
184
- : '0'
185
- | [1-9] [0-9_]*
186
- ;
187
-
188
- INTEGER_VALUE: ([1-9]+ [0-9]*) | [0];
189
- DECIMAL_VALUE: DecimalIntegerLiteral '.' [0-9][0-9_]*;
190
- NUMERIC_VALUE: (INTEGER_VALUE | DECIMAL_VALUE) [kmMunp]?;
191
-
192
- STRING_VALUE: '"' (.)*? '"';
193
- PERCENTAGE_VALUE: [1-9]+[0-9]* '%';
194
- ALPHA_NUMERIC: [a-zA-Z0-9]+;
195
-
196
- WS: [ \t]+ -> skip;
197
-
198
- NEWLINE
199
- : ( '\r'? '\n' | '\r' | '\f' ) SPACES? {this.onNewLine();}
200
- ;
201
-
202
- fragment SPACES
203
- : [ \t]+
204
- ;
205
-
206
- // Follow python's comment symbol for now
207
- fragment COMMENT: '#' ~[\r\n\f]*;
208
-
209
- SKIP_: (WS | COMMENT) -> skip;