-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b77e1f
commit 93cae78
Showing
53 changed files
with
3,710 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
...ava/io/github/sebastiantoepfer/jsonschema/vocabulary/format/assertion/abnf/CoreRules.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2023 sebastian. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package io.github.sebastiantoepfer.jsonschema.vocabulary.format.assertion.abnf; | ||
|
||
import io.github.sebastiantoepfer.jsonschema.vocabulary.format.assertion.abnf.element.Alternative; | ||
import io.github.sebastiantoepfer.jsonschema.vocabulary.format.assertion.abnf.element.Element; | ||
import io.github.sebastiantoepfer.jsonschema.vocabulary.format.assertion.abnf.element.NumericCharacter; | ||
import io.github.sebastiantoepfer.jsonschema.vocabulary.format.assertion.abnf.element.RuleName; | ||
import io.github.sebastiantoepfer.jsonschema.vocabulary.format.assertion.abnf.element.StringElement; | ||
import io.github.sebastiantoepfer.jsonschema.vocabulary.format.assertion.abnf.element.ValueRangeAlternatives; | ||
|
||
public enum CoreRules implements Element { | ||
ALPHA() { | ||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
return Alternative | ||
.of( | ||
ValueRangeAlternatives.of( | ||
NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x41), | ||
NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x51A) | ||
), | ||
ValueRangeAlternatives.of( | ||
NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x61), | ||
NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x7A) | ||
) | ||
) | ||
.isValidFor(codePoint); | ||
} | ||
}, | ||
BIT() { | ||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
return Alternative.of(StringElement.of("0"), StringElement.of("1")).isValidFor(codePoint); | ||
} | ||
}, | ||
CHAR() { | ||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
return ValueRangeAlternatives | ||
.of( | ||
NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x01), | ||
NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x7F) | ||
) | ||
.isValidFor(codePoint); | ||
} | ||
}, | ||
CR() { | ||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
return NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x0D).isValidFor(codePoint); | ||
} | ||
}, | ||
CRLF, //CR LF | ||
CTL, //%x00-1F / %x7F | ||
DIGIT() { | ||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
return ValueRangeAlternatives | ||
.of( | ||
NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x30), | ||
NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x39) | ||
) | ||
.isValidFor(codePoint); | ||
} | ||
}, | ||
DQUOTE() { | ||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
return NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x22).isValidFor(codePoint); | ||
} | ||
}, | ||
HEXDIG() { | ||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
return Alternative | ||
.of( | ||
DIGIT, | ||
StringElement.of("A"), | ||
StringElement.of("B"), | ||
StringElement.of("C"), | ||
StringElement.of("D"), | ||
StringElement.of("E"), | ||
StringElement.of("F") | ||
) | ||
.isValidFor(codePoint); | ||
} | ||
}, | ||
HTAB() { | ||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
return NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x09).isValidFor(codePoint); | ||
} | ||
}, | ||
LF() { | ||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
return NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x0A).isValidFor(codePoint); | ||
} | ||
}, | ||
LWSP, //*(WSP / CRLF WSP) | ||
OCTET() { | ||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
return ValueRangeAlternatives | ||
.of( | ||
NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x00), | ||
NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0xFF) | ||
) | ||
.isValidFor(codePoint); | ||
} | ||
}, | ||
SP() { | ||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
return NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x20).isValidFor(codePoint); | ||
} | ||
}, | ||
VCHAR() { | ||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
return ValueRangeAlternatives | ||
.of( | ||
NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x21), | ||
NumericCharacter.of(NumericCharacter.BASE.HEXADECIMAL, 0x7E) | ||
) | ||
.isValidFor(codePoint); | ||
} | ||
}, | ||
WSP { | ||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
return Alternative.of(SP, HTAB).isValidFor(codePoint); | ||
} | ||
}; | ||
|
||
public RuleName asRuleName() { | ||
return RuleName.of(name()); | ||
} | ||
|
||
@Override | ||
public boolean isValidFor(final int codePoint) { | ||
throw new UnsupportedOperationException("Not supported yet."); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...ain/java/io/github/sebastiantoepfer/jsonschema/vocabulary/format/assertion/abnf/Rule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2023 sebastian. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package io.github.sebastiantoepfer.jsonschema.vocabulary.format.assertion.abnf; | ||
|
||
import io.github.sebastiantoepfer.jsonschema.vocabulary.format.assertion.abnf.element.Element; | ||
import io.github.sebastiantoepfer.jsonschema.vocabulary.format.assertion.abnf.element.RuleName; | ||
import java.util.Objects; | ||
|
||
public final class Rule { | ||
|
||
public static Rule of(final RuleName name, final Element elements) { | ||
return new Rule(name, elements); | ||
} | ||
|
||
private final RuleName name; | ||
private final Element elements; | ||
|
||
private Rule(final RuleName name, final Element elements) { | ||
this.name = Objects.requireNonNull(name); | ||
this.elements = Objects.requireNonNull(elements); | ||
} | ||
|
||
public boolean hasRuleName(final RuleName name) { | ||
return Objects.equals(this.name, name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Rule{" + "name=" + name + ", elements=" + elements + '}'; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hash = 5; | ||
hash = 83 * hash + Objects.hashCode(this.name); | ||
hash = 83 * hash + Objects.hashCode(this.elements); | ||
return hash; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
final Rule other = (Rule) obj; | ||
if (!Objects.equals(this.name, other.name)) { | ||
return false; | ||
} | ||
return Objects.equals(this.elements, other.elements); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...java/io/github/sebastiantoepfer/jsonschema/vocabulary/format/assertion/abnf/RuleList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2023 sebastian. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package io.github.sebastiantoepfer.jsonschema.vocabulary.format.assertion.abnf; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public final class RuleList { | ||
|
||
public static RuleList of(final Rule rule, final Rule... rules) { | ||
final List<Rule> ruleList = new ArrayList<>(); | ||
ruleList.add(Objects.requireNonNull(rule)); | ||
ruleList.addAll(asList(rules)); | ||
return of(ruleList); | ||
} | ||
|
||
public static RuleList of(final List<Rule> rules) { | ||
return new RuleList(rules); | ||
} | ||
|
||
private final List<Rule> rules; | ||
|
||
private RuleList(final List<Rule> rules) { | ||
this.rules = List.copyOf(rules); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RuleList{" + "rules=" + rules + '}'; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hash = 7; | ||
hash = 73 * hash + Objects.hashCode(this.rules); | ||
return hash; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
final RuleList other = (RuleList) obj; | ||
return Objects.equals(this.rules, other.rules); | ||
} | ||
} |
Oops, something went wrong.