summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAlexander Momchilov <amomchilov@users.noreply.github.com>2024-12-12 20:28:27 -0500
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2024-12-16 10:10:34 +0900
commit41e24c2f3e9a5ff29cccbfe92ecf4d412e5a4e0d (patch)
treea37ff3e276f7a7c2f988b236b4534e23c96f3cc6 /doc
parent219c2eee5a4a2b76f054c396635893e6139694a4 (diff)
[ruby/strscan] [DOC] Add syntax highlighting to MarkDown code blocks
(https://github.com/ruby/strscan/pull/126) Split off from https://github.com/ruby/ruby/pull/12322 https://github.com/ruby/strscan/commit/9bee37e0f5
Diffstat (limited to 'doc')
-rw-r--r--doc/strscan/helper_methods.md12
-rw-r--r--doc/strscan/methods/get_byte.md4
-rw-r--r--doc/strscan/methods/get_charpos.md2
-rw-r--r--doc/strscan/methods/get_pos.md2
-rw-r--r--doc/strscan/methods/getch.md6
-rw-r--r--doc/strscan/methods/scan.md4
-rw-r--r--doc/strscan/methods/scan_until.md4
-rw-r--r--doc/strscan/methods/set_pos.md4
-rw-r--r--doc/strscan/methods/skip.md2
-rw-r--r--doc/strscan/methods/skip_until.md4
-rw-r--r--doc/strscan/methods/terminate.md2
-rw-r--r--doc/strscan/strscan.md30
12 files changed, 36 insertions, 40 deletions
diff --git a/doc/strscan/helper_methods.md b/doc/strscan/helper_methods.md
index 6555a2ce66..9fb1d79bba 100644
--- a/doc/strscan/helper_methods.md
+++ b/doc/strscan/helper_methods.md
@@ -10,7 +10,7 @@ Display scanner's situation:
- Character position (`#charpos`)
- Target string (`#rest`) and size (`#rest_size`).
-```
+```rb
scanner = StringScanner.new('foobarbaz')
scanner.scan(/foo/)
put_situation(scanner)
@@ -25,7 +25,7 @@ put_situation(scanner)
Display the scanner's match values:
-```
+```rb
scanner = StringScanner.new('Fri Dec 12 1975 14:39')
pattern = /(?<wday>\w+) (?<month>\w+) (?<day>\d+) /
scanner.match?(pattern)
@@ -53,7 +53,7 @@ put_match_values(scanner)
Returns whether the scanner's match values are all properly cleared:
-```
+```rb
scanner = StringScanner.new('foobarbaz')
match_values_cleared?(scanner) # => true
put_match_values(scanner)
@@ -75,7 +75,7 @@ match_values_cleared?(scanner) # => false
## The Code
-```
+```rb
def put_situation(scanner)
puts '# Situation:'
puts "# pos: #{scanner.pos}"
@@ -83,9 +83,7 @@ def put_situation(scanner)
puts "# rest: #{scanner.rest.inspect}"
puts "# rest_size: #{scanner.rest_size}"
end
-```
-```
def put_match_values(scanner)
puts '# Basic match values:'
puts "# matched?: #{scanner.matched?}"
@@ -109,9 +107,7 @@ def put_match_values(scanner)
end
end
end
-```
-```
def match_values_cleared?(scanner)
scanner.matched? == false &&
scanner.matched_size.nil? &&
diff --git a/doc/strscan/methods/get_byte.md b/doc/strscan/methods/get_byte.md
index 2f23be1899..3208d77158 100644
--- a/doc/strscan/methods/get_byte.md
+++ b/doc/strscan/methods/get_byte.md
@@ -10,7 +10,7 @@ Returns the next byte, if available:
- Increments the [byte position][2].
- Adjusts the [character position][7].
- ```
+ ```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
# => #<StringScanner 0/15 @ "\xE3\x81\x93\xE3\x82...">
scanner.string # => "こんにちは"
@@ -24,7 +24,7 @@ Returns the next byte, if available:
- Otherwise, returns `nil`, and does not change the positions.
- ```
+ ```rb
scanner.terminate
[scanner.get_byte, scanner.pos, scanner.charpos] # => [nil, 15, 5]
```
diff --git a/doc/strscan/methods/get_charpos.md b/doc/strscan/methods/get_charpos.md
index f77563c860..954fcf5b44 100644
--- a/doc/strscan/methods/get_charpos.md
+++ b/doc/strscan/methods/get_charpos.md
@@ -5,7 +5,7 @@ Returns the [character position][7] (initially zero),
which may be different from the [byte position][2]
given by method #pos:
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.getch # => "こ" # 3-byte character.
diff --git a/doc/strscan/methods/get_pos.md b/doc/strscan/methods/get_pos.md
index 56bcef3274..81bbb2345e 100644
--- a/doc/strscan/methods/get_pos.md
+++ b/doc/strscan/methods/get_pos.md
@@ -4,7 +4,7 @@ call-seq:
Returns the integer [byte position][2],
which may be different from the [character position][7]:
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos # => 0
diff --git a/doc/strscan/methods/getch.md b/doc/strscan/methods/getch.md
index b57732ad7c..3dd70e4c5b 100644
--- a/doc/strscan/methods/getch.md
+++ b/doc/strscan/methods/getch.md
@@ -12,7 +12,7 @@ if available:
- Increments the [byte position][2]
by the size (in bytes) of the character.
- ```
+ ```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
[scanner.getch, scanner.pos, scanner.charpos] # => ["こ", 3, 1]
@@ -27,7 +27,7 @@ if available:
(that is, not at its beginning),
behaves like #get_byte (returns a 1-byte character):
- ```
+ ```rb
scanner.pos = 1
[scanner.getch, scanner.pos, scanner.charpos] # => ["\x81", 2, 2]
[scanner.getch, scanner.pos, scanner.charpos] # => ["\x93", 3, 1]
@@ -37,7 +37,7 @@ if available:
- If the [position][2] is at the end of the [stored string][1],
returns `nil` and does not modify the positions:
- ```
+ ```rb
scanner.terminate
[scanner.getch, scanner.pos, scanner.charpos] # => [nil, 15, 5]
```
diff --git a/doc/strscan/methods/scan.md b/doc/strscan/methods/scan.md
index 714fa9910a..22ddd368b6 100644
--- a/doc/strscan/methods/scan.md
+++ b/doc/strscan/methods/scan.md
@@ -11,7 +11,7 @@ If the match succeeds:
and may increment the [character position][7].
- Sets [match values][9].
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos = 6
@@ -45,7 +45,7 @@ If the match fails:
- Does not increment byte and character positions.
- Clears match values.
-```
+```rb
scanner.scan(/nope/) # => nil
match_values_cleared?(scanner) # => true
```
diff --git a/doc/strscan/methods/scan_until.md b/doc/strscan/methods/scan_until.md
index 3b7ff2c3a9..9a8c7c02f6 100644
--- a/doc/strscan/methods/scan_until.md
+++ b/doc/strscan/methods/scan_until.md
@@ -12,7 +12,7 @@ If the match attempt succeeds:
- Returns the matched substring.
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos = 6
@@ -46,7 +46,7 @@ If the match attempt fails:
- Returns `nil`.
- Does not update positions.
-```
+```rb
scanner.scan_until(/nope/) # => nil
match_values_cleared?(scanner) # => true
```
diff --git a/doc/strscan/methods/set_pos.md b/doc/strscan/methods/set_pos.md
index 230177109c..3b7abe65e3 100644
--- a/doc/strscan/methods/set_pos.md
+++ b/doc/strscan/methods/set_pos.md
@@ -9,7 +9,7 @@ Does not affect [match values][9].
For non-negative `n`, sets the position to `n`:
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos = 3 # => 3
@@ -19,7 +19,7 @@ scanner.charpos # => 1
For negative `n`, counts from the end of the [stored string][1]:
-```
+```rb
scanner.pos = -9 # => -9
scanner.pos # => 6
scanner.rest # => "にちは"
diff --git a/doc/strscan/methods/skip.md b/doc/strscan/methods/skip.md
index 656f134c5a..10a329e0e4 100644
--- a/doc/strscan/methods/skip.md
+++ b/doc/strscan/methods/skip.md
@@ -11,7 +11,7 @@ If the match succeeds:
- Sets [match values][9].
- Returns the size (bytes) of the matched substring.
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos = 6
diff --git a/doc/strscan/methods/skip_until.md b/doc/strscan/methods/skip_until.md
index 5187a4826f..b7dacf6da1 100644
--- a/doc/strscan/methods/skip_until.md
+++ b/doc/strscan/methods/skip_until.md
@@ -10,7 +10,7 @@ If the match attempt succeeds:
- Sets [match values][9].
- Returns the size of the matched substring.
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.pos = 6
@@ -43,7 +43,7 @@ If the match attempt fails:
- Clears match values.
- Returns `nil`.
-```
+```rb
scanner.skip_until(/nope/) # => nil
match_values_cleared?(scanner) # => true
```
diff --git a/doc/strscan/methods/terminate.md b/doc/strscan/methods/terminate.md
index fd55727099..b03b37d2a2 100644
--- a/doc/strscan/methods/terminate.md
+++ b/doc/strscan/methods/terminate.md
@@ -7,7 +7,7 @@ returns +self+:
- Sets both [positions][11] to end-of-stream.
- Clears [match values][9].
-```
+```rb
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string # => "こんにちは"
scanner.scan_until(/に/)
diff --git a/doc/strscan/strscan.md b/doc/strscan/strscan.md
index 558568dc43..dea87e0d43 100644
--- a/doc/strscan/strscan.md
+++ b/doc/strscan/strscan.md
@@ -1,7 +1,7 @@
\Class `StringScanner` supports processing a stored string as a stream;
this code creates a new `StringScanner` object with string `'foobarbaz'`:
-```
+```rb
require 'strscan'
scanner = StringScanner.new('foobarbaz')
```
@@ -10,13 +10,13 @@ scanner = StringScanner.new('foobarbaz')
All examples here assume that `StringScanner` has been required:
-```
+```rb
require 'strscan'
```
Some examples here assume that these constants are defined:
-```
+```rb
MULTILINE_TEXT = <<~EOT
Go placidly amid the noise and haste,
and remember what peace there may be in silence.
@@ -45,7 +45,7 @@ This code creates a `StringScanner` object
(we'll call it simply a _scanner_),
and shows some of its basic properties:
-```
+```rb
scanner = StringScanner.new('foobarbaz')
scanner.string # => "foobarbaz"
put_situation(scanner)
@@ -138,7 +138,7 @@ To get or set the byte position:
Many methods use the byte position as the basis for finding matches;
many others set, increment, or decrement the byte position:
-```
+```rb
scanner = StringScanner.new('foobar')
scanner.pos # => 0
scanner.scan(/foo/) # => "foo" # Match found.
@@ -176,7 +176,7 @@ see:
Example (string includes multi-byte characters):
-```
+```rb
scanner = StringScanner.new(ENGLISH_TEXT) # Five 1-byte characters.
scanner.concat(HIRAGANA_TEXT) # Five 3-byte characters
scanner.string # => "Helloこんにちは" # Twenty bytes in all.
@@ -216,7 +216,7 @@ and its size is returned by method #rest_size.
Examples:
-```
+```rb
scanner = StringScanner.new('foobarbaz')
put_situation(scanner)
# Situation:
@@ -430,7 +430,7 @@ See examples below.
Successful basic match attempt (no captures):
-```
+```rb
scanner = StringScanner.new('foobarbaz')
scanner.exist?(/bar/)
put_match_values(scanner)
@@ -452,7 +452,7 @@ put_match_values(scanner)
Failed basic match attempt (no captures);
-```
+```rb
scanner = StringScanner.new('foobarbaz')
scanner.exist?(/nope/)
match_values_cleared?(scanner) # => true
@@ -460,7 +460,7 @@ match_values_cleared?(scanner) # => true
Successful unnamed capture match attempt:
-```
+```rb
scanner = StringScanner.new('foobarbazbatbam')
scanner.exist?(/(foo)bar(baz)bat(bam)/)
put_match_values(scanner)
@@ -486,7 +486,7 @@ put_match_values(scanner)
Successful named capture match attempt;
same as unnamed above, except for #named_captures:
-```
+```rb
scanner = StringScanner.new('foobarbazbatbam')
scanner.exist?(/(?<x>foo)bar(?<y>baz)bat(?<z>bam)/)
scanner.named_captures # => {"x"=>"foo", "y"=>"baz", "z"=>"bam"}
@@ -494,7 +494,7 @@ scanner.named_captures # => {"x"=>"foo", "y"=>"baz", "z"=>"bam"}
Failed unnamed capture match attempt:
-```
+```rb
scanner = StringScanner.new('somestring')
scanner.exist?(/(foo)bar(baz)bat(bam)/)
match_values_cleared?(scanner) # => true
@@ -503,7 +503,7 @@ match_values_cleared?(scanner) # => true
Failed named capture match attempt;
same as unnamed above, except for #named_captures:
-```
+```rb
scanner = StringScanner.new('somestring')
scanner.exist?(/(?<x>foo)bar(?<y>baz)bat(?<z>bam)/)
match_values_cleared?(scanner) # => false
@@ -518,7 +518,7 @@ which determines the meaning of `'\A'`:
* `false` (the default): matches the current byte position.
- ```
+ ```rb
scanner = StringScanner.new('foobar')
scanner.scan(/\A./) # => "f"
scanner.scan(/\A./) # => "o"
@@ -529,7 +529,7 @@ which determines the meaning of `'\A'`:
* `true`: matches the beginning of the target substring;
never matches unless the byte position is zero:
- ```
+ ```rb
scanner = StringScanner.new('foobar', fixed_anchor: true)
scanner.scan(/\A./) # => "f"
scanner.scan(/\A./) # => nil