livetext 0.9.21 → 0.9.25

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 (109) hide show
  1. checksums.yaml +4 -4
  2. data/README.lt3 +8 -8
  3. data/bin/livetext +57 -40
  4. data/imports/bookish.rb +89 -90
  5. data/imports/calibre.rb +3 -3
  6. data/imports/livemagick.rb +17 -17
  7. data/imports/markdown.rb +10 -10
  8. data/imports/pyggish.rb +15 -47
  9. data/imports/tutorial.rb +18 -18
  10. data/lib/cmdargs.rb +10 -6
  11. data/lib/{errors.rb → livetext/errors.rb} +1 -1
  12. data/lib/{formatline.rb → livetext/formatline.rb} +69 -125
  13. data/lib/livetext/funcall.rb +84 -0
  14. data/lib/{functions.rb → livetext/functions.rb} +16 -3
  15. data/lib/livetext/global_helpers.rb +37 -0
  16. data/lib/livetext/handler/import.rb +44 -0
  17. data/lib/livetext/handler/mixin.rb +37 -0
  18. data/lib/livetext/handler.rb +3 -0
  19. data/lib/{helpers.rb → livetext/helpers.rb} +89 -67
  20. data/lib/{html.rb → livetext/html.rb} +3 -2
  21. data/lib/{parser → livetext/parser}/general.rb +0 -3
  22. data/lib/{parser → livetext/parser}/set.rb +1 -6
  23. data/lib/{parser → livetext/parser}/string.rb +2 -2
  24. data/lib/{parser.rb → livetext/parser.rb} +0 -1
  25. data/lib/livetext/parsing.rb +29 -0
  26. data/lib/livetext/paths.rb +13 -0
  27. data/lib/livetext/processor.rb +89 -0
  28. data/lib/livetext/reopen.rb +12 -0
  29. data/lib/livetext/skeleton.rb +17 -0
  30. data/lib/{standard.rb → livetext/standard.rb} +152 -122
  31. data/lib/livetext/userapi.rb +153 -0
  32. data/lib/livetext/version.rb +6 -0
  33. data/lib/livetext.rb +66 -27
  34. data/plugin/bookish.rb +85 -85
  35. data/plugin/calibre.rb +3 -3
  36. data/plugin/livemagick.rb +17 -17
  37. data/plugin/markdown.rb +10 -10
  38. data/plugin/pyggish.rb +131 -162
  39. data/plugin/tutorial.rb +15 -16
  40. data/test/all.rb +6 -0
  41. data/test/snapshots/def_method/expected-output.txt +2 -0
  42. data/test/snapshots/def_method/source.lt3 +4 -2
  43. data/test/snapshots/error_inc_line_num/OUT +17 -0
  44. data/test/snapshots/error_inc_line_num/README.txt +20 -0
  45. data/test/snapshots/error_inc_line_num/expected-output.txt +0 -6
  46. data/test/snapshots/error_inc_line_num/match-error.txt +1 -1
  47. data/test/snapshots/error_line_num/match-error.txt +1 -1
  48. data/test/snapshots/error_missing_end/expected-output.txt +0 -1
  49. data/test/snapshots/error_name_not_permitted/expected-output.txt +4 -0
  50. data/test/snapshots/error_name_not_permitted/match-error.txt +1 -1
  51. data/test/snapshots/error_no_such_copy/duh +26 -0
  52. data/test/snapshots/error_no_such_copy/expected-output.txt +1 -0
  53. data/test/snapshots/error_no_such_copy/match-error.txt +1 -1
  54. data/test/snapshots/error_no_such_copy/mystery.txt +36 -0
  55. data/test/snapshots/error_no_such_inc/match-error.txt +1 -1
  56. data/test/snapshots/error_no_such_mixin/expected-output.txt +1 -0
  57. data/test/snapshots/error_no_such_mixin/match-error.txt +1 -1
  58. data/test/snapshots/error_no_such_mixin/source.lt3 +1 -1
  59. data/test/snapshots/example_alpha/source.lt3 +2 -2
  60. data/test/snapshots/example_alpha2/expected-output.txt +0 -2
  61. data/test/snapshots/example_alpha2/source.lt3 +5 -4
  62. data/test/snapshots/{icanhaz → import}/expected-output.txt +2 -1
  63. data/test/snapshots/import/match-error.txt +1 -0
  64. data/test/snapshots/{icanhaz → import}/simple_import.rb +1 -1
  65. data/test/snapshots/{icanhaz → import}/source.lt3 +2 -2
  66. data/test/snapshots/{icanhaz2 → import2}/expected-error.txt +0 -0
  67. data/test/snapshots/{icanhaz2 → import2}/expected-output.txt +3 -1
  68. data/test/snapshots/{icanhaz2/simple_canhaz.rb → import2/simple_import.rb} +1 -1
  69. data/test/snapshots/import2/source.lt3 +8 -0
  70. data/test/snapshots/import_bookish/expected-error.txt +0 -0
  71. data/test/snapshots/import_bookish/expected-output.txt +10 -0
  72. data/test/snapshots/import_bookish/source.lt3 +7 -0
  73. data/test/snapshots/import_bookish/toc.tmp +0 -0
  74. data/test/snapshots/mixin_bookish/expected-error.txt +0 -0
  75. data/test/snapshots/mixin_bookish/expected-output.txt +10 -0
  76. data/test/snapshots/mixin_bookish/source.lt3 +7 -0
  77. data/test/snapshots/mixin_bookish/toc.tmp +0 -0
  78. data/test/snapshots/more_functions/expected-error.txt +0 -0
  79. data/test/snapshots/more_functions/expected-output.txt +37 -0
  80. data/test/snapshots/more_functions/source.lt3 +40 -0
  81. data/test/snapshots/raw_lines/expected-output.txt +0 -2
  82. data/test/snapshots/simple_import/expected-output.txt +2 -0
  83. data/test/snapshots/simple_import/simple_import.rb +1 -1
  84. data/test/snapshots/simple_import/source.lt3 +3 -1
  85. data/test/snapshots/simple_mixin/simple_mixin.rb +1 -1
  86. data/test/snapshots/single_raw_line/expected-output.txt +0 -2
  87. data/test/snapshots/subset.txt +14 -14
  88. data/test/snapshots.rb +30 -13
  89. data/test/unit/formatline.rb +253 -134
  90. data/test/unit/html.rb +2 -3
  91. data/test/unit/parser/general.rb +1 -2
  92. data/test/unit/parser/mixin.rb +1 -3
  93. data/test/unit/parser/set.rb +8 -12
  94. data/test/unit/parser/string.rb +6 -6
  95. data/test/unit/parser.rb +0 -1
  96. data/test/unit/standard.rb +0 -2
  97. metadata +47 -30
  98. data/imports/markdown_importable.rb +0 -45
  99. data/lib/handler/icanhaz.rb +0 -35
  100. data/lib/handler.rb +0 -1
  101. data/lib/livetext/importable.rb +0 -2
  102. data/lib/parser/file.rb +0 -8
  103. data/lib/parser/import.rb +0 -15
  104. data/lib/parser/mixin.rb +0 -38
  105. data/lib/processor.rb +0 -83
  106. data/lib/userapi.rb +0 -160
  107. data/test/snapshots/icanhaz/match-error.txt +0 -1
  108. data/test/snapshots/icanhaz2/source.lt3 +0 -6
  109. data/test/unit/parser/importable.rb +0 -19
@@ -1,9 +1,7 @@
1
1
 
2
2
  require 'minitest/autorun'
3
3
 
4
- require_relative '../../../lib/parser/set'
5
-
6
- # ParseSet = Livetext::ParseSet
4
+ require_relative '../parser' # nested
7
5
 
8
6
  class TestParseSet < MiniTest::Test
9
7
 
@@ -1,9 +1,9 @@
1
1
 
2
2
  require 'minitest/autorun'
3
3
 
4
- require_relative '../../../lib/parser/set'
4
+ require_relative '../parser' # nested
5
5
 
6
- ParseSet = Livetext::ParseSet
6
+ ParseSet = ::Livetext::ParseSet
7
7
 
8
8
  class TestParseSet < MiniTest::Test
9
9
 
@@ -137,30 +137,26 @@ class TestParseSet < MiniTest::Test
137
137
  # - allow/disallow escaping??
138
138
  end
139
139
 
140
- # BUG: FormatLine doesn't know variables in this context!
141
-
142
140
  def test_var_eq_var
143
141
  set = ParseSet.new("file = $File").parse
144
142
  set = set.first # [["var", "value"]]
145
143
  assert_equal set.first, "file"
146
- refute set.last =~ /undefined/, "Found 'undefined' for variable value"
144
+ assert set.last =~ /undefined/, "Found 'undefined' for variable value"
145
+ # ^ ParseSet isn't smart enough to know about variables/functions
147
146
  end
148
147
 
149
- # BUG: ...or functions.
150
- # (Additional bug: Failing silently seems wrong.)
151
-
152
148
  def test_var_eq_func
153
149
  set = ParseSet.new("date = $$date").parse
154
150
  set = set.first # [["var", "value"]]
155
151
  assert_equal set.first, "date"
156
- refute set.last =~ /undefined/, "Found 'undefined' for variable value"
157
- assert set.last =~ /^\d\d.\d\d.\d\d/, "Did not find 6-digit date with two separators"
152
+ assert set.last =~ /undefined/, "Found 'undefined' for variable value"
153
+ # ^ ParseSet isn't smart enough to know about variables/functions
158
154
  end
159
155
 
160
156
  def test_two_strings
161
- line = %[bday="May_31", date="5/31"]
157
+ line = %[bday="May 31", date='5/31']
162
158
  set = ParseSet.new(line).parse
163
- assert set == [["bday", "May_31"], ["date", "5/31"]]
159
+ assert set == [["bday", "May 31"], ["date", "5/31"]]
164
160
  end
165
161
 
166
162
  end
@@ -1,6 +1,6 @@
1
1
  require 'minitest/autorun'
2
2
 
3
- require_relative '../../../lib/parser/string'
3
+ require_relative '../parser' # nested
4
4
 
5
5
  class TestStringParser < MiniTest::Test
6
6
 
@@ -58,7 +58,7 @@ class TestStringParser < MiniTest::Test
58
58
  assert @zero.eos?
59
59
 
60
60
  @one.grab
61
- assert @one.eos? # FIXME??
61
+ assert @one.eos?
62
62
  @one.grab
63
63
  assert @one.eos?
64
64
 
@@ -90,7 +90,7 @@ class TestStringParser < MiniTest::Test
90
90
  assert char2 == char1
91
91
  assert char3 == @str1[1]
92
92
  assert @one.i == 1
93
- assert @one.eos? # FIXME??
93
+ assert @one.eos?
94
94
 
95
95
  char1 = @many.peek
96
96
  char2 = @many.grab
@@ -143,14 +143,14 @@ class TestStringParser < MiniTest::Test
143
143
  assert_equal parse.peek, "c"
144
144
  end
145
145
 
146
- def test_next_bang
146
+ def test_lookahead
147
147
  parse = StringParser.new("abcdef")
148
148
  assert_equal parse.peek, "a"
149
- assert_equal parse.next!, "b"
149
+ assert_equal parse.lookahead, "b"
150
150
  assert_equal parse.i, 0
151
151
  3.times { parse.grab }
152
152
  before = parse.i
153
- assert_equal parse.next!, "e"
153
+ assert_equal parse.lookahead, "e"
154
154
  after = parse.i
155
155
  assert_equal before, after
156
156
  end
data/test/unit/parser.rb CHANGED
@@ -3,4 +3,3 @@ require_relative 'parser/string'
3
3
  require_relative 'parser/set'
4
4
  require_relative 'parser/general'
5
5
  require_relative 'parser/mixin' # currently empty
6
- require_relative 'parser/importable' # currently empty
@@ -1,11 +1,9 @@
1
1
  require 'minitest/autorun'
2
2
 
3
-
4
3
  require_relative '../../lib/livetext'
5
4
 
6
5
  class TestingLivetext < MiniTest::Test
7
6
  include Livetext::Standard
8
- include Livetext::UserAPI
9
7
 
10
8
  # Only method here "really" belongs elsewhere? FIXME
11
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: livetext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.21
4
+ version: 0.9.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-12 00:00:00.000000000 Z
11
+ date: 2022-01-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com
@@ -24,29 +24,32 @@ files:
24
24
  - imports/calibre.rb
25
25
  - imports/livemagick.rb
26
26
  - imports/markdown.rb
27
- - imports/markdown_importable.rb
28
27
  - imports/pyggish.rb
29
28
  - imports/tutorial.rb
30
29
  - lib/cmdargs.rb
31
- - lib/errors.rb
32
- - lib/formatline.rb
33
- - lib/functions.rb
34
- - lib/handler.rb
35
- - lib/handler/icanhaz.rb
36
- - lib/helpers.rb
37
- - lib/html.rb
38
30
  - lib/livetext.rb
39
- - lib/livetext/importable.rb
40
- - lib/parser.rb
41
- - lib/parser/file.rb
42
- - lib/parser/general.rb
43
- - lib/parser/import.rb
44
- - lib/parser/mixin.rb
45
- - lib/parser/set.rb
46
- - lib/parser/string.rb
47
- - lib/processor.rb
48
- - lib/standard.rb
49
- - lib/userapi.rb
31
+ - lib/livetext/errors.rb
32
+ - lib/livetext/formatline.rb
33
+ - lib/livetext/funcall.rb
34
+ - lib/livetext/functions.rb
35
+ - lib/livetext/global_helpers.rb
36
+ - lib/livetext/handler.rb
37
+ - lib/livetext/handler/import.rb
38
+ - lib/livetext/handler/mixin.rb
39
+ - lib/livetext/helpers.rb
40
+ - lib/livetext/html.rb
41
+ - lib/livetext/parser.rb
42
+ - lib/livetext/parser/general.rb
43
+ - lib/livetext/parser/set.rb
44
+ - lib/livetext/parser/string.rb
45
+ - lib/livetext/parsing.rb
46
+ - lib/livetext/paths.rb
47
+ - lib/livetext/processor.rb
48
+ - lib/livetext/reopen.rb
49
+ - lib/livetext/skeleton.rb
50
+ - lib/livetext/standard.rb
51
+ - lib/livetext/userapi.rb
52
+ - lib/livetext/version.rb
50
53
  - livetext.gemspec
51
54
  - plugin/bookish.rb
52
55
  - plugin/calibre.rb
@@ -72,6 +75,8 @@ files:
72
75
  - test/snapshots/def_method/expected-error.txt
73
76
  - test/snapshots/def_method/expected-output.txt
74
77
  - test/snapshots/def_method/source.lt3
78
+ - test/snapshots/error_inc_line_num/OUT
79
+ - test/snapshots/error_inc_line_num/README.txt
75
80
  - test/snapshots/error_inc_line_num/expected-output.txt
76
81
  - test/snapshots/error_inc_line_num/file2.lt3
77
82
  - test/snapshots/error_inc_line_num/match-error.txt
@@ -91,8 +96,10 @@ files:
91
96
  - test/snapshots/error_name_not_permitted/expected-output.txt
92
97
  - test/snapshots/error_name_not_permitted/match-error.txt
93
98
  - test/snapshots/error_name_not_permitted/source.lt3
99
+ - test/snapshots/error_no_such_copy/duh
94
100
  - test/snapshots/error_no_such_copy/expected-output.txt
95
101
  - test/snapshots/error_no_such_copy/match-error.txt
102
+ - test/snapshots/error_no_such_copy/mystery.txt
96
103
  - test/snapshots/error_no_such_copy/source.lt3
97
104
  - test/snapshots/error_no_such_inc/expected-output.txt
98
105
  - test/snapshots/error_no_such_inc/match-error.txt
@@ -112,17 +119,28 @@ files:
112
119
  - test/snapshots/hello_world/expected-error.txt
113
120
  - test/snapshots/hello_world/expected-output.txt
114
121
  - test/snapshots/hello_world/source.lt3
115
- - test/snapshots/icanhaz/expected-output.txt
116
- - test/snapshots/icanhaz/match-error.txt
117
- - test/snapshots/icanhaz/simple_import.rb
118
- - test/snapshots/icanhaz/source.lt3
119
- - test/snapshots/icanhaz2/expected-error.txt
120
- - test/snapshots/icanhaz2/expected-output.txt
121
- - test/snapshots/icanhaz2/simple_canhaz.rb
122
- - test/snapshots/icanhaz2/source.lt3
122
+ - test/snapshots/import/expected-output.txt
123
+ - test/snapshots/import/match-error.txt
124
+ - test/snapshots/import/simple_import.rb
125
+ - test/snapshots/import/source.lt3
126
+ - test/snapshots/import2/expected-error.txt
127
+ - test/snapshots/import2/expected-output.txt
128
+ - test/snapshots/import2/simple_import.rb
129
+ - test/snapshots/import2/source.lt3
130
+ - test/snapshots/import_bookish/expected-error.txt
131
+ - test/snapshots/import_bookish/expected-output.txt
132
+ - test/snapshots/import_bookish/source.lt3
133
+ - test/snapshots/import_bookish/toc.tmp
134
+ - test/snapshots/mixin_bookish/expected-error.txt
135
+ - test/snapshots/mixin_bookish/expected-output.txt
136
+ - test/snapshots/mixin_bookish/source.lt3
137
+ - test/snapshots/mixin_bookish/toc.tmp
123
138
  - test/snapshots/more_complex_vars/expected-error.txt
124
139
  - test/snapshots/more_complex_vars/expected-output.txt
125
140
  - test/snapshots/more_complex_vars/source.lt3
141
+ - test/snapshots/more_functions/expected-error.txt
142
+ - test/snapshots/more_functions/expected-output.txt
143
+ - test/snapshots/more_functions/source.lt3
126
144
  - test/snapshots/predef_vars/expected-error.txt
127
145
  - test/snapshots/predef_vars/match-output.txt
128
146
  - test/snapshots/predef_vars/source.lt3
@@ -166,7 +184,6 @@ files:
166
184
  - test/unit/parser.rb
167
185
  - test/unit/parser/all.rb
168
186
  - test/unit/parser/general.rb
169
- - test/unit/parser/importable.rb
170
187
  - test/unit/parser/mixin.rb
171
188
  - test/unit/parser/set.rb
172
189
  - test/unit/parser/string.rb
@@ -1,45 +0,0 @@
1
- # This file is intended to be used via a Livetext .mixin
2
- # or the equivalent.
3
-
4
- require_relative '../lib/livetext/importable'
5
-
6
- class MarkdownImportable < LiveText::Importable
7
-
8
- SimpleFormats[:b] = %w[* *]
9
- SimpleFormats[:i] = %w[_ _]
10
- SimpleFormats[:t] = %w[` `]
11
- SimpleFormats[:s] = %w[<strike> </strike>]
12
-
13
- def h1; _out "# #{Livetext.interpolate(@_data)}"; _optional_blank_line end # atx style for now
14
- def h2; _out "## #{Livetext.interpolate(@_data)}"; _optional_blank_line end
15
- def h3; _out "### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
16
- def h4; _out "#### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
17
- def h5; _out "##### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
18
- def h6; _out "###### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
19
-
20
- def title
21
- h1
22
- end
23
-
24
- def section
25
- h3
26
- end
27
-
28
- def bq # block quote
29
- _body {|line| _out "> #{line}" }
30
- end
31
-
32
- def list
33
- _body {|line| _out " * #{line}" }
34
- end
35
-
36
- def olist # Doesn't handle paragraphs yet
37
- n = 0
38
- _body do |line|
39
- n += 1
40
- _out "#{n}. #{_format(line)}"
41
- end
42
- end
43
-
44
- alias nlist olist
45
- end
@@ -1,35 +0,0 @@
1
-
2
- class Livetext::Handler::ICanHaz
3
- include Helpers
4
-
5
- attr_reader :file
6
-
7
- def initialize(name)
8
- @name = name
9
- @file = find_file(name)
10
- end
11
-
12
- def self.get_module(name)
13
- handler = self.new(name)
14
- const1 = Object.constants
15
- @file = handler.file.sub(/.rb$/, "")
16
- require @file # + ".rb"
17
- const2 = Object.constants
18
- names = (const2 - const1)
19
- abort "Expected ONE new constant: #{names.inspect}" if names.size != 1
20
- modname = names.first.to_s
21
- newmod = Object.const_get("::" + modname)
22
- newmod # return actual module
23
- end
24
-
25
- private
26
-
27
- def cwd_root?
28
- File.dirname(File.expand_path(".")) == "/"
29
- end
30
-
31
- def fname2module(name)
32
- end
33
-
34
- end
35
-
data/lib/handler.rb DELETED
@@ -1 +0,0 @@
1
- require_relative 'handler/icanhaz'
@@ -1,2 +0,0 @@
1
- class LiveText::Importable
2
- end
data/lib/parser/file.rb DELETED
@@ -1,8 +0,0 @@
1
-
2
- require_relative '../livetext'
3
-
4
- # Hmm. not today?
5
-
6
- class Livetext::ParseFile
7
-
8
- end
data/lib/parser/import.rb DELETED
@@ -1,15 +0,0 @@
1
-
2
- require '../livetext/importable'
3
-
4
- make_exception(:BadVariableName, "Error: invalid variable name")
5
- make_exception(:NoEqualSign, "Error: no equal sign found")
6
-
7
- class Livetext::Handler::Import
8
- def use_import(name)
9
- require name
10
- include name
11
- init = "init_#{name}"
12
- self.send(init) if self.respond_to? init
13
- end
14
- end
15
-
data/lib/parser/mixin.rb DELETED
@@ -1,38 +0,0 @@
1
- require_relative '../livetext'
2
- require_relative '../helpers'
3
- require_relative 'string'
4
-
5
- make_exception(:NoEqualSign, "Error: no equal sign found")
6
-
7
- class Livetext::ParseMixin
8
- include Helpers
9
-
10
- def initialize(name)
11
- @name = name
12
- @file = find_file(name)
13
- end
14
-
15
- def self.get_module(name)
16
- parse = self.new(name)
17
- modname, code = parse.read_mixin
18
- eval(code) # Avoid in the future
19
- newmod = Object.const_get("::" + modname)
20
- # return actual module
21
- newmod
22
- end
23
-
24
- def read_mixin
25
- modname = @name.gsub("/","_").capitalize
26
- meths = grab_file(@file)
27
- [modname, "module ::#{modname}; #{meths}\nend"]
28
- end
29
-
30
- private
31
-
32
- def cwd_root?
33
- File.dirname(File.expand_path(".")) == "/"
34
- end
35
-
36
-
37
- end
38
-
data/lib/processor.rb DELETED
@@ -1,83 +0,0 @@
1
- # Class Livetext is the actual top-level class.
2
-
3
- class Livetext
4
-
5
- def self.interpolate(str)
6
- FormatLine.var_func_parse(str)
7
- end
8
-
9
- # Class Processor does the actual work of processing input.
10
-
11
- class Processor
12
-
13
- GenericError = Class.new(StandardError)
14
-
15
- include Livetext::Standard
16
- include Livetext::UserAPI
17
-
18
- Disallowed =
19
- %i[ __binding__ __id__ __send__ class
20
- clone display dup enum_for
21
- eql? equal? extend freeze
22
- frozen? hash inspect instance_eval
23
- instance_exec instance_of? is_a? kind_of?
24
- method methods nil? object_id
25
- pretty_inspect private_methods protected_methods public_method
26
- public_methods public_send respond_to? send
27
- singleton_class singleton_method singleton_methods taint
28
- tainted? tap to_enum to_s
29
- trust untaint untrust untrusted?
30
- define_singleton_method instance_variable_defined?
31
- instance_variable_get instance_variable_set
32
- remove_instance_variable instance_variables ]
33
-
34
- def initialize(parent, output = nil)
35
- @parent = parent
36
- @_nopass = false
37
- @_nopara = false
38
- # Meh?
39
- @output = ::Livetext.output = (output || File.open("/dev/null", "w"))
40
- @sources = []
41
- @indentation = @parent.indentation
42
- @_mixins = []
43
- end
44
-
45
- def output=(io)
46
- @output = io
47
- end
48
-
49
- def _error!(err, raise_error=false, trace=false) # FIXME much bullshit happens here
50
- where = @sources.last || @save_location
51
- STDERR.puts "Error: #{err} (at #{where[1]} line #{where[2]})"
52
- STDERR.puts err.backtrace if err.respond_to?(:backtrace) # && trace
53
- raise GenericError.new("Error: #{err}") if raise_error
54
- end
55
-
56
- def disallowed?(name)
57
- Disallowed.include?(name.to_sym)
58
- end
59
-
60
- def source(enum, file, line)
61
- @sources.push([enum, file, line])
62
- end
63
-
64
- def peek_nextline
65
- line = @sources.last[0].peek
66
- rescue StopIteration
67
- @sources.pop
68
- nil
69
- rescue => err
70
- nil
71
- end
72
-
73
- def nextline
74
- return nil if @sources.empty?
75
- line = @sources.last[0].next
76
- @sources.last[2] += 1
77
- line
78
- rescue StopIteration
79
- @sources.pop
80
- nil
81
- end
82
- end
83
- end
data/lib/userapi.rb DELETED
@@ -1,160 +0,0 @@
1
- # User API
2
-
3
- require_relative 'formatline'
4
-
5
- # UserAPI deals mostly with user-level methods.
6
-
7
- module Livetext::UserAPI
8
-
9
- def setvar(var, val)
10
- str, sym = var.to_s, var.to_sym
11
- Livetext::Vars[str] = val
12
- Livetext::Vars[sym] = val
13
- end
14
-
15
- def _check_existence(file, msg)
16
- _error! msg unless File.exist?(file)
17
- end
18
-
19
- def _source
20
- @input
21
- end
22
-
23
- def _args
24
- @_args = _format(@_data).chomp.split
25
- if block_given?
26
- @_args.each {|arg| yield arg }
27
- else
28
- @_args
29
- end
30
- end
31
-
32
- def _vars
33
- @_vars.dup
34
- end
35
-
36
- def _optional_blank_line
37
- peek = peek_nextline
38
- return if peek.nil?
39
- @line = nextline if peek =~ /^ *$/
40
- end
41
-
42
- def _comment?(str)
43
- sigil = Livetext::Sigil
44
- c1 = sigil + Livetext::Space
45
- c2 = sigil + sigil + Livetext::Space
46
- str.index(c1) == 0 || str.index(c2) == 0
47
- end
48
-
49
- def _trailing?(char)
50
- return true if ["\n", " ", nil].include?(char)
51
- return false
52
- end
53
-
54
- def _end?(str)
55
- return true if str == ".end" || str =~ / *\$\.end/
56
- return false
57
- end
58
-
59
- def _raw_body(tag = "__EOF__")
60
- lines = []
61
- # @save_location = @sources.last
62
- loop do
63
- @line = nextline
64
- break if @line.nil?
65
- break if @line.chomp.strip == tag
66
- lines << @line
67
- end
68
- _optional_blank_line
69
- if block_given?
70
- lines.each {|line| yield line }
71
- else
72
- lines
73
- end
74
- lines
75
- end
76
-
77
- def _body(raw=false)
78
- lines = []
79
- end_found = false
80
- loop do
81
- @line = nextline
82
- break if @line.nil?
83
- @line.chomp!
84
- break if _end?(@line)
85
- next if _comment?(@line)
86
- @line = _format(@line) unless raw
87
- lines << @line
88
- end
89
-
90
- raise "Expected .end, found end of file" unless _end?(@line)
91
-
92
- _optional_blank_line
93
- if block_given?
94
- lines.each {|line| yield line } # FIXME what about $. ?
95
- else
96
- lines
97
- end
98
- end
99
-
100
- def _body_text(raw=false)
101
- _raw_body.join("\n")
102
- end
103
-
104
- def _raw_body!
105
- _raw_body(Livetext::Sigil).join("\n")
106
- end
107
-
108
- def _handle_escapes(str, set)
109
- str = str.dup
110
- set.each_char do |ch|
111
- str.gsub!("\\#{ch}", ch)
112
- end
113
- str
114
- end
115
-
116
- def _format(line)
117
- return "" if line == "\n" || line.nil?
118
- line2 = FormatLine.parse!(line)
119
- line.replace(line2)
120
- line
121
- end
122
-
123
- def _passthru(line)
124
- return if @_nopass
125
- _out "<p>" if line == "\n" and ! @_nopara
126
- line = _format(line)
127
- _out line
128
- end
129
-
130
- def _out(str = "", file = nil)
131
- return if str.nil?
132
- if file.nil? # FIXME do this elsewhere?
133
- @parent.body << str
134
- @parent.body << "\n" unless str.end_with?("\n")
135
- else
136
- file.puts str
137
- end
138
- end
139
-
140
- def _out!(str = "")
141
- @parent.body << str # no newline
142
- end
143
-
144
- def _puts(*args)
145
- @output.puts *args
146
- end
147
-
148
- def _print(*args)
149
- @output.print *args
150
- end
151
-
152
- def _debug=(val)
153
- @_debug = val
154
- end
155
-
156
- def _debug(*args)
157
- TTY.puts *args if @_debug
158
- end
159
-
160
- end
@@ -1 +0,0 @@
1
- 1 /No such mixin 'nonexistent'/
@@ -1,6 +0,0 @@
1
- Testing fake command .icanhaz:
2
-
3
- .icanhaz simple_canhaz
4
- Now call a method:
5
- .hello_world
6
- That's all.
@@ -1,19 +0,0 @@
1
-
2
- require 'minitest/autorun'
3
-
4
- require_relative '../../../lib/parser/set'
5
-
6
- # ParseSet = Livetext::ParseSet
7
-
8
- class TestParseSet < MiniTest::Test
9
-
10
- def setup
11
- end
12
-
13
- def teardown
14
- end
15
-
16
- # FIXME no tests yet
17
- # Bad syntax? File not found? not found searching upward?
18
-
19
- end