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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/.rubocop_todo.yml +64 -0
  4. data/CODE_OF_CONDUCT.md +132 -0
  5. data/Gemfile +3 -1
  6. data/README.adoc +402 -0
  7. data/lib/rng/any_name.rb +26 -0
  8. data/lib/rng/attribute.rb +58 -4
  9. data/lib/rng/choice.rb +60 -0
  10. data/lib/rng/data.rb +32 -0
  11. data/lib/rng/define.rb +51 -3
  12. data/lib/rng/element.rb +62 -16
  13. data/lib/rng/empty.rb +23 -0
  14. data/lib/rng/except.rb +62 -0
  15. data/lib/rng/external_ref.rb +28 -0
  16. data/lib/rng/grammar.rb +36 -0
  17. data/lib/rng/group.rb +60 -0
  18. data/lib/rng/include.rb +24 -0
  19. data/lib/rng/interleave.rb +58 -0
  20. data/lib/rng/list.rb +56 -0
  21. data/lib/rng/mixed.rb +58 -0
  22. data/lib/rng/name.rb +28 -0
  23. data/lib/rng/not_allowed.rb +23 -0
  24. data/lib/rng/ns_name.rb +31 -0
  25. data/lib/rng/one_or_more.rb +58 -0
  26. data/lib/rng/optional.rb +58 -0
  27. data/lib/rng/param.rb +30 -0
  28. data/lib/rng/parent_ref.rb +28 -0
  29. data/lib/rng/parse_rnc.rb +26 -0
  30. data/lib/rng/pattern.rb +24 -0
  31. data/lib/rng/ref.rb +28 -0
  32. data/lib/rng/rnc_parser.rb +351 -94
  33. data/lib/rng/start.rb +54 -5
  34. data/lib/rng/text.rb +26 -0
  35. data/lib/rng/to_rnc.rb +55 -0
  36. data/lib/rng/value.rb +29 -0
  37. data/lib/rng/version.rb +1 -1
  38. data/lib/rng/zero_or_more.rb +58 -0
  39. data/lib/rng.rb +29 -5
  40. data/rng.gemspec +3 -2
  41. data/spec/fixtures/rnc/address_book.rnc +10 -0
  42. data/spec/fixtures/rnc/complex_example.rnc +61 -0
  43. data/spec/fixtures/rng/address_book.rng +20 -0
  44. data/spec/fixtures/rng/relaxng.rng +335 -0
  45. data/spec/fixtures/rng/testSuite.rng +163 -0
  46. data/spec/fixtures/spectest.xml +6845 -0
  47. data/spec/rng/rnc_parser_spec.rb +6 -4
  48. data/spec/rng/rnc_roundtrip_spec.rb +121 -0
  49. data/spec/rng/schema_spec.rb +115 -166
  50. data/spec/rng/spectest_spec.rb +195 -0
  51. data/spec/spec_helper.rb +33 -0
  52. metadata +54 -7
  53. data/lib/rng/builder.rb +0 -158
  54. data/lib/rng/rng_parser.rb +0 -107
  55. data/lib/rng/schema.rb +0 -18
  56. data/spec/rng/rng_parser_spec.rb +0 -102
data/lib/rng/mixed.rb ADDED
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Rng
6
+ class Mixed < Lutaml::Model::Serializable
7
+ attribute :id, :string
8
+ attribute :ns, :string
9
+ attribute :datatypeLibrary, :string
10
+ attribute :element, Element, collection: true, initialize_empty: true
11
+ attribute :attribute, Attribute, collection: true, initialize_empty: true
12
+ attribute :ref, Ref, collection: true, initialize_empty: true
13
+ attribute :choice, Choice, collection: true, initialize_empty: true
14
+ attribute :group, Group, collection: true, initialize_empty: true
15
+ attribute :interleave, Interleave, collection: true, initialize_empty: true
16
+ attribute :mixed, Mixed, collection: true, initialize_empty: true
17
+ attribute :optional, Optional, collection: true, initialize_empty: true
18
+ attribute :zeroOrMore, ZeroOrMore, collection: true, initialize_empty: true
19
+ attribute :oneOrMore, OneOrMore, collection: true, initialize_empty: true
20
+ attribute :text, Text, collection: true, initialize_empty: true
21
+ attribute :empty, Empty, collection: true, initialize_empty: true
22
+ attribute :value, Value, collection: true, initialize_empty: true
23
+ attribute :data, Data, collection: true, initialize_empty: true
24
+ attribute :list, List, collection: true, initialize_empty: true
25
+ attribute :notAllowed, NotAllowed, collection: true, initialize_empty: true
26
+
27
+ xml do
28
+ root "mixed", ordered: true
29
+ namespace "http://relaxng.org/ns/structure/1.0"
30
+
31
+ map_attribute "id", to: :id
32
+ map_attribute "ns", to: :ns, value_map: {
33
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
34
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
35
+ }
36
+ map_attribute "datatypeLibrary", to: :datatypeLibrary, value_map: {
37
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
38
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
39
+ }
40
+ map_element "element", to: :element
41
+ map_element "attribute", to: :attribute
42
+ map_element "ref", to: :ref
43
+ map_element "choice", to: :choice
44
+ map_element "group", to: :group
45
+ map_element "interleave", to: :interleave
46
+ map_element "mixed", to: :mixed
47
+ map_element "optional", to: :optional
48
+ map_element "zeroOrMore", to: :zeroOrMore
49
+ map_element "oneOrMore", to: :oneOrMore
50
+ map_element "text", to: :text
51
+ map_element "empty", to: :empty
52
+ map_element "value", to: :value
53
+ map_element "data", to: :data
54
+ map_element "list", to: :list
55
+ map_element "notAllowed", to: :notAllowed
56
+ end
57
+ end
58
+ end
data/lib/rng/name.rb ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Rng
6
+ class Name < Lutaml::Model::Serializable
7
+ attribute :id, :string
8
+ attribute :ns, :string
9
+ attribute :datatypeLibrary, :string
10
+ attribute :value, :string
11
+
12
+ xml do
13
+ root "name", ordered: true
14
+ namespace "http://relaxng.org/ns/structure/1.0"
15
+
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, value_map: {
22
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
23
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
24
+ }
25
+ map_content to: :value
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Rng
6
+ class NotAllowed < Lutaml::Model::Serializable
7
+ attribute :id, :string
8
+ attribute :ns, :string
9
+ attribute :datatypeLibrary, :string
10
+
11
+ xml do
12
+ root "notAllowed", ordered: true
13
+ namespace "http://relaxng.org/ns/structure/1.0"
14
+
15
+ map_attribute "id", to: :id
16
+ map_attribute "ns", to: :ns, value_map: {
17
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
18
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
19
+ }
20
+ map_attribute "datatypeLibrary", to: :datatypeLibrary
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Rng
6
+ class NsName < Lutaml::Model::Serializable
7
+ attribute :id, :string
8
+ attribute :ns, :string
9
+ attribute :datatypeLibrary, :string
10
+ attribute :name, :string
11
+ attribute :except, Except
12
+
13
+ xml do
14
+ root "nsName", ordered: true
15
+ namespace "http://relaxng.org/ns/structure/1.0"
16
+
17
+ map_attribute "id", to: :id
18
+ map_attribute "ns", to: :ns, value_map: {
19
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
20
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
21
+ }
22
+ map_attribute "datatypeLibrary", to: :datatypeLibrary, value_map: {
23
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
24
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
25
+ }
26
+ map_attribute "name", to: :name
27
+
28
+ map_element "except", to: :except
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Rng
6
+ class OneOrMore < Lutaml::Model::Serializable
7
+ attribute :id, :string
8
+ attribute :ns, :string
9
+ attribute :datatypeLibrary, :string
10
+ attribute :element, Element, collection: true, initialize_empty: true
11
+ attribute :attribute, Attribute, collection: true, initialize_empty: true
12
+ attribute :ref, Ref, collection: true, initialize_empty: true
13
+ attribute :choice, Choice, collection: true, initialize_empty: true
14
+ attribute :group, Group, collection: true, initialize_empty: true
15
+ attribute :interleave, Interleave, collection: true, initialize_empty: true
16
+ attribute :mixed, Mixed, collection: true, initialize_empty: true
17
+ attribute :optional, Optional, collection: true, initialize_empty: true
18
+ attribute :zeroOrMore, ZeroOrMore, collection: true, initialize_empty: true
19
+ attribute :oneOrMore, OneOrMore, collection: true, initialize_empty: true
20
+ attribute :text, Text, collection: true, initialize_empty: true
21
+ attribute :empty, Empty, collection: true, initialize_empty: true
22
+ attribute :value, Value, collection: true, initialize_empty: true
23
+ attribute :data, Data, collection: true, initialize_empty: true
24
+ attribute :list, List, collection: true, initialize_empty: true
25
+ attribute :notAllowed, NotAllowed, collection: true, initialize_empty: true
26
+
27
+ xml do
28
+ root "oneOrMore", ordered: true
29
+ namespace "http://relaxng.org/ns/structure/1.0"
30
+
31
+ map_attribute "id", to: :id
32
+ map_attribute "ns", to: :ns, value_map: {
33
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
34
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
35
+ }
36
+ map_attribute "datatypeLibrary", to: :datatypeLibrary, value_map: {
37
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
38
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
39
+ }
40
+ map_element "element", to: :element
41
+ map_element "attribute", to: :attribute
42
+ map_element "ref", to: :ref
43
+ map_element "choice", to: :choice
44
+ map_element "group", to: :group
45
+ map_element "interleave", to: :interleave
46
+ map_element "mixed", to: :mixed
47
+ map_element "optional", to: :optional
48
+ map_element "zeroOrMore", to: :zeroOrMore
49
+ map_element "oneOrMore", to: :oneOrMore
50
+ map_element "text", to: :text
51
+ map_element "empty", to: :empty
52
+ map_element "value", to: :value
53
+ map_element "data", to: :data
54
+ map_element "list", to: :list
55
+ map_element "notAllowed", to: :notAllowed
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Rng
6
+ class Optional < Lutaml::Model::Serializable
7
+ attribute :id, :string
8
+ attribute :ns, :string
9
+ attribute :datatypeLibrary, :string
10
+ attribute :element, Element, collection: true, initialize_empty: true
11
+ attribute :attribute, Attribute, collection: true, initialize_empty: true
12
+ attribute :ref, Ref, collection: true, initialize_empty: true
13
+ attribute :choice, Choice, collection: true, initialize_empty: true
14
+ attribute :group, Group, collection: true, initialize_empty: true
15
+ attribute :interleave, Interleave, collection: true, initialize_empty: true
16
+ attribute :mixed, Mixed, collection: true, initialize_empty: true
17
+ attribute :optional, Optional, collection: true, initialize_empty: true
18
+ attribute :zeroOrMore, ZeroOrMore, collection: true, initialize_empty: true
19
+ attribute :oneOrMore, OneOrMore, collection: true, initialize_empty: true
20
+ attribute :text, Text, collection: true, initialize_empty: true
21
+ attribute :empty, Empty, collection: true, initialize_empty: true
22
+ attribute :value, Value, collection: true, initialize_empty: true
23
+ attribute :data, Data, collection: true, initialize_empty: true
24
+ attribute :list, List, collection: true, initialize_empty: true
25
+ attribute :notAllowed, NotAllowed, collection: true, initialize_empty: true
26
+
27
+ xml do
28
+ root "optional", ordered: true
29
+ namespace "http://relaxng.org/ns/structure/1.0"
30
+
31
+ map_attribute "id", to: :id
32
+ map_attribute "ns", to: :ns, value_map: {
33
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
34
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
35
+ }
36
+ map_attribute "datatypeLibrary", to: :datatypeLibrary, value_map: {
37
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
38
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
39
+ }
40
+ map_element "element", to: :element
41
+ map_element "attribute", to: :attribute
42
+ map_element "ref", to: :ref
43
+ map_element "choice", to: :choice
44
+ map_element "group", to: :group
45
+ map_element "interleave", to: :interleave
46
+ map_element "mixed", to: :mixed
47
+ map_element "optional", to: :optional
48
+ map_element "zeroOrMore", to: :zeroOrMore
49
+ map_element "oneOrMore", to: :oneOrMore
50
+ map_element "text", to: :text
51
+ map_element "empty", to: :empty
52
+ map_element "value", to: :value
53
+ map_element "data", to: :data
54
+ map_element "list", to: :list
55
+ map_element "notAllowed", to: :notAllowed
56
+ end
57
+ end
58
+ end
data/lib/rng/param.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Rng
6
+ class Param < Lutaml::Model::Serializable
7
+ attribute :id, :string
8
+ attribute :ns, :string
9
+ attribute :datatypeLibrary, :string
10
+ attribute :name, :string
11
+ attribute :value, :string
12
+
13
+ xml do
14
+ root "param", ordered: true
15
+ namespace "http://relaxng.org/ns/structure/1.0"
16
+
17
+ map_attribute "id", to: :id
18
+ map_attribute "ns", to: :ns, value_map: {
19
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
20
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
21
+ }
22
+ map_attribute "datatypeLibrary", to: :datatypeLibrary, value_map: {
23
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
24
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
25
+ }
26
+ map_attribute "name", to: :name
27
+ map_content to: :value
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Rng
6
+ class ParentRef < Lutaml::Model::Serializable
7
+ attribute :id, :string
8
+ attribute :ns, :string
9
+ attribute :datatypeLibrary, :string
10
+ attribute :name, :string
11
+
12
+ xml do
13
+ root "parentRef", ordered: true
14
+ namespace "http://relaxng.org/ns/structure/1.0"
15
+
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, value_map: {
22
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
23
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
24
+ }
25
+ map_attribute "name", to: :name
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rng
4
+ # RNC Parser module
5
+ # Provides functionality to parse RELAX NG Compact Syntax (RNC) files
6
+ module ParseRnc
7
+ class << self
8
+ # Parse RNC syntax and return an RNG schema object
9
+ # @param rnc_string [String] The RNC content to parse
10
+ # @return [Rng::Grammar] The parsed schema object
11
+ def parse(rnc_string)
12
+ # This is a placeholder implementation
13
+ # The actual parsing logic would need to be implemented
14
+
15
+ # For now, we delegate to RncParser which is our internal implementation
16
+ # In the future, this could be expanded with additional functionality
17
+ RncParser.parse(rnc_string)
18
+ end
19
+ end
20
+ end
21
+
22
+ # Add class-level parsing method
23
+ def self.parse_rnc(rnc_string)
24
+ ParseRnc.parse(rnc_string)
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Rng
6
+ # Base class for all pattern elements
7
+ class Pattern < Lutaml::Model::Serializable
8
+ attribute :id, :string
9
+ attribute :ns, :string
10
+ attribute :datatypeLibrary, :string
11
+
12
+ xml do
13
+ root "pattern", ordered: true
14
+ namespace "http://relaxng.org/ns/structure/1.0"
15
+
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
+ end
23
+ end
24
+ end
data/lib/rng/ref.rb ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Rng
6
+ class Ref < Lutaml::Model::Serializable
7
+ attribute :id, :string
8
+ attribute :ns, :string
9
+ attribute :datatypeLibrary, :string
10
+ attribute :name, :string
11
+
12
+ xml do
13
+ root "ref", ordered: true
14
+ namespace "http://relaxng.org/ns/structure/1.0"
15
+
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, value_map: {
22
+ from: { empty: :empty, omitted: :omitted, nil: :nil },
23
+ to: { empty: :empty, omitted: :omitted, nil: :nil }
24
+ }
25
+ map_attribute "name", to: :name
26
+ end
27
+ end
28
+ end