@dbml/core 2.5.4 → 2.6.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.
Files changed (27) hide show
  1. package/lib/model_structure/field.js +3 -1
  2. package/lib/parse/ANTLR/ASTGeneration/AST.js +246 -0
  3. package/lib/parse/ANTLR/ASTGeneration/ParserErrorListener.js +40 -0
  4. package/lib/parse/ANTLR/ASTGeneration/SyntaxError.js +47 -0
  5. package/lib/parse/ANTLR/ASTGeneration/index.js +32 -0
  6. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLLexerBase.js +43 -0
  7. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgreSQLParserBase.js +37 -0
  8. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +1126 -0
  9. package/lib/parse/ANTLR/README.md +32 -0
  10. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.g4 +3044 -0
  11. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.interp +2074 -0
  12. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.js +882 -0
  13. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLLexer.tokens +1314 -0
  14. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +5506 -0
  15. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +2182 -0
  16. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +3 -0
  17. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +1314 -0
  18. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +5767 -0
  19. package/lib/parse/ANTLR/parsers/postgresql/README.md +10 -0
  20. package/lib/parse/Parser.js +9 -0
  21. package/lib/parse/dbml/parser.pegjs +2 -2
  22. package/lib/parse/dbmlParser.js +66 -103
  23. package/lib/parse/mysql/parser.pegjs +2 -2
  24. package/lib/parse/mysqlParser.js +281 -283
  25. package/package.json +5 -2
  26. package/types/import/index.d.ts +1 -1
  27. package/types/parse/Parser.d.ts +1 -0
@@ -0,0 +1,10 @@
1
+ Based on: https://github.com/antlr/grammars-v4/tree/master/sql/postgresql
2
+
3
+ These folder contain base classes, grammar files and auto-generated parser.
4
+
5
+ * PostgreSQLLexer.g4: lexer definition - copied from antlr/grammars-v4 repo
6
+ * PostgreSQLParser.g4: grammar definition - copied from antlr/grammars-v4 repo
7
+ * PostgreSQLLexer.interp, PostgreSQLLexer.js, PostgreSQLLexer.tokens, PostgreSQLParser.interp, PostgreSQLParser.js, PostgreSQLParser.tokens, PostgreSQLParserVisitor.js: Auto generated by the grammar
8
+ * PostgreSQLLexerBase.js, PostgreSQLParserBase.js: Contain simple base classes and helper funtions required by the grammar.
9
+
10
+ You don't need to touch these files unless you're planning on updating the grammar. In that case, read the setup guide to know more.
@@ -10,6 +10,7 @@ var _postgresParser = _interopRequireDefault(require("./postgresParser"));
10
10
  var _dbmlParser = _interopRequireDefault(require("./dbmlParser"));
11
11
  var _schemarbParser = _interopRequireDefault(require("./schemarbParser"));
12
12
  var _mssqlParser = _interopRequireDefault(require("./mssqlParser"));
13
+ var _ASTGeneration = require("./ANTLR/ASTGeneration");
13
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
15
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
15
16
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -32,6 +33,11 @@ var Parser = /*#__PURE__*/function () {
32
33
  value: function parseMySQLToJSON(str) {
33
34
  return _mysqlParser["default"].parse(str);
34
35
  }
36
+ }, {
37
+ key: "parsePostgresToJSONv2",
38
+ value: function parsePostgresToJSONv2(str) {
39
+ return (0, _ASTGeneration.parse)(str, 'postgres');
40
+ }
35
41
  }, {
36
42
  key: "parsePostgresToJSON",
37
43
  value: function parsePostgresToJSON(str) {
@@ -61,6 +67,9 @@ var Parser = /*#__PURE__*/function () {
61
67
  rawDatabase = Parser.parseMySQLToJSON(str);
62
68
  break;
63
69
  case 'postgres':
70
+ rawDatabase = Parser.parsePostgresToJSONv2(str);
71
+ break;
72
+ case 'postgresLegacy':
64
73
  rawDatabase = Parser.parsePostgresToJSON(str);
65
74
  break;
66
75
  case 'dbml':
@@ -532,8 +532,7 @@ CompositeIndex
532
532
  }
533
533
 
534
534
  IndexSettings
535
- = "[" sp* pk sp* "]" { return { pk: true } }
536
- / "[" first:IndexSetting rest:(Comma IndexSetting)* "]" {
535
+ = "[" first:IndexSetting rest:(Comma IndexSetting)* "]" {
537
536
  let arrSettings = [first].concat(rest.map(el => el[1]));
538
537
  let res = {};
539
538
  arrSettings.forEach((ele) => {
@@ -552,6 +551,7 @@ IndexSetting
552
551
  / _ v:IndexName _ { return { type: 'name', value: v } }
553
552
  / _ v:IndexType _ { return { type: 'type', value: v } }
554
553
  / _ v:ObjectNote _ { return { type: 'note', value: v } }
554
+ / _ pk _ { return { type: 'pk', value: true } }
555
555
  IndexName
556
556
  = "name:"i _ val:StringLiteral { return val.value }
557
557
  ObjectNoteElement
@@ -624,12 +624,7 @@ function peg$parse(input, options) {
624
624
  }));
625
625
  return arrIndex;
626
626
  },
627
- peg$c84 = function peg$c84() {
628
- return {
629
- pk: true
630
- };
631
- },
632
- peg$c85 = function peg$c85(first, rest) {
627
+ peg$c84 = function peg$c84(first, rest) {
633
628
  var arrSettings = [first].concat(rest.map(function (el) {
634
629
  return el[1];
635
630
  }));
@@ -643,18 +638,24 @@ function peg$parse(input, options) {
643
638
  });
644
639
  return res;
645
640
  },
646
- peg$c86 = function peg$c86(v) {
641
+ peg$c85 = function peg$c85(v) {
647
642
  return {
648
643
  type: 'name',
649
644
  value: v
650
645
  };
651
646
  },
652
- peg$c87 = function peg$c87(v) {
647
+ peg$c86 = function peg$c86(v) {
653
648
  return {
654
649
  type: 'type',
655
650
  value: v
656
651
  };
657
652
  },
653
+ peg$c87 = function peg$c87() {
654
+ return {
655
+ type: 'pk',
656
+ value: true
657
+ };
658
+ },
658
659
  peg$c88 = "name:",
659
660
  peg$c89 = peg$literalExpectation("name:", true),
660
661
  peg$c90 = function peg$c90(val) {
@@ -3800,70 +3801,26 @@ function peg$parse(input, options) {
3800
3801
  }
3801
3802
  }
3802
3803
  if (s1 !== peg$FAILED) {
3803
- s2 = [];
3804
- s3 = peg$parsesp();
3805
- while (s3 !== peg$FAILED) {
3806
- s2.push(s3);
3807
- s3 = peg$parsesp();
3808
- }
3804
+ s2 = peg$parseIndexSetting();
3809
3805
  if (s2 !== peg$FAILED) {
3810
- s3 = peg$parsepk();
3811
- if (s3 !== peg$FAILED) {
3812
- s4 = [];
3813
- s5 = peg$parsesp();
3814
- while (s5 !== peg$FAILED) {
3815
- s4.push(s5);
3816
- s5 = peg$parsesp();
3817
- }
3818
- if (s4 !== peg$FAILED) {
3819
- if (input.charCodeAt(peg$currPos) === 93) {
3820
- s5 = peg$c35;
3821
- peg$currPos++;
3822
- } else {
3823
- s5 = peg$FAILED;
3824
- if (peg$silentFails === 0) {
3825
- peg$fail(peg$c36);
3826
- }
3827
- }
3828
- if (s5 !== peg$FAILED) {
3829
- peg$savedPos = s0;
3830
- s1 = peg$c84();
3831
- s0 = s1;
3832
- } else {
3833
- peg$currPos = s0;
3834
- s0 = peg$FAILED;
3835
- }
3806
+ s3 = [];
3807
+ s4 = peg$currPos;
3808
+ s5 = peg$parseComma();
3809
+ if (s5 !== peg$FAILED) {
3810
+ s6 = peg$parseIndexSetting();
3811
+ if (s6 !== peg$FAILED) {
3812
+ s5 = [s5, s6];
3813
+ s4 = s5;
3836
3814
  } else {
3837
- peg$currPos = s0;
3838
- s0 = peg$FAILED;
3815
+ peg$currPos = s4;
3816
+ s4 = peg$FAILED;
3839
3817
  }
3840
3818
  } else {
3841
- peg$currPos = s0;
3842
- s0 = peg$FAILED;
3843
- }
3844
- } else {
3845
- peg$currPos = s0;
3846
- s0 = peg$FAILED;
3847
- }
3848
- } else {
3849
- peg$currPos = s0;
3850
- s0 = peg$FAILED;
3851
- }
3852
- if (s0 === peg$FAILED) {
3853
- s0 = peg$currPos;
3854
- if (input.charCodeAt(peg$currPos) === 91) {
3855
- s1 = peg$c33;
3856
- peg$currPos++;
3857
- } else {
3858
- s1 = peg$FAILED;
3859
- if (peg$silentFails === 0) {
3860
- peg$fail(peg$c34);
3819
+ peg$currPos = s4;
3820
+ s4 = peg$FAILED;
3861
3821
  }
3862
- }
3863
- if (s1 !== peg$FAILED) {
3864
- s2 = peg$parseIndexSetting();
3865
- if (s2 !== peg$FAILED) {
3866
- s3 = [];
3822
+ while (s4 !== peg$FAILED) {
3823
+ s3.push(s4);
3867
3824
  s4 = peg$currPos;
3868
3825
  s5 = peg$parseComma();
3869
3826
  if (s5 !== peg$FAILED) {
@@ -3879,42 +3836,21 @@ function peg$parse(input, options) {
3879
3836
  peg$currPos = s4;
3880
3837
  s4 = peg$FAILED;
3881
3838
  }
3882
- while (s4 !== peg$FAILED) {
3883
- s3.push(s4);
3884
- s4 = peg$currPos;
3885
- s5 = peg$parseComma();
3886
- if (s5 !== peg$FAILED) {
3887
- s6 = peg$parseIndexSetting();
3888
- if (s6 !== peg$FAILED) {
3889
- s5 = [s5, s6];
3890
- s4 = s5;
3891
- } else {
3892
- peg$currPos = s4;
3893
- s4 = peg$FAILED;
3894
- }
3895
- } else {
3896
- peg$currPos = s4;
3897
- s4 = peg$FAILED;
3839
+ }
3840
+ if (s3 !== peg$FAILED) {
3841
+ if (input.charCodeAt(peg$currPos) === 93) {
3842
+ s4 = peg$c35;
3843
+ peg$currPos++;
3844
+ } else {
3845
+ s4 = peg$FAILED;
3846
+ if (peg$silentFails === 0) {
3847
+ peg$fail(peg$c36);
3898
3848
  }
3899
3849
  }
3900
- if (s3 !== peg$FAILED) {
3901
- if (input.charCodeAt(peg$currPos) === 93) {
3902
- s4 = peg$c35;
3903
- peg$currPos++;
3904
- } else {
3905
- s4 = peg$FAILED;
3906
- if (peg$silentFails === 0) {
3907
- peg$fail(peg$c36);
3908
- }
3909
- }
3910
- if (s4 !== peg$FAILED) {
3911
- peg$savedPos = s0;
3912
- s1 = peg$c85(s2, s3);
3913
- s0 = s1;
3914
- } else {
3915
- peg$currPos = s0;
3916
- s0 = peg$FAILED;
3917
- }
3850
+ if (s4 !== peg$FAILED) {
3851
+ peg$savedPos = s0;
3852
+ s1 = peg$c84(s2, s3);
3853
+ s0 = s1;
3918
3854
  } else {
3919
3855
  peg$currPos = s0;
3920
3856
  s0 = peg$FAILED;
@@ -3927,6 +3863,9 @@ function peg$parse(input, options) {
3927
3863
  peg$currPos = s0;
3928
3864
  s0 = peg$FAILED;
3929
3865
  }
3866
+ } else {
3867
+ peg$currPos = s0;
3868
+ s0 = peg$FAILED;
3930
3869
  }
3931
3870
  return s0;
3932
3871
  }
@@ -3971,7 +3910,7 @@ function peg$parse(input, options) {
3971
3910
  s3 = peg$parse_();
3972
3911
  if (s3 !== peg$FAILED) {
3973
3912
  peg$savedPos = s0;
3974
- s1 = peg$c86(s2);
3913
+ s1 = peg$c85(s2);
3975
3914
  s0 = s1;
3976
3915
  } else {
3977
3916
  peg$currPos = s0;
@@ -3994,7 +3933,7 @@ function peg$parse(input, options) {
3994
3933
  s3 = peg$parse_();
3995
3934
  if (s3 !== peg$FAILED) {
3996
3935
  peg$savedPos = s0;
3997
- s1 = peg$c87(s2);
3936
+ s1 = peg$c86(s2);
3998
3937
  s0 = s1;
3999
3938
  } else {
4000
3939
  peg$currPos = s0;
@@ -4031,6 +3970,30 @@ function peg$parse(input, options) {
4031
3970
  peg$currPos = s0;
4032
3971
  s0 = peg$FAILED;
4033
3972
  }
3973
+ if (s0 === peg$FAILED) {
3974
+ s0 = peg$currPos;
3975
+ s1 = peg$parse_();
3976
+ if (s1 !== peg$FAILED) {
3977
+ s2 = peg$parsepk();
3978
+ if (s2 !== peg$FAILED) {
3979
+ s3 = peg$parse_();
3980
+ if (s3 !== peg$FAILED) {
3981
+ peg$savedPos = s0;
3982
+ s1 = peg$c87();
3983
+ s0 = s1;
3984
+ } else {
3985
+ peg$currPos = s0;
3986
+ s0 = peg$FAILED;
3987
+ }
3988
+ } else {
3989
+ peg$currPos = s0;
3990
+ s0 = peg$FAILED;
3991
+ }
3992
+ } else {
3993
+ peg$currPos = s0;
3994
+ s0 = peg$FAILED;
3995
+ }
3996
+ }
4034
3997
  }
4035
3998
  }
4036
3999
  }
@@ -456,8 +456,8 @@ ListOfNames = first:name rest:(comma _ name)*
456
456
 
457
457
  // Comment Syntax: Support "COMMENT 'this is a comment'"
458
458
  Comment
459
- = "COMMENT" _ ("=" _)? comment: "'" c:[^']* "'" {return c.join('')}
460
- / "COMMENT" _ ("=" _)? comment: "\"" c:[^"]* "\"" {return c.join('')}
459
+ = "COMMENT"i _ ("=" _)? comment: "'" c:[^']* "'" {return c.join('')}
460
+ / "COMMENT"i _ ("=" _)? comment: "\"" c:[^"]* "\"" {return c.join('')}
461
461
  // End of Useful Expression
462
462
 
463
463