nukadoko 0.2.0 → 0.4.0

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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +153 -0
  3. data/README.ja.md +6 -3
  4. data/README.md +6 -3
  5. data/lib/nukadoko/aria_snapshot.rb +4 -4
  6. data/lib/nukadoko/base.rb +49 -29
  7. data/lib/nukadoko/check.rb +62 -5
  8. data/lib/nukadoko/claim_check.rb +2 -2
  9. data/lib/nukadoko/claim_rules.rb +1 -1
  10. data/lib/nukadoko/claim_sides.rb +481 -0
  11. data/lib/nukadoko/claims.rb +182 -20
  12. data/lib/nukadoko/cli.rb +24 -7
  13. data/lib/nukadoko/codes.json +20 -15
  14. data/lib/nukadoko/criteria.rb +1 -1
  15. data/lib/nukadoko/env_check.rb +1 -3
  16. data/lib/nukadoko/fixtures.rb +53 -21
  17. data/lib/nukadoko/init.rb +0 -1
  18. data/lib/nukadoko/js_json.rb +274 -0
  19. data/lib/nukadoko/js_pattern.rb +531 -0
  20. data/lib/nukadoko/parameter_types.rb +54 -0
  21. data/lib/nukadoko/parts.rb +1 -1
  22. data/lib/nukadoko/pattern.rb +112 -2
  23. data/lib/nukadoko/poll.rb +5 -3
  24. data/lib/nukadoko/program.rb +5 -5
  25. data/lib/nukadoko/project_files.rb +17 -0
  26. data/lib/nukadoko/project_program.rb +119 -0
  27. data/lib/nukadoko/run.rb +62 -17
  28. data/lib/nukadoko/run_record.rb +25 -22
  29. data/lib/nukadoko/scaffold.rb +2 -2
  30. data/lib/nukadoko/schema.rb +60 -18
  31. data/lib/nukadoko/secrets.rb +20 -4
  32. data/lib/nukadoko/spaces.rb +28 -0
  33. data/lib/nukadoko/step.rb +7 -1
  34. data/lib/nukadoko/text_fit.rb +1 -1
  35. data/lib/nukadoko/trace_actions.rb +4 -2
  36. data/lib/nukadoko/tree_passes.rb +6 -3
  37. data/lib/nukadoko/version.rb +1 -1
  38. data/lib/nukadoko.rb +26 -2
  39. data/llms.txt +20 -18
  40. data/sig/generated/nukadoko/aria_snapshot.rbs +2 -2
  41. data/sig/generated/nukadoko/base.rbs +24 -18
  42. data/sig/generated/nukadoko/check.rbs +11 -1
  43. data/sig/generated/nukadoko/claim_sides.rbs +216 -0
  44. data/sig/generated/nukadoko/claims.rbs +46 -3
  45. data/sig/generated/nukadoko/cli.rbs +1 -1
  46. data/sig/generated/nukadoko/env_check.rbs +0 -4
  47. data/sig/generated/nukadoko/fixtures.rbs +25 -2
  48. data/sig/generated/nukadoko/init.rbs +0 -2
  49. data/sig/generated/nukadoko/js_json.rbs +109 -0
  50. data/sig/generated/nukadoko/js_pattern.rbs +194 -0
  51. data/sig/generated/nukadoko/parameter_types.rbs +27 -0
  52. data/sig/generated/nukadoko/pattern.rbs +59 -1
  53. data/sig/generated/nukadoko/poll.rbs +3 -2
  54. data/sig/generated/nukadoko/program.rbs +1 -1
  55. data/sig/generated/nukadoko/project_files.rbs +19 -0
  56. data/sig/generated/nukadoko/project_program.rbs +55 -0
  57. data/sig/generated/nukadoko/run.rbs +17 -3
  58. data/sig/generated/nukadoko/run_record.rbs +5 -4
  59. data/sig/generated/nukadoko/schema.rbs +22 -4
  60. data/sig/generated/nukadoko/secrets.rbs +17 -2
  61. data/sig/generated/nukadoko/spaces.rbs +31 -0
  62. data/sig/generated/nukadoko/trace_actions.rbs +3 -1
  63. data/sig/generated/nukadoko/tree_passes.rbs +2 -2
  64. data/sig/generated/nukadoko.rbs +11 -0
  65. data/skills/nukadoko/SKILL.md +2 -2
  66. data/skills/nukadoko/references/diagnosing.md +1 -1
  67. data/skills/nukadoko/references/examples/http-api.md +19 -16
  68. data/skills/nukadoko/references/fixtures.md +1 -1
  69. data/skills/nukadoko/references/perturbed-worlds.md +8 -6
  70. data/skills/nukadoko/references/program.md +20 -20
  71. data/skills/nukadoko/references/running.md +2 -2
  72. data/skills/nukadoko/references/scenario-rules.md +2 -2
  73. data/skills/nukadoko/references/verdicts.md +3 -3
  74. data/skills/nukadoko/references/writing-steps.md +1 -1
  75. data/skills/nukadoko-verification/SKILL.md +6 -6
  76. metadata +19 -5
@@ -0,0 +1,216 @@
1
+ # Generated from lib/nukadoko/claim_sides.rb with RBS::Inline
2
+
3
+ # Responsibility: the two sides of a top-level comparison claim, read as the
4
+ # TypeScript engine reads them: where each value sits (its place, whose
5
+ # label a reason names), the plain JSON copy a claim judges, and what stops
6
+ # a claim before any compare runs (a value that is undefined, one that is
7
+ # not plain JSON, a view that cannot read it, a claim that compares a value
8
+ # with itself or with one observe could have returned). It reads; the
9
+ # compares stay in Claims.compare. A claim on each item of a list is read
10
+ # elsewhere.
11
+ module Nukadoko
12
+ module Engine
13
+ module ClaimSides
14
+ class Place < Data
15
+ attr_reader origin(): String
16
+
17
+ attr_reader segments(): Array[String]
18
+
19
+ attr_reader label(): String
20
+
21
+ attr_reader open(): bool
22
+
23
+ def self.new: (String origin, Array[String] segments, String label, bool open) -> instance
24
+ | (origin: String, segments: Array[String], label: String, open: bool) -> instance
25
+
26
+ def self.members: () -> [ :origin, :segments, :label, :open ]
27
+
28
+ def members: () -> [ :origin, :segments, :label, :open ]
29
+ end
30
+
31
+ # What one side read: a value, or why the claim breaks or is not judged.
32
+ class Side < Data
33
+ attr_reader place(): Place
34
+
35
+ attr_reader found(): Hash[Symbol, untyped]
36
+
37
+ def self.new: (Place place, Hash[Symbol, untyped] found) -> instance
38
+ | (place: Place, found: Hash[Symbol, untyped]) -> instance
39
+
40
+ def self.members: () -> [ :place, :found ]
41
+
42
+ def members: () -> [ :place, :found ]
43
+ end
44
+
45
+ OBSERVE: untyped
46
+
47
+ LITERAL: untyped
48
+
49
+ SAFE: untyped
50
+
51
+ MAX_DEPTH: ::Integer
52
+
53
+ INDEX: ::Regexp
54
+
55
+ # Where a claim reads from: what observe returned with the from values
56
+ # merged in, the args, whether the step observes, its from keys, the
57
+ # label of each args key's origin, and the args keys observe received.
58
+ class Inputs < Data
59
+ attr_reader observed(): untyped
60
+
61
+ attr_reader args(): untyped
62
+
63
+ attr_reader observes(): bool
64
+
65
+ attr_reader from_keys(): Array[String]
66
+
67
+ attr_reader labels(): ^(String) -> String
68
+
69
+ attr_reader received(): Array[String]
70
+
71
+ attr_reader transformed(): Hash[String, String]
72
+
73
+ def self.new: (untyped observed, untyped args, bool observes, Array[String] from_keys, ^(String) -> String labels, Array[String] received, Hash[String, String] transformed) -> instance
74
+ | (observed: untyped, args: untyped, observes: bool, from_keys: Array[String], labels: ^(String) -> String, received: Array[String], transformed: Hash[String, String]) -> instance
75
+
76
+ def self.members: () -> [ :observed, :args, :observes, :from_keys, :labels, :received, :transformed ]
77
+
78
+ def members: () -> [ :observed, :args, :observes, :from_keys, :labels, :received, :transformed ]
79
+ end
80
+
81
+ # A Data block's methods are its own, but rbs-inline reads only a class
82
+ # body, so they are written in one.
83
+ class Inputs
84
+ # : (?transformed: Hash[String, String], **untyped) -> void
85
+ def initialize: (?transformed: Hash[String, String], **untyped) -> void
86
+ end
87
+
88
+ # : (Place, String?) -> Place
89
+ def self.place_at: (Place, String?) -> Place
90
+
91
+ # : (Place, String?) -> Place
92
+ def self.place_viewed: (Place, String?) -> Place
93
+
94
+ # : (Place, bool?) -> Place
95
+ def self.place_counted: (Place, bool?) -> Place
96
+
97
+ # : (Place, Place) -> bool
98
+ def self.same_place?: (Place, Place) -> bool
99
+
100
+ # : (Place, Place) -> bool
101
+ def self.overlap?: (Place, Place) -> bool
102
+
103
+ # : (String, Inputs) -> Place
104
+ def self.arg_place: (String, Inputs) -> Place
105
+
106
+ # : (String) -> Array[String]
107
+ def self.segments: (String) -> Array[String]
108
+
109
+ # The value at `segments` inside `root`, or the index of the first
110
+ # segment that finds nothing. nil is JSON's null, which is a value.
111
+ # : (untyped, Array[String]) -> Hash[Symbol, untyped]
112
+ def self.value_at: (untyped, Array[String]) -> Hash[Symbol, untyped]
113
+
114
+ # : (untyped, Array[String]) -> Hash[Symbol, untyped]
115
+ def self.read_at: (untyped, Array[String]) -> Hash[Symbol, untyped]
116
+
117
+ # : (String) -> String
118
+ def self.article: (String) -> String
119
+
120
+ # The plain JSON copy a claim judges, as JavaScript holds it, or where
121
+ # the first part that is not plain JSON sits and what it is. A whole
122
+ # float is the integer JavaScript's one number type would hold, so
123
+ # 2500.0 is judged and shown as 2500; a symbol is its name.
124
+ # : (untyped, ?Integer) -> Hash[Symbol, untyped]
125
+ def self.snapshot: (untyped, ?Integer) -> Hash[Symbol, untyped]
126
+
127
+ # A JavaScript object lists its array-index keys first, in ascending
128
+ # order, then its other keys in the order they were added.
129
+ # : (Hash[String, untyped]) -> Hash[String, untyped]
130
+ def self.js_order: (Hash[String, untyped]) -> Hash[String, untyped]
131
+
132
+ # : (Place) -> String
133
+ def self.name_of: (Place) -> String
134
+
135
+ # : (Place, Hash[Symbol, untyped]) -> String
136
+ def self.refusal_reason: (Place, Hash[Symbol, untyped]) -> String
137
+
138
+ # : (Integer, Place, Array[String]) -> String
139
+ def self.first_missing: (Integer, Place, Array[String]) -> String
140
+
141
+ # : (Hash[Symbol, untyped], Place, Array[String], Integer, ?^(Place) -> String) -> Side
142
+ def self.side_of: (Hash[Symbol, untyped], Place, Array[String], Integer, ?^(Place) -> String) -> Side
143
+
144
+ # : (Array[String], Inputs, ?^(Place) -> String) -> Side
145
+ def self.arg_side: (Array[String], Inputs, ?^(Place) -> String) -> Side
146
+
147
+ # The side a claim's actual names, read at its path and, with no
148
+ # view, at its at too; `at_read` says the at was read here.
149
+ # : (Hash[Symbol, untyped], Inputs) -> [Side, bool]
150
+ def self.top_side: (Hash[Symbol, untyped], Inputs) -> [ Side, bool ]
151
+
152
+ # The value after a view, or why the view could not read it.
153
+ # : (String?, untyped) -> Hash[Symbol, untyped]
154
+ def self.apply_view: (String?, untyped) -> Hash[Symbol, untyped]
155
+
156
+ # : (Side, String?, String?, ?bool) -> Side
157
+ def self.shaped: (Side, String?, String?, ?bool) -> Side
158
+
159
+ # : (Side, bool?) -> Side
160
+ def self.counted: (Side, bool?) -> Side
161
+
162
+ # The expected side, and whether observe gave it.
163
+ # : (Hash[Symbol, untyped], Inputs) -> [Side, bool]
164
+ def self.expected_side: (Hash[Symbol, untyped], Inputs) -> [ Side, bool ]
165
+
166
+ # What stops a claim before any compare runs, or nil.
167
+ # : (Side, Side, bool, Inputs) -> Hash[Symbol, String]?
168
+ def self.precondition: (Side, Side, bool, Inputs) -> Hash[Symbol, String]?
169
+
170
+ # : (Place, Inputs, String) -> Hash[Symbol, String]?
171
+ def self.observe_received: (Place, Inputs, String) -> Hash[Symbol, String]?
172
+
173
+ # A top-level comparison claim, judged as Claims.judge_one reports one.
174
+ # : (Hash[Symbol, untyped], Inputs) -> Hash[Symbol, untyped]
175
+ def self.judge: (Hash[Symbol, untyped], Inputs) -> Hash[Symbol, untyped]
176
+
177
+ # One comparison on a side already read: a top-level claim's, or one
178
+ # item's under an each.
179
+ # : (Hash[Symbol, untyped], Side, Inputs, ?bool) -> Hash[Symbol, untyped]
180
+ def self.judge_comparison: (Hash[Symbol, untyped], Side, Inputs, ?bool) -> Hash[Symbol, untyped]
181
+
182
+ # : (Hash[Symbol, untyped], StandardError) -> Hash[Symbol, untyped]
183
+ def self.unjudgeable: (Hash[Symbol, untyped], StandardError) -> Hash[Symbol, untyped]
184
+
185
+ # The array an each reads, after its view and at.
186
+ # : (Hash[Symbol, untyped], Inputs) -> Side
187
+ def self.array_side: (Hash[Symbol, untyped], Inputs) -> Side
188
+
189
+ # The side an item claim reads: the item, or a path inside it. The item
190
+ # is part of a snapshot, so a read inside it finds a value or nothing.
191
+ # : (untyped, Place, Hash[Symbol, untyped]) -> Side
192
+ def self.item_side: (untyped, Place, Hash[Symbol, untyped]) -> Side
193
+
194
+ # What ends an each before any item: a declaration whose expected value
195
+ # observe received, or reads through what observe returned while observe
196
+ # received the array, does not depend on an item, and an empty array
197
+ # would hide it. Then a where clause that implies an item claim.
198
+ # : (Hash[Symbol, untyped], Place, Inputs) -> Hash[Symbol, String]?
199
+ def self.each_stop: (Hash[Symbol, untyped], Place, Inputs) -> Hash[Symbol, String]?
200
+
201
+ # The first where clause and item claim that read one value where the
202
+ # clause implies the claim whatever the value is, as the reason that
203
+ # breaks the each: the claim holds on every item where selects, so
204
+ # "every item" measures nothing.
205
+ # : (Hash[Symbol, untyped], Inputs) -> String?
206
+ def self.where_implication: (Hash[Symbol, untyped], Inputs) -> String?
207
+
208
+ # Whether every value a where clause selects holds an item claim on the
209
+ # same value: the same order direction with a bound at least as strict,
210
+ # not-equal against the same value, or an is-a whose kind is the one JSON
211
+ # type the clause can compare.
212
+ # : (String, untyped, String, untyped) -> bool
213
+ def self.where_implies?: (String, untyped, String, untyped) -> bool
214
+ end
215
+ end
216
+ end
@@ -43,10 +43,17 @@ module Nukadoko
43
43
  # : (Hash[Symbol, untyped], untyped) -> Hash[Symbol, String]
44
44
  def self.aria_side: (Hash[Symbol, untyped], untyped) -> Hash[Symbol, String]
45
45
 
46
- # : (Array[Hash[Symbol, untyped]], untyped, untyped) -> Array[Hash[Symbol, untyped]]
47
- def self.judge: (Array[Hash[Symbol, untyped]], untyped, untyped) -> Array[Hash[Symbol, untyped]]
46
+ # `inputs` says where each side sits, so a top-level comparison is read
47
+ # as the TypeScript engine reads it (ClaimSides); without it, a claim
48
+ # reads `observed` as the value of each key.
49
+ # : (Array[Hash[Symbol, untyped]], untyped, untyped, ?ClaimSides::Inputs?) -> Array[Hash[Symbol, untyped]]
50
+ def self.judge: (Array[Hash[Symbol, untyped]], untyped, untyped, ?ClaimSides::Inputs?) -> Array[Hash[Symbol, untyped]]
51
+
52
+ # An each judged as its record judges it, so a poll waits on the
53
+ # outcome the record will hold.
54
+ # : (Hash[Symbol, untyped], ClaimSides::Inputs) -> Hash[Symbol, untyped]
55
+ def self.each_judged: (Hash[Symbol, untyped], ClaimSides::Inputs) -> Hash[Symbol, untyped]
48
56
 
49
- # `top` is what observe returned, which an expected { observe } reads
50
57
  # from inside an each as well. A claim on an item with no actual reads
51
58
  # the item itself.
52
59
  # : (Hash[Symbol, untyped], untyped, untyped, ?untyped) -> Hash[Symbol, untyped]
@@ -112,9 +119,45 @@ module Nukadoko
112
119
 
113
120
  # A text a URL parser accepts can still be no URL a program wrote, so
114
121
  # the scheme needs "//" and no character a reader cannot see may appear.
122
+ # The rest is what the WHATWG URL parser, which the TypeScript engine
123
+ # uses, refuses for http and https: a missing host, a port that is not
124
+ # a number up to 65535, a host with a character no domain may hold, and
125
+ # an IPv4 or IPv6 address that does not parse. A path, a query, and a
126
+ # fragment can hold anything, as a browser takes them.
115
127
  # : (untyped) -> bool
116
128
  def self.url?: (untyped) -> bool
117
129
 
130
+ # The host and the port of `host:port`, a colon inside brackets kept.
131
+ # : (String) -> [String?, String?]
132
+ def self.split_host_port: (String) -> [ String?, String? ]
133
+
134
+ # : (String) -> bool
135
+ def self.ipv6?: (String) -> bool
136
+
137
+ FORBIDDEN_DOMAIN: ::Regexp
138
+
139
+ # A host percent-decoded and mapped as UTS #46 maps it (NFKC, then
140
+ # lower case), which holds no character a domain may not, and whose
141
+ # last label, when it reads as a number, is an IPv4 address.
142
+ # : (String) -> bool
143
+ def self.domain?: (String) -> bool
144
+
145
+ # Whether a label written as `xn--` decodes, under RFC 3492, to a
146
+ # label UTS #46 keeps: one with a character outside ASCII, no control,
147
+ # joiner, or unassigned character, and already in its mapped form.
148
+ # : (String) -> bool
149
+ def self.punycode_label?: (String) -> bool
150
+
151
+ # RFC 3492's decoder, or nil for a text that does not decode.
152
+ # : (String) -> String?
153
+ def self.punycode_decode: (String) -> String?
154
+
155
+ # The WHATWG IPv4 parser: up to four parts, each decimal, octal with a
156
+ # leading 0, or hex with 0x, every part but the last below 256 and the
157
+ # last below what the parts before it leave.
158
+ # : (Array[String]) -> bool
159
+ def self.ipv4?: (Array[String]) -> bool
160
+
118
161
  KIND_TESTS: untyped
119
162
 
120
163
  # The test of the kind `name` names, read trimmed and in any case.
@@ -95,7 +95,7 @@ module Nukadoko
95
95
 
96
96
  # Why --env left out every selected scenario, and the run that meets
97
97
  # them: the run without --env when it does, else the first environment
98
- # of the program file that meets each, or else one that meets some.
98
+ # of the program that meets each, or else one that meets some.
99
99
  # : (Array[Engine::Scenario], Engine::Program) -> Hash[Symbol, String]
100
100
  def left_out_stop: (Array[Engine::Scenario], Engine::Program) -> Hash[Symbol, String]
101
101
 
@@ -9,10 +9,6 @@
9
9
  module Nukadoko
10
10
  module Engine
11
11
  module EnvCheck
12
- CONFIG: ::String
13
-
14
- PROGRAM: ::String
15
-
16
12
  # `KEY` counts only as a whole underscore-delimited word, so MONKEY,
17
13
  # KEYWORD, and APIKEY are not guessed to be secrets.
18
14
  SECRET_LOOKING: ::Regexp
@@ -49,8 +49,31 @@ module Nukadoko
49
49
  # TypeScript engine. Requests the page sends are recorded by the engine's
50
50
  # own listener, and each step gets a trace chunk.
51
51
  class Browser
52
- # : (String?, ?Hash[Symbol, untyped]) -> void
53
- def initialize: (String?, ?Hash[Symbol, untyped]) -> void
52
+ # `secrets` gives the run's loaded secrets when a screenshot is taken,
53
+ # since an environment's env files are read after the browser is made.
54
+ # : (String?, ?Hash[Symbol, untyped], ?secrets: ^() -> Secrets) -> void
55
+ def initialize: (String?, ?Hash[Symbol, untyped], ?secrets: ^() -> Secrets) -> void
56
+
57
+ # Opaque, so a masked secret leaves no trace of its glyphs.
58
+ MASK_COLOR: ::String
59
+
60
+ # Locators for every element of `page`, in every frame, that shows a
61
+ # loaded secret: as text, or as the value of an input or textarea, which
62
+ # is not text `get_by_text` reads, and a step may have typed the secret
63
+ # there. The text redaction of a record cannot reach pixels, and
64
+ # marking or rewriting the elements would change the page the next step
65
+ # reads. Only the value as written is found, not an encoded spelling;
66
+ # `get_by_text` ignores case, which costs pixels, never a leak.
67
+ # : (untyped) -> Array[untyped]
68
+ def secret_masks: (untyped) -> Array[untyped]
69
+
70
+ # A screenshot of `page` at `path` with what shows a secret covered,
71
+ # true once written. No screenshot rather than one that shows a
72
+ # secret: masks not found by `deadline` (a monotonic time) give none,
73
+ # and the image is written only once it arrived. `bounded` holds the
74
+ # screenshot to the deadline too, as a pause and a judged view do.
75
+ # : (untyped, String, Float, ?caret: String?, ?bounded: bool) -> bool
76
+ def masked_shot: (untyped, String, Float, ?caret: String?, ?bounded: bool) -> bool
54
77
 
55
78
  # : (String, Array[Hash[Symbol, untyped]]) -> [untyped, ^() -> void]
56
79
  def page_for: (String, Array[Hash[Symbol, untyped]]) -> [ untyped, ^() -> void ]
@@ -17,8 +17,6 @@
17
17
  module Nukadoko
18
18
  module Engine
19
19
  class Init
20
- CONFIG: ::String
21
-
22
20
  STEPS: untyped
23
21
 
24
22
  # `.env` files are ignored since a committed one is configuration, not
@@ -0,0 +1,109 @@
1
+ # Generated from lib/nukadoko/js_json.rb with RBS::Inline
2
+
3
+ # JSON text read as JavaScript's JSON.parse reads it, and refused in V8's
4
+ # words. A claim's json view reports why a text is no JSON, and that reason
5
+ # is part of the record both engines write, so the Ruby engine walks the
6
+ # grammar V8 walks and names the same place. Ruby's own parser accepts
7
+ # what JSON.parse refuses (comments, a NaN under some options), so the walk
8
+ # also decides what is valid; Ruby's parser only builds the value after it.
9
+ # Positions count UTF-16 code units, as a JavaScript string does.
10
+ module Nukadoko
11
+ module JsJson
12
+ class Error < JSON::ParserError
13
+ end
14
+
15
+ # Texts V8 names whole, since they are what a JavaScript value turns
16
+ # into when it is passed as text by mistake.
17
+ SPECIAL: untyped
18
+
19
+ CONTEXT: ::Integer
20
+
21
+ WHITESPACE: untyped
22
+
23
+ ESCAPES: untyped
24
+
25
+ HEX: untyped
26
+
27
+ # A Failure carries where the walk stopped and what V8 says there.
28
+ class Failure < Data
29
+ attr_reader pos(): untyped
30
+
31
+ attr_reader message(): untyped
32
+
33
+ def self.new: (untyped pos, untyped message) -> instance
34
+ | (pos: untyped, message: untyped) -> instance
35
+
36
+ def self.members: () -> [ :pos, :message ]
37
+
38
+ def members: () -> [ :pos, :message ]
39
+ end
40
+
41
+ # : (String) -> untyped
42
+ def self.parse: (String) -> untyped
43
+
44
+ # A value as JavaScript's JSON.stringify writes it: a whole float is the
45
+ # integer its one number type holds (2.0 is 2), a float its shortest digits
46
+ # (1e20 is 100000000000000000000), and NaN or Infinity null, so a reason that
47
+ # quotes a value reads as the TypeScript engine's does.
48
+ # : (untyped) -> String
49
+ def self.generate: (untyped) -> String
50
+
51
+ # Walks the text once and gives V8's message for the first place it is
52
+ # no JSON, or nil.
53
+ class Walk
54
+ # : (String) -> void
55
+ def initialize: (String) -> void
56
+
57
+ # : () -> String?
58
+ def failure: () -> String?
59
+
60
+ private
61
+
62
+ class Stop < StandardError
63
+ end
64
+
65
+ # : () -> Integer?
66
+ def peek: () -> Integer?
67
+
68
+ # : () -> void
69
+ def space: () -> void
70
+
71
+ # : (String) -> String
72
+ def located: (String) -> String
73
+
74
+ # : (?String?) -> bot
75
+ def stop: (?String?) -> bot
76
+
77
+ # V8's message for a character no rule expected: the text itself when
78
+ # it is short, else ten units on each side of the character.
79
+ # : () -> String
80
+ def unexpected: () -> String
81
+
82
+ # A run of UTF-16 units as text; half of a pair, which a UTF-8 string
83
+ # cannot hold, is the replacement character.
84
+ # : (Array[Integer]) -> String
85
+ def text_of: (Array[Integer]) -> String
86
+
87
+ # : () -> void
88
+ def value: () -> void
89
+
90
+ # : (String) -> void
91
+ def literal: (String) -> void
92
+
93
+ # : () -> void
94
+ def object: () -> void
95
+
96
+ # : () -> void
97
+ def array: () -> void
98
+
99
+ # : () -> void
100
+ def string: () -> void
101
+
102
+ # : () -> void
103
+ def number: () -> void
104
+
105
+ # : () -> bool
106
+ def digit?: () -> bool
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,194 @@
1
+ # Generated from lib/nukadoko/js_pattern.rb with RBS::Inline
2
+
3
+ # Responsibility: read a `matches` claim's pattern as JavaScript's RegExp
4
+ # reads it, so the Ruby engine judges the claim the way the TypeScript
5
+ # engine does: `new RegExp(pattern)`, no flags, with the web's legacy
6
+ # grammar (a `{` that starts no quantifier is a `{`, `\A` is an `A`). Ruby's
7
+ # own grammar reads the same text otherwise: `^` and `$` there match at
8
+ # every line, `\s` takes no Unicode space, `\A` and `\h` mean something,
9
+ # `[^]` does not build, and an unnamed group stops capturing once a named
10
+ # one is present. So the pattern is parsed here and written again as a
11
+ # Ruby pattern that means what the JavaScript one does.
12
+ #
13
+ # JavaScript matches a text unit by UTF-16 unit, so `.` takes half of an
14
+ # emoji. Each half of a character past U+FFFF, in the pattern and in the
15
+ # text, is therefore written as one character of its own in plane 16's
16
+ # private use area (`units`).
17
+ #
18
+ # Honest limits: case-insensitive matching inside `(?i:...)` folds case as
19
+ # Ruby does, which differs for a few letters (the Kelvin sign, the long
20
+ # s); a lookbehind Ruby cannot run (one of unbounded length, or holding a
21
+ # backreference) is refused with Ruby's reason; a group inside a repeated
22
+ # group keeps its capture from an earlier round, where JavaScript clears it.
23
+ module Nukadoko
24
+ module Engine
25
+ module JsPattern
26
+ # A pattern JavaScript refuses, with V8's message.
27
+ class Invalid < StandardError
28
+ end
29
+
30
+ LINE_ENDS: ::String
31
+
32
+ SPACE: ::String
33
+
34
+ WORD: ::String
35
+
36
+ SETS: untyped
37
+
38
+ CONTROL: untyped
39
+
40
+ # Where a UTF-16 surrogate unit is written as a character of its own.
41
+ UNIT_BASE: ::Integer
42
+
43
+ SURROGATES: untyped
44
+
45
+ # Ruby refuses a repeat count past this; JavaScript takes any.
46
+ REPEAT_LIMIT: ::Integer
47
+
48
+ GROUP_NAME: ::Regexp
49
+
50
+ # `text` with each character past U+FFFF written as its two UTF-16
51
+ # units, each in plane 16's private use area.
52
+ # : (String) -> String
53
+ def self.units: (String) -> String
54
+
55
+ # The character a UTF-16 unit is written as.
56
+ # : (Integer) -> String
57
+ def self.unit: (Integer) -> String
58
+
59
+ # The Ruby pattern that matches what `new RegExp(source)` matches, in
60
+ # a text written through `units`.
61
+ # : (String, ?timeout: Float?) -> Regexp
62
+ def self.compile: (String, ?timeout: Float?) -> Regexp
63
+
64
+ # Reads a pattern in JavaScript's legacy grammar and writes it in
65
+ # Ruby's. Every group is written named, `g<n>` by JavaScript's group
66
+ # number, since Ruby stops counting unnamed groups once a named one is
67
+ # present, and a backreference to a group that has not matched
68
+ # matches nothing, as in JavaScript.
69
+ class Parser
70
+ # : (String) -> void
71
+ def initialize: (String) -> void
72
+
73
+ # : () -> String
74
+ def call: () -> String
75
+
76
+ private
77
+
78
+ # : (String) -> bot
79
+ def fail!: (String) -> bot
80
+
81
+ # : (?Integer) -> String?
82
+ def peek: (?Integer) -> String?
83
+
84
+ # : () -> String?
85
+ def take: () -> String?
86
+
87
+ # : (String) -> bool
88
+ def taken?: (String) -> bool
89
+
90
+ # The index of the `>` that ends a group name started at `from`.
91
+ # : (Integer) -> Integer?
92
+ def find_close: (Integer) -> Integer?
93
+
94
+ # Every capturing group's number and every group name, read before
95
+ # the parse, since a backreference may name a later group.
96
+ # : () -> Integer
97
+ def count_groups: () -> Integer
98
+
99
+ # : (Hash[Symbol, bool]) -> String
100
+ def disjunction: (Hash[Symbol, bool]) -> String
101
+
102
+ # : (Hash[Symbol, bool]) -> String
103
+ def alternative: (Hash[Symbol, bool]) -> String
104
+
105
+ # : (Hash[Symbol, bool]) -> String
106
+ def term: (Hash[Symbol, bool]) -> String
107
+
108
+ # `^`, `$`, `\b`, and `\B`, which no quantifier may follow.
109
+ # : (Hash[Symbol, bool]) -> String?
110
+ def assertion: (Hash[Symbol, bool]) -> String?
111
+
112
+ # An atom as Ruby source, and whether a quantifier may follow it:
113
+ # true, false, or :lookbehind, whose refusal V8 words otherwise.
114
+ # : (Hash[Symbol, bool]) -> [String, (bool | Symbol)]
115
+ def atom: (Hash[Symbol, bool]) -> [ String, bool | Symbol ]
116
+
117
+ # : (Hash[Symbol, bool]) -> [String, (bool | Symbol)]
118
+ def group: (Hash[Symbol, bool]) -> [ String, bool | Symbol ]
119
+
120
+ # `(?ims-ims:...)`: the flags it turns on and off, for its body.
121
+ # : (Hash[Symbol, bool]) -> [String, bool]
122
+ def modified: (Hash[Symbol, bool]) -> [ String, bool ]
123
+
124
+ # : () -> Array[String]
125
+ def read_flags: () -> Array[String]
126
+
127
+ # The body of a group through its `)`.
128
+ # : (Hash[Symbol, bool]) -> String
129
+ def closed: (Hash[Symbol, bool]) -> String
130
+
131
+ # A quantifier at this point, as Ruby source, or nil.
132
+ # : () -> String?
133
+ def quantifier: () -> String?
134
+
135
+ # : () -> bool
136
+ def quantifier_ahead?: () -> bool
137
+
138
+ # `{n}`, `{n,}`, or `{n,m}`, read and written for Ruby, or nil when
139
+ # the brace starts none, which makes it a `{`.
140
+ # : () -> String?
141
+ def braced_quantifier: () -> String?
142
+
143
+ # An escape outside a class, from its backslash.
144
+ # : (Hash[Symbol, bool]) -> String
145
+ def escape: (Hash[Symbol, bool]) -> String
146
+
147
+ # `\0`, a backreference, a legacy octal escape, or `\8` and `\9`.
148
+ # : (String) -> String
149
+ def decimal: (String) -> String
150
+
151
+ # A legacy octal escape from its first digit: at most three digits,
152
+ # and at most 0o377.
153
+ # : (String) -> Integer
154
+ def octal: (String) -> Integer
155
+
156
+ # `\xHH` or `\uHHHH` as the unit it names, or nil (and nothing
157
+ # read) when the digits are not there.
158
+ # : (Integer) -> String?
159
+ def hex: (Integer) -> String?
160
+
161
+ # : (Hash[Symbol, bool]) -> String
162
+ def named_reference: (Hash[Symbol, bool]) -> String
163
+
164
+ # The first of `numbers` that matched, or nothing when none did. A
165
+ # group that opens after the reference has never matched there,
166
+ # since JavaScript clears a repeated group's captures each round, so
167
+ # it is left out (Ruby refuses a name it has not seen yet).
168
+ # : (Array[Integer]) -> String
169
+ def backreference: (Array[Integer]) -> String
170
+
171
+ # : () -> String
172
+ def character_class: () -> String
173
+
174
+ # One member of a class: a unit's code, or a set as Ruby source.
175
+ # : () -> (Integer | String)
176
+ def class_atom: () -> (Integer | String)
177
+
178
+ # : (Integer | String) -> String
179
+ def class_part: (Integer | String) -> String
180
+
181
+ # A range of units, with the surrogates in it where `units` writes
182
+ # them.
183
+ # : (Integer, Integer) -> String
184
+ def range: (Integer, Integer) -> String
185
+
186
+ # : (Integer) -> String
187
+ def code: (Integer) -> String
188
+
189
+ # : (String) -> String
190
+ def literal: (String) -> String
191
+ end
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,27 @@
1
+ # Generated from lib/nukadoko/parameter_types.rb with RBS::Inline
2
+
3
+ # The config's parameterTypes, read and handed to Pattern: each entry a
4
+ # name, a regexp, and an optional transformer. A shape the TypeScript
5
+ # engine's schema refuses is refused here with its words, so a project
6
+ # moves between the engines without a config that one of them takes and
7
+ # the other does not. Boundary: reading the entries; registering them and
8
+ # matching lines are Pattern's.
9
+ module Nukadoko
10
+ module Engine
11
+ module ParameterTypes
12
+ NAME: ::Regexp
13
+
14
+ KEYS: untyped
15
+
16
+ # : (untyped) -> void
17
+ def self.read: (untyped) -> void
18
+
19
+ # A value's kind in the words zod uses for it.
20
+ # : (untyped) -> String
21
+ def self.kind: (untyped) -> String
22
+
23
+ # : (String) -> bot
24
+ def self.invalid: (String) -> bot
25
+ end
26
+ end
27
+ end