Skip to content

Commit

Permalink
Support constraints on custom datatypes (closes #158)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed Mar 3, 2022
1 parent d4f5364 commit b20d9f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,14 @@ enum class PlSqlGrammar : GrammarRuleKey {

b.rule(ANCHORED_DATATYPE).define(CUSTOM_DATATYPE, MOD, b.firstOf(TYPE, ROWTYPE))

b.rule(CUSTOM_DATATYPE).define(MEMBER_EXPRESSION)
b.rule(CUSTOM_DATATYPE).define(
MEMBER_EXPRESSION,
b.optional(b.firstOf(
b.sequence(LPARENTHESIS, b.firstOf(DATATYPE_LENGTH, MULTIPLICATION), b.optional(COMMA, b.optional(MINUS), DATATYPE_LENGTH), RPARENTHESIS),
b.sequence(
b.optional(LPARENTHESIS, DATATYPE_LENGTH, b.optional(b.firstOf(BYTE, CHAR)), RPARENTHESIS),
b.optional(CHARACTER_SET_CLAUSE))
)))

b.rule(REF_DATATYPE).define(REF, CUSTOM_DATATYPE)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class DatatypeTest : RuleTest() {
assertThat(p).matches("interval day(2) to second")
assertThat(p).matches("interval day to second(6)")
assertThat(p).matches("interval day(2) to second(6)")
assertThat(p).matches("my_datatype")
assertThat(p).matches("my_char(5)")
assertThat(p).matches("my_char(5 char)")
assertThat(p).matches("my_char character set any_cs")
assertThat(p).matches("my_number(10,2)")
}

}

0 comments on commit b20d9f0

Please sign in to comment.