nukadoko 0.1.0 → 0.3.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 (159) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +417 -0
  3. data/README.ja.md +62 -7
  4. data/README.md +19 -5
  5. data/exe/nuka +8 -0
  6. data/lib/nukadoko/aria_snapshot.rb +1008 -0
  7. data/lib/nukadoko/aria_tree.rb +150 -0
  8. data/lib/nukadoko/base.rb +294 -0
  9. data/lib/nukadoko/check.rb +669 -22
  10. data/lib/nukadoko/claim_check.rb +177 -0
  11. data/lib/nukadoko/claim_check_run.rb +293 -0
  12. data/lib/nukadoko/claim_line.rb +381 -0
  13. data/lib/nukadoko/claim_rules.rb +519 -0
  14. data/lib/nukadoko/claim_sides.rb +469 -0
  15. data/lib/nukadoko/claims.rb +576 -37
  16. data/lib/nukadoko/cli.rb +814 -22
  17. data/lib/nukadoko/codes.json +947 -0
  18. data/lib/nukadoko/codes.rb +19 -0
  19. data/lib/nukadoko/command.rb +214 -12
  20. data/lib/nukadoko/criteria.rb +172 -0
  21. data/lib/nukadoko/definition.rb +33 -41
  22. data/lib/nukadoko/env_check.rb +88 -0
  23. data/lib/nukadoko/features.rb +80 -10
  24. data/lib/nukadoko/fixtures.rb +329 -11
  25. data/lib/nukadoko/http_recording.rb +68 -0
  26. data/lib/nukadoko/init.rb +129 -0
  27. data/lib/nukadoko/js_json.rb +274 -0
  28. data/lib/nukadoko/js_pattern.rb +531 -0
  29. data/lib/nukadoko/judge.rb +221 -0
  30. data/lib/nukadoko/judgment_file.rb +78 -0
  31. data/lib/nukadoko/judgments.rb +256 -0
  32. data/lib/nukadoko/literal.rb +129 -0
  33. data/lib/nukadoko/measured.rb +105 -0
  34. data/lib/nukadoko/order.rb +84 -0
  35. data/lib/nukadoko/parts.rb +43 -22
  36. data/lib/nukadoko/pattern.rb +73 -3
  37. data/lib/nukadoko/poll.rb +21 -8
  38. data/lib/nukadoko/program.rb +105 -17
  39. data/lib/nukadoko/project_files.rb +17 -0
  40. data/lib/nukadoko/project_fixtures.rb +17 -2
  41. data/lib/nukadoko/project_program.rb +119 -0
  42. data/lib/nukadoko/report_allure.rb +751 -0
  43. data/lib/nukadoko/report_messages.rb +167 -0
  44. data/lib/nukadoko/report_run.rb +169 -0
  45. data/lib/nukadoko/run.rb +898 -91
  46. data/lib/nukadoko/run_record.rb +535 -0
  47. data/lib/nukadoko/scaffold.rb +1015 -0
  48. data/lib/nukadoko/schema.rb +120 -21
  49. data/lib/nukadoko/secrets.rb +375 -0
  50. data/lib/nukadoko/selection.rb +163 -0
  51. data/lib/nukadoko/signature.rb +4 -1
  52. data/lib/nukadoko/skill.rb +36 -0
  53. data/lib/nukadoko/spaces.rb +28 -0
  54. data/lib/nukadoko/step.rb +68 -21
  55. data/lib/nukadoko/summary.rb +662 -0
  56. data/lib/nukadoko/table.rb +34 -2
  57. data/lib/nukadoko/text_fit.rb +179 -0
  58. data/lib/nukadoko/trace.rb +244 -0
  59. data/lib/nukadoko/trace_actions.rb +116 -0
  60. data/lib/nukadoko/tree_passes.rb +122 -0
  61. data/lib/nukadoko/verdict.rb +128 -0
  62. data/lib/nukadoko/version.rb +2 -1
  63. data/lib/nukadoko/vocabulary.rb +6 -0
  64. data/lib/nukadoko/walk.rb +305 -0
  65. data/lib/nukadoko/walk_files.rb +473 -0
  66. data/lib/nukadoko/walk_step.rb +149 -0
  67. data/lib/nukadoko.rb +60 -2
  68. data/llms.txt +297 -0
  69. data/sig/generated/nukadoko/aria_snapshot.rbs +331 -0
  70. data/sig/generated/nukadoko/aria_tree.rbs +142 -0
  71. data/sig/generated/nukadoko/base.rbs +142 -0
  72. data/sig/generated/nukadoko/check.rbs +255 -0
  73. data/sig/generated/nukadoko/claim_check.rbs +118 -0
  74. data/sig/generated/nukadoko/claim_check_run.rbs +88 -0
  75. data/sig/generated/nukadoko/claim_line.rbs +158 -0
  76. data/sig/generated/nukadoko/claim_rules.rbs +172 -0
  77. data/sig/generated/nukadoko/claim_sides.rbs +207 -0
  78. data/sig/generated/nukadoko/claims.rbs +208 -0
  79. data/sig/generated/nukadoko/cli.rbs +182 -0
  80. data/sig/generated/nukadoko/codes.rbs +16 -0
  81. data/sig/generated/nukadoko/command.rbs +109 -0
  82. data/sig/generated/nukadoko/criteria.rbs +83 -0
  83. data/sig/generated/nukadoko/definition.rbs +30 -0
  84. data/sig/generated/nukadoko/env_check.rbs +34 -0
  85. data/sig/generated/nukadoko/features.rbs +101 -0
  86. data/sig/generated/nukadoko/fixtures.rbs +175 -0
  87. data/sig/generated/nukadoko/http_recording.rbs +29 -0
  88. data/sig/generated/nukadoko/init.rbs +64 -0
  89. data/sig/generated/nukadoko/js_json.rbs +109 -0
  90. data/sig/generated/nukadoko/js_pattern.rbs +194 -0
  91. data/sig/generated/nukadoko/judge.rbs +64 -0
  92. data/sig/generated/nukadoko/judgment_file.rbs +39 -0
  93. data/sig/generated/nukadoko/judgments.rbs +120 -0
  94. data/sig/generated/nukadoko/literal.rbs +71 -0
  95. data/sig/generated/nukadoko/measured.rbs +42 -0
  96. data/sig/generated/nukadoko/order.rbs +54 -0
  97. data/sig/generated/nukadoko/parts.rbs +35 -0
  98. data/sig/generated/nukadoko/pattern.rbs +62 -0
  99. data/sig/generated/nukadoko/poll.rbs +41 -0
  100. data/sig/generated/nukadoko/program.rbs +101 -0
  101. data/sig/generated/nukadoko/project_files.rbs +19 -0
  102. data/sig/generated/nukadoko/project_fixtures.rbs +57 -0
  103. data/sig/generated/nukadoko/project_program.rbs +55 -0
  104. data/sig/generated/nukadoko/report_allure.rbs +268 -0
  105. data/sig/generated/nukadoko/report_messages.rbs +68 -0
  106. data/sig/generated/nukadoko/report_run.rbs +102 -0
  107. data/sig/generated/nukadoko/run.rbs +264 -0
  108. data/sig/generated/nukadoko/run_record.rbs +175 -0
  109. data/sig/generated/nukadoko/scaffold.rbs +328 -0
  110. data/sig/generated/nukadoko/schema.rbs +155 -0
  111. data/sig/generated/nukadoko/secrets.rbs +172 -0
  112. data/sig/generated/nukadoko/selection.rbs +73 -0
  113. data/sig/generated/nukadoko/signature.rbs +17 -0
  114. data/sig/generated/nukadoko/skill.rbs +20 -0
  115. data/sig/generated/nukadoko/spaces.rbs +31 -0
  116. data/sig/generated/nukadoko/step.rbs +115 -0
  117. data/sig/generated/nukadoko/summary.rbs +204 -0
  118. data/sig/generated/nukadoko/table.rbs +43 -0
  119. data/sig/generated/nukadoko/text_fit.rbs +70 -0
  120. data/sig/generated/nukadoko/trace.rbs +127 -0
  121. data/sig/generated/nukadoko/trace_actions.rbs +40 -0
  122. data/sig/generated/nukadoko/tree_passes.rbs +48 -0
  123. data/sig/generated/nukadoko/verdict.rbs +56 -0
  124. data/sig/generated/nukadoko/version.rbs +5 -0
  125. data/sig/generated/nukadoko/vocabulary.rbs +25 -0
  126. data/sig/generated/nukadoko/walk.rbs +139 -0
  127. data/sig/generated/nukadoko/walk_files.rbs +189 -0
  128. data/sig/generated/nukadoko/walk_step.rbs +50 -0
  129. data/sig/generated/nukadoko.rbs +26 -0
  130. data/sig/nukadoko.rbs +5 -48
  131. data/skills/nukadoko/SKILL.md +120 -0
  132. data/skills/nukadoko/references/checking-steps.md +200 -0
  133. data/skills/nukadoko/references/diagnosing.md +200 -0
  134. data/skills/nukadoko/references/done.md +99 -0
  135. data/skills/nukadoko/references/evidence.md +124 -0
  136. data/skills/nukadoko/references/examples/cli.md +230 -0
  137. data/skills/nukadoko/references/examples/http-api.md +342 -0
  138. data/skills/nukadoko/references/examples/workflow.md +173 -0
  139. data/skills/nukadoko/references/exploring.md +184 -0
  140. data/skills/nukadoko/references/fixtures.md +198 -0
  141. data/skills/nukadoko/references/from-prose.md +51 -0
  142. data/skills/nukadoko/references/judgments.md +95 -0
  143. data/skills/nukadoko/references/maintenance.md +97 -0
  144. data/skills/nukadoko/references/merge-risk.md +74 -0
  145. data/skills/nukadoko/references/parts.md +152 -0
  146. data/skills/nukadoko/references/perturbed-worlds.md +109 -0
  147. data/skills/nukadoko/references/program.md +200 -0
  148. data/skills/nukadoko/references/reviewing.md +200 -0
  149. data/skills/nukadoko/references/running.md +200 -0
  150. data/skills/nukadoko/references/scenario-rules.md +188 -0
  151. data/skills/nukadoko/references/states.md +66 -0
  152. data/skills/nukadoko/references/step-files.md +200 -0
  153. data/skills/nukadoko/references/verdicts.md +200 -0
  154. data/skills/nukadoko/references/writing-steps.md +200 -0
  155. data/skills/nukadoko/references/writing-the-feature.md +165 -0
  156. data/skills/nukadoko/scripts/claude-code-verdict-hook.mjs +99 -0
  157. data/skills/nukadoko/scripts/merge-risk.jq +56 -0
  158. data/skills/nukadoko-verification/SKILL.md +263 -0
  159. metadata +133 -1
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+ # rbs_inline: enabled
3
+
4
+ require "fileutils"
5
+
6
+ # `nuka init`: the config file, the steps directory, and the .gitignore
7
+ # entries, in the TypeScript engine's order and words. A config file
8
+ # already there refuses the whole command before anything is written, so a
9
+ # half-done init never looks like a finished one. It ends with a
10
+ # self-check that loads the config and the steps as `nuka steps` does; a
11
+ # failure there is reported and the files stay, so what init wrote can be
12
+ # looked at and fixed.
13
+ #
14
+ # The TypeScript engine also adds a package.json script and tsconfig
15
+ # entries. A Ruby project's one command for people and CI is a rake task,
16
+ # so a Rakefile with no `scenarios` task gets one that runs `nuka run`; a
17
+ # project with no Rakefile gets none, since a Rakefile written only for
18
+ # this would be a second place to look. The Gemfile is read too: one that
19
+ # does not name nukadoko gets a line on stderr.
20
+ module Nukadoko
21
+ module Engine
22
+ class Init
23
+ STEPS = File.join("features", "steps")
24
+ # `.env` files are ignored since a committed one is configuration, not
25
+ # a secret source; `!.env.example` must follow `.env.*` to re-include it.
26
+ IGNORED = [".nukadoko/", ".env", ".env.*", "!.env.example"].freeze
27
+ # The gem's copy is staged at release; a checkout has only the root's.
28
+ STAGED_LLMS = File.expand_path("../../llms.txt", __dir__.to_s)
29
+ LLMS = File.file?(STAGED_LLMS) ? STAGED_LLMS : File.expand_path("../../../llms.txt", __dir__.to_s)
30
+ # The gem ships no docs/, so the config file points at the spec online.
31
+ SPEC = "https://github.com/meganemura/nukadoko/blob/main/docs/spec.md"
32
+ TASK = <<~RUBY
33
+ desc "Run the acceptance scenarios: nuka check, then every scenario under features/"
34
+ task :scenarios do
35
+ sh "bundle exec nuka run"
36
+ end
37
+ RUBY
38
+
39
+ #: (String, out: IO, err: IO) -> void
40
+ def initialize(project, out:, err:)
41
+ @project = project
42
+ @out = out
43
+ @err = err
44
+ end
45
+
46
+ # The exit code, or a Refusal when a config file exists.
47
+ #: () -> (Integer | Refusal)
48
+ def call
49
+ config = File.join(@project, CONFIG)
50
+ if File.exist?(config)
51
+ return Refusal.new("config-exists", "Refusing to init: #{config} already exists; nothing was written", run: "nuka check")
52
+ end
53
+
54
+ File.write(config, <<~RUBY)
55
+ # Every config key nukadoko reads, one line each: #{SPEC}, "Environments and secrets"
56
+ Nukadoko.config
57
+ RUBY
58
+ @out.puts CONFIG
59
+ FileUtils.mkdir_p(File.join(@project, STEPS))
60
+ @out.puts STEPS
61
+ @out.puts ".gitignore" if ignore_entries
62
+ @out.puts "Rakefile" if scenarios_task
63
+ gemfile_note
64
+ self_check
65
+ end
66
+
67
+ private
68
+
69
+ # Appends each entry no line already ignores; true when it wrote.
70
+ #: () -> bool
71
+ def ignore_entries
72
+ path = File.join(@project, ".gitignore")
73
+ existing = File.exist?(path) ? File.read(path) : ""
74
+ lines = existing.split(/\r?\n/)
75
+ missing = IGNORED.reject { |entry| lines.any? { covers?(_1, entry) } }
76
+ return false if missing.empty?
77
+
78
+ prefix = existing.empty? || existing.end_with?("\n") ? existing : "#{existing}\n"
79
+ File.write(path, "#{prefix}#{missing.join("\n")}\n")
80
+ true
81
+ end
82
+
83
+ # Appends the `scenarios` task to a Rakefile that has none; true when it wrote.
84
+ #: () -> bool
85
+ def scenarios_task
86
+ path = File.join(@project, "Rakefile")
87
+ return false unless File.exist?(path)
88
+
89
+ existing = File.read(path)
90
+ return false if existing.match?(/^\s*task\s*\(?\s*(:scenarios|["']scenarios["'])/)
91
+
92
+ prefix = existing.empty? || existing.end_with?("\n") ? existing : "#{existing}\n"
93
+ File.write(path, "#{prefix}#{"\n" unless prefix.empty?}#{TASK}")
94
+ true
95
+ end
96
+
97
+ # A root directory entry is also ignored by `/name`, `name`, or `name/**`.
98
+ #: (String, String) -> bool
99
+ def covers?(line, entry)
100
+ trimmed = line.strip
101
+ return true if trimmed == entry
102
+ return false unless entry.end_with?("/")
103
+
104
+ trimmed.delete_prefix("/").sub(%r{/(\*\*)?\z}, "") == entry.delete_suffix("/")
105
+ end
106
+
107
+ #: () -> void
108
+ def gemfile_note
109
+ gemfile = File.join(@project, "Gemfile")
110
+ return unless File.exist?(gemfile)
111
+ return if File.read(gemfile).match?(/^\s*gem\s+["']nukadoko["']/)
112
+
113
+ @err.puts %(note: the Gemfile names no nukadoko gem; add gem "nukadoko", group: :test so bundle exec nuka runs this version)
114
+ end
115
+
116
+ #: () -> Integer
117
+ def self_check
118
+ load File.join(@project, CONFIG)
119
+ Nukadoko.load_steps(File.join(@project, STEPS))
120
+ @err.puts "next: read #{LLMS}, written for an agent: the loop, every command, and every finding code; its Ruby section is how a Ruby step is written"
121
+ 0
122
+ rescue StandardError, ScriptError => e
123
+ @err.puts ["error", "unexpected-error", "-", "Self-check failed: #{e.message}"].join("\t")
124
+ @err.puts " do: nuka check"
125
+ 1
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,274 @@
1
+ # frozen_string_literal: true
2
+ # rbs_inline: enabled
3
+
4
+ require "json"
5
+
6
+ # JSON text read as JavaScript's JSON.parse reads it, and refused in V8's
7
+ # words. A claim's json view reports why a text is no JSON, and that reason
8
+ # is part of the record both engines write, so the Ruby engine walks the
9
+ # grammar V8 walks and names the same place. Ruby's own parser accepts
10
+ # what JSON.parse refuses (comments, a NaN under some options), so the walk
11
+ # also decides what is valid; Ruby's parser only builds the value after it.
12
+ # Positions count UTF-16 code units, as a JavaScript string does.
13
+ module Nukadoko
14
+ module JsJson
15
+ class Error < JSON::ParserError; end
16
+
17
+ # Texts V8 names whole, since they are what a JavaScript value turns
18
+ # into when it is passed as text by mistake.
19
+ SPECIAL = ["NaN", "Infinity", "undefined", "[object Object]"].freeze
20
+ CONTEXT = 10
21
+ WHITESPACE = [0x20, 0x09, 0x0a, 0x0d].freeze
22
+ ESCAPES = '"\\/bfnrt'.codepoints.freeze
23
+ HEX = "0123456789abcdefABCDEF".codepoints.freeze
24
+
25
+ # A Failure carries where the walk stopped and what V8 says there.
26
+ Failure = Data.define(:pos, :message)
27
+
28
+ #: (String) -> untyped
29
+ def self.parse(text)
30
+ failure = Walk.new(text).failure
31
+ raise Error, failure if failure
32
+
33
+ begin
34
+ JSON.parse(text)
35
+ rescue JSON::ParserError => e
36
+ # JSON.parse keeps a lone surrogate escape (\ud800) in its string; a
37
+ # Ruby string has no way to hold one, so the text is refused here.
38
+ raise Error, "the text holds an unpaired surrogate escape, which a Ruby string cannot hold" if e.message.include?("surrogate")
39
+
40
+ raise
41
+ end
42
+ end
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(value)
50
+ case value
51
+ when Hash then "{#{value.map { |key, item| "#{JSON.generate(key.to_s)}:#{generate(item)}" }.join(",")}}"
52
+ when Array then "[#{value.map { generate(_1) }.join(",")}]"
53
+ when Float then value.finite? ? Engine::AriaSnapshot.js_number(value) : "null"
54
+ when Symbol then JSON.generate(value.to_s)
55
+ else JSON.generate(value)
56
+ end
57
+ end
58
+
59
+ # Walks the text once and gives V8's message for the first place it is
60
+ # no JSON, or nil.
61
+ class Walk
62
+ #: (String) -> void
63
+ def initialize(text)
64
+ @text = text
65
+ @units = text.encode("UTF-16LE").unpack("v*") #: Array[Integer]
66
+ @pos = 0
67
+ end
68
+
69
+ #: () -> String?
70
+ def failure
71
+ value
72
+ space
73
+ return nil if @pos >= @units.size
74
+
75
+ located("Unexpected non-whitespace character after JSON")
76
+ rescue Stop => e
77
+ e.message
78
+ end
79
+
80
+ private
81
+
82
+ class Stop < StandardError; end
83
+
84
+ #: () -> Integer?
85
+ def peek = @units[@pos]
86
+
87
+ #: () -> void
88
+ def space
89
+ @pos += 1 while (unit = peek) && WHITESPACE.include?(unit)
90
+ end
91
+
92
+ #: (String) -> String
93
+ def located(words)
94
+ before = @units.first(@pos)
95
+ lines = 0
96
+ column = 0
97
+ index = 0
98
+ while index < before.size
99
+ unit = before[index]
100
+ if unit == 0x0d || unit == 0x0a
101
+ lines += 1
102
+ column = 0
103
+ index += 1 if unit == 0x0d && before[index + 1] == 0x0a
104
+ else
105
+ column += 1
106
+ end
107
+ index += 1
108
+ end
109
+ "#{words}#{" in JSON" unless words.end_with?("JSON")} at position #{@pos} (line #{lines + 1} column #{column + 1})"
110
+ end
111
+
112
+ #: (?String?) -> bot
113
+ def stop(words = nil)
114
+ raise Stop, located(words) if words
115
+ raise Stop, "Unexpected end of JSON input" if @pos >= @units.size
116
+ # V8 names the kind of token it found where it names one.
117
+ raise Stop, located("Unexpected number") if peek == 0x2d || digit?
118
+ raise Stop, located("Unexpected string") if peek == 0x22
119
+
120
+ raise Stop, unexpected
121
+ end
122
+
123
+ # V8's message for a character no rule expected: the text itself when
124
+ # it is short, else ten units on each side of the character.
125
+ #: () -> String
126
+ def unexpected
127
+ source = @units
128
+ return "\"#{@text}\" is not valid JSON" if SPECIAL.include?(@text)
129
+
130
+ token = text_of([source[@pos].to_i])
131
+ return "Unexpected token '#{token}', \"#{@text}\" is not valid JSON" if source.size < CONTEXT * 2 + 1
132
+
133
+ if @pos < CONTEXT
134
+ "Unexpected token '#{token}', \"#{text_of(source[0, @pos + CONTEXT] || [])}\"... is not valid JSON"
135
+ elsif @pos < source.size - CONTEXT
136
+ "Unexpected token '#{token}', ...\"#{text_of(source[@pos - CONTEXT, CONTEXT * 2] || [])}\"... is not valid JSON"
137
+ else
138
+ "Unexpected token '#{token}', ...\"#{text_of(source[(@pos - CONTEXT)..] || [])}\" is not valid JSON"
139
+ end
140
+ end
141
+
142
+ # A run of UTF-16 units as text; half of a pair, which a UTF-8 string
143
+ # cannot hold, is the replacement character.
144
+ #: (Array[Integer]) -> String
145
+ def text_of(units)
146
+ units.pack("v*").force_encoding("UTF-16LE").encode("UTF-8", invalid: :replace, undef: :replace)
147
+ end
148
+
149
+ #: () -> void
150
+ def value
151
+ space
152
+ case peek
153
+ when nil then stop
154
+ when 0x22 then string
155
+ when 0x7b then object
156
+ when 0x5b then array
157
+ when 0x2d, 0x30..0x39 then number
158
+ when 0x74 then literal("true")
159
+ when 0x66 then literal("false")
160
+ when 0x6e then literal("null")
161
+ else stop
162
+ end
163
+ end
164
+
165
+ #: (String) -> void
166
+ def literal(word)
167
+ word.each_codepoint do |unit|
168
+ stop if peek != unit
169
+ @pos += 1
170
+ end
171
+ end
172
+
173
+ #: () -> void
174
+ def object
175
+ @pos += 1
176
+ space
177
+ return @pos += 1 if peek == 0x7d
178
+
179
+ first = true
180
+ loop do
181
+ stop(first ? "Expected property name or '}'" : "Expected double-quoted property name") unless peek == 0x22
182
+ first = false
183
+ string
184
+ space
185
+ stop("Expected ':' after property name") unless peek == 0x3a
186
+ @pos += 1
187
+ value
188
+ space
189
+ case peek
190
+ when 0x2c then @pos += 1
191
+ space
192
+ when 0x7d then return @pos += 1
193
+ else stop("Expected ',' or '}' after property value")
194
+ end
195
+ end
196
+ end
197
+
198
+ #: () -> void
199
+ def array
200
+ @pos += 1
201
+ space
202
+ return @pos += 1 if peek == 0x5d
203
+
204
+ loop do
205
+ value
206
+ space
207
+ case peek
208
+ when 0x2c then @pos += 1
209
+ when 0x5d then return @pos += 1
210
+ else stop("Expected ',' or ']' after array element")
211
+ end
212
+ end
213
+ end
214
+
215
+ #: () -> void
216
+ def string
217
+ @pos += 1
218
+ loop do
219
+ unit = peek
220
+ stop("Unterminated string") if unit.nil?
221
+ @pos += 1
222
+ return if unit == 0x22
223
+
224
+ if unit < 0x20
225
+ @pos -= 1
226
+ stop("Bad control character in string literal")
227
+ end
228
+ next unless unit == 0x5c
229
+
230
+ escape = peek
231
+ stop if escape.nil?
232
+ if escape == 0x75
233
+ @pos += 1
234
+ 4.times do
235
+ stop("Bad Unicode escape") unless (hex = peek) && HEX.include?(hex)
236
+ @pos += 1
237
+ end
238
+ else
239
+ stop("Bad escaped character") unless ESCAPES.include?(escape)
240
+ @pos += 1
241
+ end
242
+ end
243
+ end
244
+
245
+ #: () -> void
246
+ def number
247
+ if peek == 0x2d
248
+ @pos += 1
249
+ stop("No number after minus sign") unless digit?
250
+ end
251
+ if peek == 0x30
252
+ @pos += 1
253
+ raise Stop, located("Unexpected number") if digit?
254
+ else
255
+ @pos += 1 while digit?
256
+ end
257
+ if peek == 0x2e
258
+ @pos += 1
259
+ stop("Unterminated fractional number") unless digit?
260
+ @pos += 1 while digit?
261
+ end
262
+ return unless [0x65, 0x45].include?(peek)
263
+
264
+ @pos += 1
265
+ @pos += 1 if [0x2b, 0x2d].include?(peek)
266
+ stop("Exponent part is missing a number") unless digit?
267
+ @pos += 1 while digit?
268
+ end
269
+
270
+ #: () -> bool
271
+ def digit? = (unit = peek) ? unit.between?(0x30, 0x39) : false
272
+ end
273
+ end
274
+ end