@lbdudc/gp-gis-dsl 0.3.1 → 0.3.3

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 (42) hide show
  1. package/.claude/settings.local.json +7 -0
  2. package/grammar/.antlr/GISGrammar.interp +182 -0
  3. package/grammar/.antlr/GISGrammar.tokens +73 -0
  4. package/grammar/.antlr/GISGrammarBaseListener.java +579 -0
  5. package/grammar/.antlr/GISGrammarLexer.interp +241 -0
  6. package/grammar/.antlr/GISGrammarLexer.java +686 -0
  7. package/grammar/.antlr/GISGrammarLexer.tokens +73 -0
  8. package/grammar/.antlr/GISGrammarListener.java +459 -0
  9. package/grammar/.antlr/GISGrammarParser.java +2948 -0
  10. package/grammar/GISGrammar.g4 +313 -313
  11. package/package.json +1 -1
  12. package/parse-file.js +73 -0
  13. package/src/GISVisitorHelper.js +93 -93
  14. package/src/cli.js +34 -34
  15. package/src/error/ErrorListener.js +26 -26
  16. package/src/error/SyntaxGenericError.js +18 -18
  17. package/src/index.js +4 -1
  18. package/src/lib/GISGrammar.interp +181 -181
  19. package/src/lib/GISGrammarLexer.interp +241 -241
  20. package/src/lib/GISGrammarLexer.js +202 -202
  21. package/src/lib/GISGrammarListener.js +1 -1
  22. package/src/lib/GISGrammarParser.js +1 -1
  23. package/src/lib/GISGrammarVisitor.js +1 -1
  24. package/src/spl/GIS.js +234 -234
  25. package/src/spl/GeoJSONLayer.js +21 -21
  26. package/src/spl/GeoJSONLayerStyle.js +14 -14
  27. package/src/spl/TileLayer.js +16 -16
  28. package/src/spl/WMSLayer.js +30 -30
  29. package/src/spl/WMSStyle.js +13 -13
  30. package/src/spl/WMSStyleCustom.js +22 -22
  31. package/src/store.js +74 -74
  32. package/test-examples.js +120 -0
  33. package/test-output/agriculture.json +429 -0
  34. package/test-output/basic.json +315 -0
  35. package/test-output/complete.json +1259 -0
  36. package/test-output/emergency.json +755 -0
  37. package/test-output/environmental.json +591 -0
  38. package/test-output/gis.json +254 -0
  39. package/test-output/tourism.json +704 -0
  40. package/test-output/transportation.json +488 -0
  41. package/test-output/utilities.json +620 -0
  42. package/test-output/wms.json +110 -0
@@ -1,22 +1,22 @@
1
- export default class WMSStyleCustom {
2
- constructor(
3
- id,
4
- geometryType,
5
- fillColor,
6
- strokeColor,
7
- fillOpacity,
8
- strokeOpacity,
9
- ) {
10
- this.name = id;
11
- this.type = "WMSLayerStyle";
12
- this.geometryType = geometryType;
13
- this.fillColor = fillColor;
14
- this.strokeColor = strokeColor;
15
- this.fillOpacity = fillOpacity;
16
- this.strokeOpacity = strokeOpacity;
17
- }
18
-
19
- getId() {
20
- return this.name;
21
- }
22
- }
1
+ export default class WMSStyleCustom {
2
+ constructor(
3
+ id,
4
+ geometryType,
5
+ fillColor,
6
+ strokeColor,
7
+ fillOpacity,
8
+ strokeOpacity,
9
+ ) {
10
+ this.name = id;
11
+ this.type = "WMSLayerStyle";
12
+ this.geometryType = geometryType;
13
+ this.fillColor = fillColor;
14
+ this.strokeColor = strokeColor;
15
+ this.fillOpacity = fillOpacity;
16
+ this.strokeOpacity = strokeOpacity;
17
+ }
18
+
19
+ getId() {
20
+ return this.name;
21
+ }
22
+ }
package/src/store.js CHANGED
@@ -1,74 +1,74 @@
1
- const store = {
2
- products: [],
3
- currentProduct: null,
4
- currentEntity: null,
5
- lastGeneratedProduct: null,
6
- };
7
-
8
- function getProducts() {
9
- return store.products;
10
- }
11
-
12
- function getCurrentProduct() {
13
- return store.currentProduct;
14
- }
15
-
16
- function setCurrentProduct(productName) {
17
- if (!productName) {
18
- store.currentProduct = null;
19
- } else {
20
- store.currentProduct = getProduct(productName);
21
- if (!store.currentProduct) {
22
- throw `GIS ${productName} does not exist!!!`;
23
- }
24
- }
25
- }
26
-
27
- function getCurrentEntity() {
28
- return store.currentEntity;
29
- }
30
-
31
- function setCurrentEntity(entityName) {
32
- if (!entityName) {
33
- store.currentEntity = null;
34
- } else {
35
- store.currentEntity = getCurrentProduct().getEntity(entityName);
36
- if (!store.currentEntity) {
37
- throw `Entity ${entityName} does not exist in current product!!!`;
38
- }
39
- }
40
- }
41
-
42
- function getProduct(name) {
43
- return store.products.find((e) => e.name == name);
44
- }
45
-
46
- function addProduct(id, product) {
47
- store.products.push(product);
48
- }
49
-
50
- function getLastGeneratedProduct() {
51
- return store.lastGeneratedProduct;
52
- }
53
-
54
- function setLastGeneratedProduct(generatedProduct) {
55
- store.lastGeneratedProduct = generatedProduct;
56
- }
57
-
58
- function reset() {
59
- store.products.splice(0, store.products.length);
60
- store.lastGeneratedProduct = null;
61
- }
62
-
63
- export default {
64
- getCurrentProduct,
65
- setCurrentProduct,
66
- getCurrentEntity,
67
- setCurrentEntity,
68
- getProducts,
69
- getProduct,
70
- addProduct,
71
- getLastGeneratedProduct,
72
- setLastGeneratedProduct,
73
- reset,
74
- };
1
+ const store = {
2
+ products: [],
3
+ currentProduct: null,
4
+ currentEntity: null,
5
+ lastGeneratedProduct: null,
6
+ };
7
+
8
+ function getProducts() {
9
+ return store.products;
10
+ }
11
+
12
+ function getCurrentProduct() {
13
+ return store.currentProduct;
14
+ }
15
+
16
+ function setCurrentProduct(productName) {
17
+ if (!productName) {
18
+ store.currentProduct = null;
19
+ } else {
20
+ store.currentProduct = getProduct(productName);
21
+ if (!store.currentProduct) {
22
+ throw `GIS ${productName} does not exist!!!`;
23
+ }
24
+ }
25
+ }
26
+
27
+ function getCurrentEntity() {
28
+ return store.currentEntity;
29
+ }
30
+
31
+ function setCurrentEntity(entityName) {
32
+ if (!entityName) {
33
+ store.currentEntity = null;
34
+ } else {
35
+ store.currentEntity = getCurrentProduct().getEntity(entityName);
36
+ if (!store.currentEntity) {
37
+ throw `Entity ${entityName} does not exist in current product!!!`;
38
+ }
39
+ }
40
+ }
41
+
42
+ function getProduct(name) {
43
+ return store.products.find((e) => e.name == name);
44
+ }
45
+
46
+ function addProduct(id, product) {
47
+ store.products.push(product);
48
+ }
49
+
50
+ function getLastGeneratedProduct() {
51
+ return store.lastGeneratedProduct;
52
+ }
53
+
54
+ function setLastGeneratedProduct(generatedProduct) {
55
+ store.lastGeneratedProduct = generatedProduct;
56
+ }
57
+
58
+ function reset() {
59
+ store.products.splice(0, store.products.length);
60
+ store.lastGeneratedProduct = null;
61
+ }
62
+
63
+ export default {
64
+ getCurrentProduct,
65
+ setCurrentProduct,
66
+ getCurrentEntity,
67
+ setCurrentEntity,
68
+ getProducts,
69
+ getProduct,
70
+ addProduct,
71
+ getLastGeneratedProduct,
72
+ setLastGeneratedProduct,
73
+ reset,
74
+ };
@@ -0,0 +1,120 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import parse from './src/index.js';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+
9
+ const examplesDir = path.join(__dirname, 'examples');
10
+
11
+ // ANSI color codes for console output
12
+ const colors = {
13
+ reset: '\x1b[0m',
14
+ green: '\x1b[32m',
15
+ red: '\x1b[31m',
16
+ yellow: '\x1b[33m',
17
+ cyan: '\x1b[36m',
18
+ bold: '\x1b[1m'
19
+ };
20
+
21
+ function testExample(filePath, fileName) {
22
+ console.log(`\n${colors.cyan}${colors.bold}Testing: ${fileName}${colors.reset}`);
23
+ console.log('='.repeat(60));
24
+
25
+ try {
26
+ // Read the file
27
+ const content = fs.readFileSync(filePath, 'utf8');
28
+ console.log(`${colors.yellow}File size: ${content.length} characters${colors.reset}`);
29
+
30
+ // Parse the content
31
+ const result = parse(content, false);
32
+
33
+ // Check if parsing was successful
34
+ if (result) {
35
+ console.log(`${colors.green}✓ PASSED${colors.reset} - Successfully parsed and generated product`);
36
+
37
+ // Display some basic info about the result if available
38
+ if (result.name) {
39
+ console.log(` Product name: ${result.name}`);
40
+ }
41
+ if (result.entities && result.entities.length > 0) {
42
+ console.log(` Entities: ${result.entities.length}`);
43
+ }
44
+ if (result.layers && result.layers.length > 0) {
45
+ console.log(` Layers: ${result.layers.length}`);
46
+ }
47
+ if (result.maps && result.maps.length > 0) {
48
+ console.log(` Maps: ${result.maps.length}`);
49
+ }
50
+
51
+ fs.writeFileSync(path.join(__dirname, 'test-output', `${fileName.replace('.txt', '.json')}`), JSON.stringify(result, null, 2));
52
+
53
+ return { success: true, fileName };
54
+ } else {
55
+ console.log(`${colors.yellow}⚠ WARNING${colors.reset} - Parsed but no product generated`);
56
+ return { success: true, fileName, warning: true };
57
+ }
58
+ } catch (error) {
59
+ console.log(`${colors.red}✗ FAILED${colors.reset} - Error during parsing`);
60
+ console.log(` Error: ${error.message}`);
61
+ if (error.stack) {
62
+ console.log(` Stack trace:\n${error.stack.split('\n').slice(0, 5).join('\n')}`);
63
+ }
64
+ return { success: false, fileName, error: error.message };
65
+ }
66
+ }
67
+
68
+ function main() {
69
+ console.log(`${colors.bold}${colors.cyan}\n╔════════════════════════════════════════════════════════════╗`);
70
+ console.log(`║ GIS DSL Example Validation Test Suite ║`);
71
+ console.log(`╚════════════════════════════════════════════════════════════╝${colors.reset}\n`);
72
+
73
+ // Get all .txt files in the examples directory
74
+ const files = fs.readdirSync(examplesDir)
75
+ .filter(file => file.endsWith('.txt'))
76
+ .sort();
77
+
78
+ console.log(`Found ${files.length} example file(s) to test\n`);
79
+
80
+ const results = [];
81
+
82
+ // Test each file
83
+ for (const file of files) {
84
+ const filePath = path.join(examplesDir, file);
85
+ const result = testExample(filePath, file);
86
+ results.push(result);
87
+ }
88
+
89
+ // Summary
90
+ console.log(`\n${colors.bold}${colors.cyan}${'='.repeat(60)}`);
91
+ console.log('TEST SUMMARY');
92
+ console.log(`${'='.repeat(60)}${colors.reset}\n`);
93
+
94
+ const passed = results.filter(r => r.success && !r.warning).length;
95
+ const warnings = results.filter(r => r.success && r.warning).length;
96
+ const failed = results.filter(r => !r.success).length;
97
+
98
+ console.log(`${colors.green}Passed: ${passed}${colors.reset}`);
99
+ if (warnings > 0) {
100
+ console.log(`${colors.yellow}Warnings: ${warnings}${colors.reset}`);
101
+ }
102
+ if (failed > 0) {
103
+ console.log(`${colors.red}Failed: ${failed}${colors.reset}`);
104
+ }
105
+ console.log(`Total: ${results.length}\n`);
106
+
107
+ // List failed tests if any
108
+ if (failed > 0) {
109
+ console.log(`${colors.red}${colors.bold}Failed tests:${colors.reset}`);
110
+ results.filter(r => !r.success).forEach(r => {
111
+ console.log(` ${colors.red}✗${colors.reset} ${r.fileName}: ${r.error}`);
112
+ });
113
+ console.log();
114
+ }
115
+
116
+ // Exit with appropriate code
117
+ process.exit(failed > 0 ? 1 : 0);
118
+ }
119
+
120
+ main();