rng 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/.rubocop_todo.yml +64 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/Gemfile +3 -1
- data/README.adoc +402 -0
- data/lib/rng/any_name.rb +26 -0
- data/lib/rng/attribute.rb +58 -4
- data/lib/rng/choice.rb +60 -0
- data/lib/rng/data.rb +32 -0
- data/lib/rng/define.rb +51 -3
- data/lib/rng/element.rb +62 -16
- data/lib/rng/empty.rb +23 -0
- data/lib/rng/except.rb +62 -0
- data/lib/rng/external_ref.rb +28 -0
- data/lib/rng/grammar.rb +36 -0
- data/lib/rng/group.rb +60 -0
- data/lib/rng/include.rb +24 -0
- data/lib/rng/interleave.rb +58 -0
- data/lib/rng/list.rb +56 -0
- data/lib/rng/mixed.rb +58 -0
- data/lib/rng/name.rb +28 -0
- data/lib/rng/not_allowed.rb +23 -0
- data/lib/rng/ns_name.rb +31 -0
- data/lib/rng/one_or_more.rb +58 -0
- data/lib/rng/optional.rb +58 -0
- data/lib/rng/param.rb +30 -0
- data/lib/rng/parent_ref.rb +28 -0
- data/lib/rng/parse_rnc.rb +26 -0
- data/lib/rng/pattern.rb +24 -0
- data/lib/rng/ref.rb +28 -0
- data/lib/rng/rnc_parser.rb +351 -94
- data/lib/rng/start.rb +54 -5
- data/lib/rng/text.rb +26 -0
- data/lib/rng/to_rnc.rb +55 -0
- data/lib/rng/value.rb +29 -0
- data/lib/rng/version.rb +1 -1
- data/lib/rng/zero_or_more.rb +58 -0
- data/lib/rng.rb +29 -5
- data/rng.gemspec +3 -2
- data/spec/fixtures/rnc/address_book.rnc +10 -0
- data/spec/fixtures/rnc/complex_example.rnc +61 -0
- data/spec/fixtures/rng/address_book.rng +20 -0
- data/spec/fixtures/rng/relaxng.rng +335 -0
- data/spec/fixtures/rng/testSuite.rng +163 -0
- data/spec/fixtures/spectest.xml +6845 -0
- data/spec/rng/rnc_parser_spec.rb +6 -4
- data/spec/rng/rnc_roundtrip_spec.rb +121 -0
- data/spec/rng/schema_spec.rb +115 -166
- data/spec/rng/spectest_spec.rb +195 -0
- data/spec/spec_helper.rb +33 -0
- metadata +54 -7
- data/lib/rng/builder.rb +0 -158
- data/lib/rng/rng_parser.rb +0 -107
- data/lib/rng/schema.rb +0 -18
- data/spec/rng/rng_parser_spec.rb +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6098b94d05fc5d4051353c56c3506280514394551876755c300e3926ba514501
|
4
|
+
data.tar.gz: 588a13fd65f9aae5c317ff64c69a9d567fdbbe586ca4cf94b8c234888c3a0b11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59de0a086d49d26a332e3ffda73eb81b4873ea9ff45ecaf97e78b2fcda7e477650abf726e8be5d1623bcf8176aec74d6c5e4b336d75549f8ea973dba4328d3e8
|
7
|
+
data.tar.gz: 1bea4dfb461300942a4f677a352ddc5801833bb915ea16656b2cf86ad07e62414c9a0bb426ae765731ce8361e1c0a30348314434c1dcf2dfb7a2d7b031fef479
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2025-06-13 04:55:12 UTC using RuboCop version 1.76.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# This cop supports safe autocorrection (--autocorrect).
|
11
|
+
Layout/EmptyLineAfterGuardClause:
|
12
|
+
Exclude:
|
13
|
+
- 'spec/rng/spectest_spec.rb'
|
14
|
+
|
15
|
+
# Offense count: 2
|
16
|
+
# This cop supports safe autocorrection (--autocorrect).
|
17
|
+
# Configuration parameters: AutoCorrect, AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods, NotImplementedExceptions.
|
18
|
+
# NotImplementedExceptions: NotImplementedError
|
19
|
+
Lint/UnusedMethodArgument:
|
20
|
+
Exclude:
|
21
|
+
- 'lib/rng.rb'
|
22
|
+
|
23
|
+
# Offense count: 7
|
24
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
25
|
+
Metrics/AbcSize:
|
26
|
+
Max: 95
|
27
|
+
|
28
|
+
# Offense count: 23
|
29
|
+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
30
|
+
# AllowedMethods: refine
|
31
|
+
Metrics/BlockLength:
|
32
|
+
Max: 109
|
33
|
+
|
34
|
+
# Offense count: 2
|
35
|
+
# Configuration parameters: CountComments, CountAsOne.
|
36
|
+
Metrics/ClassLength:
|
37
|
+
Max: 167
|
38
|
+
|
39
|
+
# Offense count: 5
|
40
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
41
|
+
Metrics/CyclomaticComplexity:
|
42
|
+
Max: 29
|
43
|
+
|
44
|
+
# Offense count: 8
|
45
|
+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
46
|
+
Metrics/MethodLength:
|
47
|
+
Max: 86
|
48
|
+
|
49
|
+
# Offense count: 4
|
50
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
51
|
+
Metrics/PerceivedComplexity:
|
52
|
+
Max: 27
|
53
|
+
|
54
|
+
# Offense count: 31
|
55
|
+
# Configuration parameters: AllowedConstants.
|
56
|
+
Style/Documentation:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
# Offense count: 1
|
60
|
+
# This cop supports safe autocorrection (--autocorrect).
|
61
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
|
62
|
+
# URISchemes: http, https
|
63
|
+
Layout/LineLength:
|
64
|
+
Max: 261
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/Gemfile
CHANGED
@@ -5,12 +5,14 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in rng.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
+
gem "diffy" # For generating human-readable diffs
|
8
9
|
gem "equivalent-xml"
|
10
|
+
gem "lutaml-model"
|
9
11
|
gem "nokogiri"
|
10
|
-
gem "xml-c14n"
|
11
12
|
gem "rake", "~> 13.0"
|
12
13
|
gem "rspec", "~> 3.0"
|
13
14
|
gem "rubocop", "~> 1.21"
|
14
15
|
gem "rubocop-performance", require: false
|
15
16
|
gem "rubocop-rake", require: false
|
16
17
|
gem "rubocop-rspec", require: false
|
18
|
+
gem "xml-c14n"
|
data/README.adoc
ADDED
@@ -0,0 +1,402 @@
|
|
1
|
+
= RNG: RELAX NG Schema Processing for Ruby
|
2
|
+
:toc: macro
|
3
|
+
:toclevels: 3
|
4
|
+
:toc-title: Contents
|
5
|
+
:source-highlighter: highlight.js
|
6
|
+
|
7
|
+
image:https://github.com/lutaml/rng/workflows/rake/badge.svg["Build Status", link="https://github.com/lutaml/rng/actions?workflow=rake"]
|
8
|
+
|
9
|
+
toc::[]
|
10
|
+
|
11
|
+
== Introduction and purpose
|
12
|
+
|
13
|
+
RNG provides Ruby tools for working with RELAX NG schemas, supporting both the XML syntax (RNG) and the compact syntax (RNC). It allows parsing, manipulation, and generation of RELAX NG schemas through an intuitive Ruby API.
|
14
|
+
|
15
|
+
Key features:
|
16
|
+
|
17
|
+
* Parse RELAX NG XML (.rng) and Compact (.rnc) syntax
|
18
|
+
* Programmatically build RELAX NG schemas
|
19
|
+
* Convert between XML and compact notations
|
20
|
+
* Object model representing RELAX NG concepts
|
21
|
+
* Integration with the LutaML ecosystem
|
22
|
+
|
23
|
+
== Getting started
|
24
|
+
|
25
|
+
Install the gem:
|
26
|
+
|
27
|
+
[source,ruby]
|
28
|
+
----
|
29
|
+
# In your Gemfile
|
30
|
+
gem 'rng'
|
31
|
+
----
|
32
|
+
|
33
|
+
=== Parsing RNG schemas
|
34
|
+
|
35
|
+
[source,ruby]
|
36
|
+
----
|
37
|
+
require 'rng'
|
38
|
+
|
39
|
+
# Parse from XML syntax
|
40
|
+
schema = Rng.parse(File.read('example.rng'))
|
41
|
+
|
42
|
+
# Access schema components
|
43
|
+
if schema.element
|
44
|
+
# Simple element pattern
|
45
|
+
puts "Root element: #{schema.element.name}"
|
46
|
+
else
|
47
|
+
# Grammar with named patterns
|
48
|
+
start_element = schema.start.element
|
49
|
+
puts "Root element: #{start_element.name}"
|
50
|
+
end
|
51
|
+
----
|
52
|
+
|
53
|
+
=== Parsing RNC schemas
|
54
|
+
|
55
|
+
[source,ruby]
|
56
|
+
----
|
57
|
+
require 'rng'
|
58
|
+
|
59
|
+
# Parse from compact syntax
|
60
|
+
schema = Rng.parse_rnc(File.read('example.rnc'))
|
61
|
+
|
62
|
+
# Access schema components
|
63
|
+
if schema.element
|
64
|
+
# Simple element pattern
|
65
|
+
puts "Root element: #{schema.element.name}"
|
66
|
+
else
|
67
|
+
# Grammar with named patterns
|
68
|
+
start_element = schema.start.element
|
69
|
+
puts "Root element: #{start_element.name}"
|
70
|
+
end
|
71
|
+
----
|
72
|
+
|
73
|
+
=== Converting between formats
|
74
|
+
|
75
|
+
[source,ruby]
|
76
|
+
----
|
77
|
+
require 'rng'
|
78
|
+
|
79
|
+
# Parse RNG and convert to RNC
|
80
|
+
schema = Rng.parse(File.read('example.rng'))
|
81
|
+
rnc = Rng.to_rnc(schema)
|
82
|
+
File.write('example.rnc', rnc)
|
83
|
+
|
84
|
+
# Parse RNC and get RNG XML
|
85
|
+
schema = Rng.parse_rnc(File.read('example.rnc'))
|
86
|
+
rng_xml = Rng::RncParser.parse(File.read('example.rnc'))
|
87
|
+
File.write('example.rng', rng_xml)
|
88
|
+
----
|
89
|
+
|
90
|
+
=== Building schemas programmatically
|
91
|
+
|
92
|
+
[source,ruby]
|
93
|
+
----
|
94
|
+
require 'rng'
|
95
|
+
|
96
|
+
# Create a schema with an address element
|
97
|
+
schema = Rng::Grammar.new
|
98
|
+
schema.element = Rng::Element.new(
|
99
|
+
name: "address"
|
100
|
+
)
|
101
|
+
|
102
|
+
# Add attributes
|
103
|
+
schema.element.attribute = Rng::Attribute.new(
|
104
|
+
name: "id"
|
105
|
+
)
|
106
|
+
schema.element.attribute.data = Rng::Data.new(
|
107
|
+
type: "ID"
|
108
|
+
)
|
109
|
+
|
110
|
+
# Add child elements
|
111
|
+
name_element = Rng::Element.new(name: "name")
|
112
|
+
name_element.text = Rng::Text.new
|
113
|
+
|
114
|
+
street_element = Rng::Element.new(name: "street")
|
115
|
+
street_element.text = Rng::Text.new
|
116
|
+
|
117
|
+
city_element = Rng::Element.new(name: "city")
|
118
|
+
city_element.text = Rng::Text.new
|
119
|
+
|
120
|
+
# Add child elements to parent
|
121
|
+
schema.element.element = [name_element, street_element, city_element]
|
122
|
+
|
123
|
+
# Convert to RNC format
|
124
|
+
rnc = Rng.to_rnc(schema)
|
125
|
+
File.write('address.rnc', rnc)
|
126
|
+
----
|
127
|
+
|
128
|
+
== Schema object model
|
129
|
+
|
130
|
+
=== Grammar
|
131
|
+
|
132
|
+
The Grammar class represents a complete RELAX NG schema:
|
133
|
+
|
134
|
+
[source,ruby]
|
135
|
+
----
|
136
|
+
# Simple element pattern
|
137
|
+
schema = Rng::Grammar.new(
|
138
|
+
element: Rng::Element.new(...)
|
139
|
+
)
|
140
|
+
|
141
|
+
# Grammar with named patterns
|
142
|
+
schema = Rng::Grammar.new(
|
143
|
+
start: Rng::Start.new(...),
|
144
|
+
define: [Rng::Define.new(...), ...],
|
145
|
+
datatypeLibrary: "http://www.w3.org/2001/XMLSchema-datatypes"
|
146
|
+
)
|
147
|
+
----
|
148
|
+
|
149
|
+
=== Start
|
150
|
+
|
151
|
+
The Start class defines the entry point of a schema:
|
152
|
+
|
153
|
+
[source,ruby]
|
154
|
+
----
|
155
|
+
start = Rng::Start.new(
|
156
|
+
ref: Rng::Ref.new(name: "addressDef"), # Reference to a named pattern
|
157
|
+
element: Rng::Element.new(...), # Inline element definition
|
158
|
+
choice: Rng::Choice.new(...), # Choice pattern
|
159
|
+
group: Rng::Group.new(...) # Group pattern
|
160
|
+
)
|
161
|
+
----
|
162
|
+
|
163
|
+
=== Define
|
164
|
+
|
165
|
+
Define represents named pattern definitions:
|
166
|
+
|
167
|
+
[source,ruby]
|
168
|
+
----
|
169
|
+
define = Rng::Define.new(
|
170
|
+
name: "addressDef",
|
171
|
+
element: Rng::Element.new(...),
|
172
|
+
choice: Rng::Choice.new(...),
|
173
|
+
group: Rng::Group.new(...)
|
174
|
+
)
|
175
|
+
----
|
176
|
+
|
177
|
+
=== Element
|
178
|
+
|
179
|
+
Element represents XML elements in the schema:
|
180
|
+
|
181
|
+
[source,ruby]
|
182
|
+
----
|
183
|
+
element = Rng::Element.new(
|
184
|
+
name: "address",
|
185
|
+
attribute: Rng::Attribute.new(...), # Attribute definition
|
186
|
+
element: Rng::Element.new(...), # Child element definition
|
187
|
+
text: Rng::Text.new, # Text content
|
188
|
+
zeroOrMore: Rng::ZeroOrMore.new(...), # Elements that can appear zero or more times
|
189
|
+
oneOrMore: Rng::OneOrMore.new(...), # Elements that must appear at least once
|
190
|
+
optional: Rng::Optional.new(...) # Optional elements
|
191
|
+
)
|
192
|
+
----
|
193
|
+
|
194
|
+
=== Attribute
|
195
|
+
|
196
|
+
Attribute defines attributes for elements:
|
197
|
+
|
198
|
+
[source,ruby]
|
199
|
+
----
|
200
|
+
attribute = Rng::Attribute.new(
|
201
|
+
name: "id",
|
202
|
+
data: Rng::Data.new(type: "ID") # XML Schema datatype
|
203
|
+
)
|
204
|
+
----
|
205
|
+
|
206
|
+
=== Pattern Classes
|
207
|
+
|
208
|
+
The library includes classes for all RELAX NG patterns:
|
209
|
+
|
210
|
+
* `Rng::Choice` - Represents a choice between patterns
|
211
|
+
* `Rng::Group` - Represents a sequence of patterns
|
212
|
+
* `Rng::Interleave` - Represents patterns that can be interleaved
|
213
|
+
* `Rng::Mixed` - Represents mixed content (text and elements)
|
214
|
+
* `Rng::Optional` - Represents an optional pattern
|
215
|
+
* `Rng::ZeroOrMore` - Represents a pattern that can occur zero or more times
|
216
|
+
* `Rng::OneOrMore` - Represents a pattern that must occur at least once
|
217
|
+
* `Rng::Text` - Represents text content
|
218
|
+
* `Rng::Empty` - Represents empty content
|
219
|
+
* `Rng::Value` - Represents a specific value
|
220
|
+
* `Rng::Data` - Represents a datatype
|
221
|
+
* `Rng::List` - Represents a list of values
|
222
|
+
* `Rng::Ref` - Represents a reference to a named pattern
|
223
|
+
* `Rng::ParentRef` - Represents a reference to a pattern in a parent grammar
|
224
|
+
* `Rng::ExternalRef` - Represents a reference to a pattern in an external grammar
|
225
|
+
* `Rng::NotAllowed` - Represents a pattern that is not allowed
|
226
|
+
|
227
|
+
== Schema formats
|
228
|
+
|
229
|
+
=== RELAX NG XML syntax (RNG)
|
230
|
+
|
231
|
+
XML syntax is the canonical form of RELAX NG schemas:
|
232
|
+
|
233
|
+
[source,xml]
|
234
|
+
----
|
235
|
+
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
|
236
|
+
<start>
|
237
|
+
<element name="address">
|
238
|
+
<attribute name="id">
|
239
|
+
<data type="ID"/>
|
240
|
+
</attribute>
|
241
|
+
<element name="name">
|
242
|
+
<text/>
|
243
|
+
</element>
|
244
|
+
<element name="street">
|
245
|
+
<text/>
|
246
|
+
</element>
|
247
|
+
<element name="city">
|
248
|
+
<text/>
|
249
|
+
</element>
|
250
|
+
</element>
|
251
|
+
</start>
|
252
|
+
</grammar>
|
253
|
+
----
|
254
|
+
|
255
|
+
=== RELAX NG Compact syntax (RNC)
|
256
|
+
|
257
|
+
Compact syntax provides a more readable alternative:
|
258
|
+
|
259
|
+
[source,rnc]
|
260
|
+
----
|
261
|
+
element address {
|
262
|
+
attribute id { text },
|
263
|
+
element name { text },
|
264
|
+
element street { text },
|
265
|
+
element city { text }
|
266
|
+
}
|
267
|
+
----
|
268
|
+
|
269
|
+
== Advanced usage
|
270
|
+
|
271
|
+
=== Working with complex patterns
|
272
|
+
|
273
|
+
[source,ruby]
|
274
|
+
----
|
275
|
+
require 'rng'
|
276
|
+
|
277
|
+
# Create a schema with choice patterns
|
278
|
+
schema = Rng::Grammar.new
|
279
|
+
schema.start = Rng::Start.new
|
280
|
+
|
281
|
+
# Create a choice between two elements
|
282
|
+
choice = Rng::Choice.new
|
283
|
+
choice.element = []
|
284
|
+
|
285
|
+
# First option: name element
|
286
|
+
name_element = Rng::Element.new(name: "name")
|
287
|
+
name_element.text = Rng::Text.new
|
288
|
+
choice.element << name_element
|
289
|
+
|
290
|
+
# Second option: first name and last name elements
|
291
|
+
first_name = Rng::Element.new(name: "firstName")
|
292
|
+
first_name.text = Rng::Text.new
|
293
|
+
|
294
|
+
last_name = Rng::Element.new(name: "lastName")
|
295
|
+
last_name.text = Rng::Text.new
|
296
|
+
|
297
|
+
# Group the first name and last name elements
|
298
|
+
group = Rng::Group.new
|
299
|
+
group.element = [first_name, last_name]
|
300
|
+
|
301
|
+
# Add the group as the second choice
|
302
|
+
choice.group = [group]
|
303
|
+
|
304
|
+
# Add the choice to the start element
|
305
|
+
schema.start.choice = choice
|
306
|
+
|
307
|
+
# Convert to RNC format
|
308
|
+
rnc = Rng.to_rnc(schema)
|
309
|
+
puts rnc
|
310
|
+
----
|
311
|
+
|
312
|
+
=== Working with named patterns
|
313
|
+
|
314
|
+
[source,ruby]
|
315
|
+
----
|
316
|
+
require 'rng'
|
317
|
+
|
318
|
+
# Create a schema with named patterns
|
319
|
+
schema = Rng::Grammar.new
|
320
|
+
schema.start = Rng::Start.new
|
321
|
+
|
322
|
+
# Create a reference to a named pattern
|
323
|
+
ref = Rng::Ref.new(name: "addressDef")
|
324
|
+
schema.start.ref = ref
|
325
|
+
|
326
|
+
# Define the named pattern
|
327
|
+
define = Rng::Define.new(name: "addressDef")
|
328
|
+
schema.define = [define]
|
329
|
+
|
330
|
+
# Add an element to the named pattern
|
331
|
+
element = Rng::Element.new(name: "address")
|
332
|
+
element.attribute = Rng::Attribute.new(name: "id")
|
333
|
+
element.attribute.data = Rng::Data.new(type: "ID")
|
334
|
+
|
335
|
+
# Add child elements
|
336
|
+
name_element = Rng::Element.new(name: "name")
|
337
|
+
name_element.text = Rng::Text.new
|
338
|
+
element.element = [name_element]
|
339
|
+
|
340
|
+
# Add the element to the named pattern
|
341
|
+
define.element = element
|
342
|
+
|
343
|
+
# Convert to RNC format
|
344
|
+
rnc = Rng.to_rnc(schema)
|
345
|
+
puts rnc
|
346
|
+
----
|
347
|
+
|
348
|
+
=== Working with cardinality constraints
|
349
|
+
|
350
|
+
[source,ruby]
|
351
|
+
----
|
352
|
+
require 'rng'
|
353
|
+
|
354
|
+
# Create a schema with cardinality constraints
|
355
|
+
schema = Rng::Grammar.new
|
356
|
+
schema.element = Rng::Element.new(name: "addressBook")
|
357
|
+
|
358
|
+
# Create a card element that can appear zero or more times
|
359
|
+
zero_or_more = Rng::ZeroOrMore.new
|
360
|
+
card_element = Rng::Element.new(name: "card")
|
361
|
+
|
362
|
+
# Add child elements to the card element
|
363
|
+
name_element = Rng::Element.new(name: "name")
|
364
|
+
name_element.text = Rng::Text.new
|
365
|
+
|
366
|
+
email_element = Rng::Element.new(name: "email")
|
367
|
+
email_element.text = Rng::Text.new
|
368
|
+
|
369
|
+
# Create an optional note element
|
370
|
+
optional = Rng::Optional.new
|
371
|
+
note_element = Rng::Element.new(name: "note")
|
372
|
+
note_element.text = Rng::Text.new
|
373
|
+
optional.element = [note_element]
|
374
|
+
|
375
|
+
# Add the child elements to the card element
|
376
|
+
card_element.element = [name_element, email_element]
|
377
|
+
card_element.optional = optional
|
378
|
+
|
379
|
+
# Add the card element to the zero_or_more pattern
|
380
|
+
zero_or_more.element = [card_element]
|
381
|
+
|
382
|
+
# Add the zero_or_more pattern to the address book element
|
383
|
+
schema.element.zeroOrMore = zero_or_more
|
384
|
+
|
385
|
+
# Convert to RNC format
|
386
|
+
rnc = Rng.to_rnc(schema)
|
387
|
+
puts rnc
|
388
|
+
----
|
389
|
+
|
390
|
+
== Contributing
|
391
|
+
|
392
|
+
1. Fork the repository
|
393
|
+
2. Create your feature branch (`git checkout -b feature/my-new-feature`)
|
394
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
395
|
+
4. Push to the branch (`git push origin feature/my-new-feature`)
|
396
|
+
5. Create a new Pull Request
|
397
|
+
|
398
|
+
== License
|
399
|
+
|
400
|
+
Copyright (c) 2025 Ribose Inc.
|
401
|
+
|
402
|
+
This project is licensed under the BSD-2-Clause License.
|
data/lib/rng/any_name.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "lutaml/model"
|
4
|
+
|
5
|
+
module Rng
|
6
|
+
class AnyName < Lutaml::Model::Serializable
|
7
|
+
attribute :name, :string
|
8
|
+
attribute :id, :string
|
9
|
+
attribute :ns, :string
|
10
|
+
attribute :datatypeLibrary, :string
|
11
|
+
attribute :except, Except
|
12
|
+
|
13
|
+
xml do
|
14
|
+
root "anyName", ordered: true
|
15
|
+
map_attribute "name", to: :name
|
16
|
+
map_attribute "id", to: :id
|
17
|
+
map_attribute "ns", to: :ns, value_map: {
|
18
|
+
from: { empty: :empty, omitted: :omitted, nil: :nil },
|
19
|
+
to: { empty: :empty, omitted: :omitted, nil: :nil }
|
20
|
+
}
|
21
|
+
map_attribute "datatypeLibrary", to: :datatypeLibrary
|
22
|
+
|
23
|
+
map_element "except", to: :except
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|