img_to_script 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +25 -0
  3. data/.vscode/launch.json +21 -0
  4. data/CHANGELOG.md +7 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +271 -0
  7. data/Rakefile +16 -0
  8. data/img_to_script.gemspec +41 -0
  9. data/lib/img_to_script/abs_token_type.rb +33 -0
  10. data/lib/img_to_script/abstract_token/abs_func.rb +19 -0
  11. data/lib/img_to_script/abstract_token/abstract_token.rb +23 -0
  12. data/lib/img_to_script/abstract_token/assign_value.rb +20 -0
  13. data/lib/img_to_script/abstract_token/clear_screen.rb +16 -0
  14. data/lib/img_to_script/abstract_token/data_read.rb +19 -0
  15. data/lib/img_to_script/abstract_token/data_store.rb +19 -0
  16. data/lib/img_to_script/abstract_token/draw_chunk_by_hex_value.rb +19 -0
  17. data/lib/img_to_script/abstract_token/draw_line_by_abs_coords.rb +22 -0
  18. data/lib/img_to_script/abstract_token/draw_pixel_by_abs_coords.rb +20 -0
  19. data/lib/img_to_script/abstract_token/go_to.rb +19 -0
  20. data/lib/img_to_script/abstract_token/if_condition.rb +20 -0
  21. data/lib/img_to_script/abstract_token/loop_begin.rb +21 -0
  22. data/lib/img_to_script/abstract_token/loop_end.rb +19 -0
  23. data/lib/img_to_script/abstract_token/math_add.rb +20 -0
  24. data/lib/img_to_script/abstract_token/math_greater_than.rb +20 -0
  25. data/lib/img_to_script/abstract_token/math_mult.rb +20 -0
  26. data/lib/img_to_script/abstract_token/math_sub.rb +20 -0
  27. data/lib/img_to_script/abstract_token/move_point_to_abs_coords.rb +20 -0
  28. data/lib/img_to_script/abstract_token/parentheses.rb +19 -0
  29. data/lib/img_to_script/abstract_token/program_begin.rb +16 -0
  30. data/lib/img_to_script/abstract_token/program_end.rb +16 -0
  31. data/lib/img_to_script/abstract_token/remark.rb +19 -0
  32. data/lib/img_to_script/abstract_token/sign_func.rb +19 -0
  33. data/lib/img_to_script/abstract_token/wait.rb +19 -0
  34. data/lib/img_to_script/abstract_token.rb +8 -0
  35. data/lib/img_to_script/container.rb +26 -0
  36. data/lib/img_to_script/current_line_placeholder.rb +40 -0
  37. data/lib/img_to_script/formatter.rb +34 -0
  38. data/lib/img_to_script/generators/generator.rb +134 -0
  39. data/lib/img_to_script/generators/hex_mask/default.rb +24 -0
  40. data/lib/img_to_script/generators/hex_mask/enhanced.rb +220 -0
  41. data/lib/img_to_script/generators/hex_mask/hex_mask.rb +100 -0
  42. data/lib/img_to_script/generators/hex_mask.rb +13 -0
  43. data/lib/img_to_script/generators/run_length_encoding/horizontal.rb +78 -0
  44. data/lib/img_to_script/generators/run_length_encoding/run_length_encoding.rb +304 -0
  45. data/lib/img_to_script/generators/run_length_encoding/vertical.rb +79 -0
  46. data/lib/img_to_script/generators/run_length_encoding.rb +10 -0
  47. data/lib/img_to_script/generators/segmental/data_read_draw/data_read_draw.rb +70 -0
  48. data/lib/img_to_script/generators/segmental/data_read_draw/horizontal.rb +54 -0
  49. data/lib/img_to_script/generators/segmental/data_read_draw/vertical.rb +54 -0
  50. data/lib/img_to_script/generators/segmental/data_read_draw.rb +18 -0
  51. data/lib/img_to_script/generators/segmental/direct_draw/direct_draw.rb +62 -0
  52. data/lib/img_to_script/generators/segmental/direct_draw/horizontal.rb +16 -0
  53. data/lib/img_to_script/generators/segmental/direct_draw/vertical.rb +16 -0
  54. data/lib/img_to_script/generators/segmental/direct_draw.rb +12 -0
  55. data/lib/img_to_script/generators/segmental/horizontal_mixin.rb +32 -0
  56. data/lib/img_to_script/generators/segmental/segmental.rb +101 -0
  57. data/lib/img_to_script/generators/segmental/vertical_mixin.rb +38 -0
  58. data/lib/img_to_script/generators/segmental.rb +10 -0
  59. data/lib/img_to_script/generators.rb +27 -0
  60. data/lib/img_to_script/import.rb +5 -0
  61. data/lib/img_to_script/language_token.rb +8 -0
  62. data/lib/img_to_script/languages/mk90_basic/formatters/formatter.rb +49 -0
  63. data/lib/img_to_script/languages/mk90_basic/formatters/minificator.rb +316 -0
  64. data/lib/img_to_script/languages/mk90_basic/formatters/sliceable_tokens_mixin.rb +15 -0
  65. data/lib/img_to_script/languages/mk90_basic/formatters.rb +13 -0
  66. data/lib/img_to_script/languages/mk90_basic/mk90_basic_token.rb +59 -0
  67. data/lib/img_to_script/languages/mk90_basic/translators/mixin.rb +205 -0
  68. data/lib/img_to_script/languages/mk90_basic/translators/mk90_basic_10.rb +27 -0
  69. data/lib/img_to_script/languages/mk90_basic/translators/mk90_basic_20.rb +27 -0
  70. data/lib/img_to_script/languages/mk90_basic/translators/translator.rb +205 -0
  71. data/lib/img_to_script/languages/mk90_basic/translators.rb +13 -0
  72. data/lib/img_to_script/languages/mk90_basic.rb +17 -0
  73. data/lib/img_to_script/languages.rb +10 -0
  74. data/lib/img_to_script/task.rb +26 -0
  75. data/lib/img_to_script/translator.rb +31 -0
  76. data/lib/img_to_script/version.rb +5 -0
  77. data/lib/img_to_script.rb +19 -0
  78. data/sig/img_to_script.rbs +4 -0
  79. metadata +204 -0
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ module RunLengthEncoding
6
+ #
7
+ # RLE - vertical scanlines.
8
+ #
9
+ class Vertical < RunLengthEncoding
10
+ private
11
+
12
+ def _generate
13
+ _transpose
14
+ @pixels = @image.get_pixels(0, 0, @image.width, @image.height)
15
+ _encode_pixels
16
+ _append_decoder
17
+ end
18
+
19
+ def _append_decoder
20
+ @image_size = @image.width + @y_offset
21
+ @segment_size = @image_size - 1
22
+
23
+ @major_axis_symbol = Y_LBL
24
+ @minor_axis_symbol = X_LBL
25
+
26
+ @major_axis_value = @y_offset
27
+
28
+ @part_line_pattern = _part_line_pattern
29
+ @full_line_pattern = _full_line_pattern
30
+
31
+ super
32
+ end
33
+
34
+ #
35
+ # Part-length line, i.e. a line that fills only
36
+ # a part of the scan line.
37
+ #
38
+ # Formatted for the vertical scan lines.
39
+ #
40
+ def _part_line_pattern
41
+ AbstractToken::DrawLineByAbsCoords.new(
42
+ x0: X_LBL,
43
+ y0: Y_LBL,
44
+ x1: X_LBL,
45
+ y1: _y1_expression
46
+ )
47
+ end
48
+
49
+ #
50
+ # Expression to evaluate y1 point.
51
+ #
52
+ def _y1_expression
53
+ AbstractToken::MathSub.new(
54
+ left: AbstractToken::MathAdd.new(
55
+ left: Y_LBL,
56
+ right: READ_VAR
57
+ ),
58
+ right: "1"
59
+ )
60
+ end
61
+
62
+ #
63
+ # Full-length line pattern, i.e. a line that fills
64
+ # the whole scan line.
65
+ #
66
+ # Formatted for the vertical scan lines.
67
+ #
68
+ def _full_line_pattern
69
+ AbstractToken::DrawLineByAbsCoords.new(
70
+ x0: X_LBL,
71
+ y0: Y_LBL,
72
+ x1: X_LBL,
73
+ y1: @segment_size
74
+ )
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ #
6
+ # Simple RLE with a depacker.
7
+ #
8
+ module RunLengthEncoding; end
9
+ end
10
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ module Segmental
6
+ module DataReadDraw
7
+ #
8
+ # Base class for the 'DATA..READ' draw method.
9
+ #
10
+ # The segment's coordinates are stored via the DATA statement. Three
11
+ # coordinates are stored: two coordinates of the 'major' axis, and oneI
12
+ # coordinate of the 'minor' axis.
13
+ #
14
+ # The FOR..NEXT loop is defined after the DATA statements. It loops
15
+ # through the array of coordinates, reads three values in a row, and
16
+ # passes the values to the statement that draws a line.
17
+ #
18
+ class DataReadDraw < Segmental
19
+ private
20
+
21
+ def _generate
22
+ @data = []
23
+
24
+ super
25
+ end
26
+
27
+ #
28
+ # Append a loop to read values from DATA and pass them to the DRAWD
29
+ # statement that draws a line.
30
+ #
31
+ def _append_decoder
32
+ _append_data
33
+ _loop_begin
34
+ _read
35
+ _draw_line
36
+ _loop_end
37
+ end
38
+
39
+ def _append_data
40
+ @tokens.append(
41
+ AbstractToken::DataStore.new(
42
+ data: @data,
43
+ require_nl: true
44
+ )
45
+ )
46
+ end
47
+
48
+ def _loop_begin
49
+ @tokens.append(
50
+ AbstractToken::LoopBegin.new(
51
+ start_value: 1,
52
+ end_value: @n_black_segments,
53
+ var_name: LOOP_VAR,
54
+ require_nl: true
55
+ )
56
+ )
57
+ end
58
+
59
+ def _loop_end
60
+ @tokens.append(
61
+ AbstractToken::LoopEnd.new(
62
+ var_name: LOOP_VAR
63
+ )
64
+ )
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ module Segmental
6
+ module DataReadDraw
7
+ #
8
+ # DATA...READ (with horizontal scan lines).
9
+ #
10
+ class Horizontal < DataReadDraw
11
+ include HorizontalMixin
12
+
13
+ private
14
+
15
+ def _generate
16
+ @data = []
17
+
18
+ super
19
+ end
20
+
21
+ def _read
22
+ @tokens.append(
23
+ AbstractToken::DataRead.new(
24
+ var_list: READ_PATTERN_HORIZ
25
+ )
26
+ )
27
+ end
28
+
29
+ def _draw_line
30
+ @tokens.append(
31
+ AbstractToken::DrawLineByAbsCoords.new(
32
+ x0: X0_LBL,
33
+ y0: Y_LBL,
34
+ x1: X1_LBL,
35
+ y1: Y_LBL
36
+ )
37
+ )
38
+ end
39
+
40
+ #
41
+ # Convert a chunk of black pixel(s) to three coordinates: x0, x1, y.
42
+ #
43
+ # @param [Integer] count
44
+ # Run-length of the pixel block.
45
+ #
46
+ def _encode_chunk(count)
47
+ coordinates = _segment_coordinates(count)
48
+ @data.push(coordinates[:x0], coordinates[:x1], coordinates[:y0])
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ module Segmental
6
+ module DataReadDraw
7
+ #
8
+ # DATA...READ (with vertical scan lines).
9
+ #
10
+ class Vertical < DataReadDraw
11
+ include VerticalMixin
12
+
13
+ private
14
+
15
+ def _generate
16
+ @data = []
17
+
18
+ super
19
+ end
20
+
21
+ def _read
22
+ @tokens.append(
23
+ AbstractToken::DataRead.new(
24
+ var_list: READ_PATTERN_VERT
25
+ )
26
+ )
27
+ end
28
+
29
+ def _draw_line
30
+ @tokens.append(
31
+ AbstractToken::DrawLineByAbsCoords.new(
32
+ x0: X_LBL,
33
+ y0: Y0_LBL,
34
+ x1: X_LBL,
35
+ y1: Y1_LBL
36
+ )
37
+ )
38
+ end
39
+
40
+ #
41
+ # Convert a chunk of black pixel(s) to three coordinates: y0, y1, x.
42
+ #
43
+ # @param [Integer] count
44
+ # Run-length of the pixel block.
45
+ #
46
+ def _encode_chunk(count)
47
+ coordinates = _segment_coordinates(count)
48
+ @data.push(coordinates[:y0], coordinates[:y1], coordinates[:x0])
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ module Segmental
6
+ module DataReadDraw
7
+ X0_LBL = :a
8
+ X1_LBL = :b
9
+
10
+ Y0_LBL = :c
11
+ Y1_LBL = :d
12
+
13
+ READ_PATTERN_HORIZ = [X0_LBL, X1_LBL, Y_LBL].freeze
14
+ READ_PATTERN_VERT = [Y0_LBL, Y1_LBL, X_LBL].freeze
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ module Segmental
6
+ module DirectDraw
7
+ #
8
+ # Base class for the 'direct' draw method. Segments are being drawed by
9
+ # calling the 'draw a pixel' and the 'draw a line' statements, and the
10
+ # coordinates of the segments are *directly* hard-coded as the statement's
11
+ # arguments. Hence the name.
12
+ #
13
+ class DirectDraw < Segmental
14
+ private
15
+
16
+ #
17
+ # Convert a chunk of black pixel(s) to a respective BASIC statement:
18
+ #
19
+ # - for a sequence of black pixels: append 'draw a line' statement;
20
+ # - for a single black pixel: append 'draw a dot' statement.
21
+ #
22
+ # @param [Integer] count
23
+ # Run-length of the pixel block.
24
+ #
25
+ def _encode_chunk(count)
26
+ if count > 1
27
+ _append_line(_segment_coordinates(count))
28
+ else
29
+ _append_dot(_segment_coordinates(count))
30
+ end
31
+ end
32
+
33
+ #
34
+ # Draw a dot by a pair of coordinates (x, y).
35
+ #
36
+ def _append_dot(coordinates)
37
+ @tokens.append(
38
+ AbstractToken::DrawPixelByAbsCoords.new(
39
+ x: coordinates[:x0],
40
+ y: coordinates[:y0]
41
+ )
42
+ )
43
+ end
44
+
45
+ #
46
+ # Draw a line by a pairs of coordinates (x0, y0), (x1, y1).
47
+ #
48
+ def _append_line(coordinates)
49
+ @tokens.append(
50
+ AbstractToken::DrawLineByAbsCoords.new(
51
+ x0: coordinates[:x0],
52
+ y0: coordinates[:y0],
53
+ x1: coordinates[:x1],
54
+ y1: coordinates[:y1]
55
+ )
56
+ )
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ module Segmental
6
+ module DirectDraw
7
+ #
8
+ # Horizontal scan lines.
9
+ #
10
+ class Horizontal < DirectDraw
11
+ include HorizontalMixin
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ module Segmental
6
+ module DirectDraw
7
+ #
8
+ # Vertical scan lines.
9
+ #
10
+ class Vertical < DirectDraw
11
+ include VerticalMixin
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ module Segmental
6
+ #
7
+ # @see direct_draw
8
+ #
9
+ module DirectDraw; end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ module Segmental
6
+ #
7
+ # Methods specific to the horizontal scan lines.
8
+ #
9
+ module HorizontalMixin
10
+ private
11
+
12
+ #
13
+ # Return the segment's coordinates x0, y0, x1, y1.
14
+ #
15
+ # Formatted for the horizontal scan lines.
16
+ #
17
+ # @param [Integer] segment_length
18
+ #
19
+ # @return [Hash{ Symbol => Integer }]
20
+ #
21
+ def _segment_coordinates(segment_length)
22
+ {
23
+ x0: @major_axis + @x_offset,
24
+ y0: @minor_axis + @y_offset,
25
+ x1: @major_axis + @x_offset + segment_length - 1,
26
+ y1: @minor_axis + @y_offset
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ module Segmental
6
+ #
7
+ # Base class for the segmental generators.
8
+ #
9
+ # Segmental generators are designed to scan an image vertically or horizontaly.
10
+ # In each scan line the isolated black px. segments are being parced out to
11
+ # get their coordinates (x0, y0), (x1, y1). Drawing lines using these coordinates
12
+ # will render the image on the target device.
13
+ #
14
+ class Segmental < Generator
15
+ SCAN_LINE_HEIGHT = 1
16
+
17
+ private
18
+
19
+ def _generate
20
+ # Keeps track of all black segment in the image.
21
+ # This value will be used in the depacker (in the DATA..READ scenario).
22
+ @n_black_segments = 0
23
+
24
+ @minor_axis = 0
25
+
26
+ _scan_image
27
+ _append_decoder
28
+ end
29
+
30
+ #
31
+ # Loop through all scan lines in the image.
32
+ #
33
+ def _scan_image
34
+ (0...@image.height).each do
35
+ @major_axis = 0
36
+ _process_scan_line(_encode_scan_line(_get_scan_line))
37
+ @minor_axis += 1
38
+ end
39
+ end
40
+
41
+ #
42
+ # Grab a horizontal line from the image.
43
+ #
44
+ # (To make a vertical scan line: simply transpose the image before a scan.)
45
+ #
46
+ # @return [Array<Magick::Pixel>]
47
+ #
48
+ def _get_scan_line
49
+ @image.get_pixels(@major_axis, @minor_axis, @image.width, SCAN_LINE_HEIGHT)
50
+ end
51
+
52
+ #
53
+ # Encode scan line with the RLE.
54
+ #
55
+ # @param [Array<Magick::Pixel>] scan_line
56
+ # Scan line to encode.
57
+ #
58
+ # @return [Array<RunLengthEncodingRb::RLEElement>]
59
+ #
60
+ def _encode_scan_line(scan_line)
61
+ RunLengthEncodingRb.encode(scan_line)
62
+ end
63
+
64
+ #
65
+ # Process current RLE-encoded scan line.
66
+ #
67
+ # @return [Array<RunLengthEncodingRb::RLEElement>] encoded_scan_line
68
+ #
69
+ def _process_scan_line(encoded_scan_line)
70
+ encoded_scan_line.each do |e|
71
+ _process_scan_line_chunk(e)
72
+ @major_axis += e.run_length
73
+ end
74
+ end
75
+
76
+ #
77
+ # Process a chunk of white or black pixels from the current scan line.
78
+ #
79
+ # Depending on the color value of the chunk, the chunk either gets ignored
80
+ # (white pixels), or gets processed to be appended to the result script
81
+ # (black pixels) as a respective statement.
82
+ #
83
+ # @param [RunLengthEncodingRb::RLEElement] element
84
+ # An RLE element.
85
+ #
86
+ def _process_scan_line_chunk(element)
87
+ pixel_color = element.chunk.to_color
88
+ return unless pixel_color == "black"
89
+
90
+ _encode_chunk(element.run_length)
91
+ @n_black_segments += 1
92
+ end
93
+
94
+ #
95
+ # Reserved for the DATA..READ scenario.
96
+ #
97
+ def _append_decoder; end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ module Segmental
6
+ #
7
+ # Methods specific to the vertical scan lines.
8
+ #
9
+ module VerticalMixin
10
+ private
11
+
12
+ def _generate
13
+ _transpose
14
+
15
+ super
16
+ end
17
+
18
+ #
19
+ # Return the segment's coordinates x0, y0, x1, y1.
20
+ #
21
+ # Formatted for the vertical scan lines.
22
+ #
23
+ # @param [Integer] segment_length
24
+ #
25
+ # @return [Hash{ Symbol => Integer }]
26
+ #
27
+ def _segment_coordinates(segment_length)
28
+ {
29
+ x0: @minor_axis + @x_offset,
30
+ y0: @major_axis + @y_offset,
31
+ x1: @minor_axis + @x_offset,
32
+ y1: @major_axis + @y_offset + segment_length - 1
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Generators
5
+ #
6
+ # @see segmental
7
+ #
8
+ module Segmental; end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ #
5
+ # Namespace for generators.
6
+ #
7
+ # Generators generate array of abstract tokens that represent the image
8
+ # in terms of simple operations, e.g.: draw a line, draw a pixel, etc.
9
+ #
10
+ module Generators
11
+ X_LBL = :x
12
+ Y_LBL = :y
13
+
14
+ LOOP_VAR = :i
15
+ READ_VAR = :l
16
+
17
+ WAIT_LOOP_COUNT = 100
18
+ WAIT_TIME = 1024
19
+
20
+ X_OFFSET = 0
21
+ Y_OFFSET = 0
22
+ CLEAR_SCREEN = true
23
+ PAUSE_PROGRAM = true
24
+ PRORGAM_BEGIN_LBL = false
25
+ PROGRAM_END_LBL = false
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ Import = Dry::AutoInject(Container)
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ #
5
+ # Base class for a target language's statement.
6
+ #
7
+ class LanguageToken; end
8
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImgToScript
4
+ module Languages
5
+ module MK90Basic
6
+ module Formatters
7
+ #
8
+ # MK90 BASIC formatter base class.
9
+ #
10
+ class Formatter < ImgToScript::Formatter
11
+ setting :line_offset, default: LINE_OFFSET
12
+ setting :line_step, default: LINE_STEP
13
+ setting :max_chars_per_line, default: MAX_CHARS_PER_LINE
14
+ setting :number_lines, default: true
15
+
16
+ private
17
+
18
+ def _format(basic_tokens, **)
19
+ _apply_config
20
+ _calc_initial_line_number
21
+
22
+ @script = []
23
+
24
+ _process_tokens(basic_tokens)
25
+
26
+ @script
27
+ end
28
+
29
+ def _process_tokens(basic_tokens)
30
+ basic_tokens.each do |token|
31
+ _append_token(token)
32
+ end
33
+ end
34
+
35
+ def _apply_config
36
+ @line_offset = config.line_offset
37
+ @line_step = config.line_step
38
+ @max_chars_per_line = config.max_chars_per_line
39
+ @number_lines = config.number_lines
40
+ end
41
+
42
+ def _calc_initial_line_number
43
+ @n_line = @line_offset - @line_step
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end