livetext 0.9.21 → 0.9.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.lt3 +8 -8
- data/bin/livetext +57 -40
- data/imports/bookish.rb +89 -90
- data/imports/calibre.rb +3 -3
- data/imports/livemagick.rb +17 -17
- data/imports/markdown.rb +10 -10
- data/imports/pyggish.rb +15 -47
- data/imports/tutorial.rb +18 -18
- data/lib/cmdargs.rb +10 -6
- data/lib/{errors.rb → livetext/errors.rb} +1 -1
- data/lib/{formatline.rb → livetext/formatline.rb} +69 -125
- data/lib/livetext/funcall.rb +84 -0
- data/lib/{functions.rb → livetext/functions.rb} +16 -3
- data/lib/livetext/global_helpers.rb +37 -0
- data/lib/livetext/handler/import.rb +44 -0
- data/lib/livetext/handler/mixin.rb +37 -0
- data/lib/livetext/handler.rb +3 -0
- data/lib/{helpers.rb → livetext/helpers.rb} +89 -67
- data/lib/{html.rb → livetext/html.rb} +3 -2
- data/lib/{parser → livetext/parser}/general.rb +0 -3
- data/lib/{parser → livetext/parser}/set.rb +1 -6
- data/lib/{parser → livetext/parser}/string.rb +2 -2
- data/lib/{parser.rb → livetext/parser.rb} +0 -1
- data/lib/livetext/parsing.rb +29 -0
- data/lib/livetext/paths.rb +13 -0
- data/lib/livetext/processor.rb +89 -0
- data/lib/livetext/reopen.rb +12 -0
- data/lib/livetext/skeleton.rb +17 -0
- data/lib/{standard.rb → livetext/standard.rb} +152 -122
- data/lib/livetext/userapi.rb +153 -0
- data/lib/livetext/version.rb +6 -0
- data/lib/livetext.rb +66 -27
- data/plugin/bookish.rb +85 -85
- data/plugin/calibre.rb +3 -3
- data/plugin/livemagick.rb +17 -17
- data/plugin/markdown.rb +10 -10
- data/plugin/pyggish.rb +131 -162
- data/plugin/tutorial.rb +15 -16
- data/test/all.rb +6 -0
- data/test/snapshots/def_method/expected-output.txt +2 -0
- data/test/snapshots/def_method/source.lt3 +4 -2
- data/test/snapshots/error_inc_line_num/OUT +17 -0
- data/test/snapshots/error_inc_line_num/README.txt +20 -0
- data/test/snapshots/error_inc_line_num/expected-output.txt +0 -6
- data/test/snapshots/error_inc_line_num/match-error.txt +1 -1
- data/test/snapshots/error_line_num/match-error.txt +1 -1
- data/test/snapshots/error_missing_end/expected-output.txt +0 -1
- data/test/snapshots/error_name_not_permitted/expected-output.txt +4 -0
- data/test/snapshots/error_name_not_permitted/match-error.txt +1 -1
- data/test/snapshots/error_no_such_copy/duh +26 -0
- data/test/snapshots/error_no_such_copy/expected-output.txt +1 -0
- data/test/snapshots/error_no_such_copy/match-error.txt +1 -1
- data/test/snapshots/error_no_such_copy/mystery.txt +36 -0
- data/test/snapshots/error_no_such_inc/match-error.txt +1 -1
- data/test/snapshots/error_no_such_mixin/expected-output.txt +1 -0
- data/test/snapshots/error_no_such_mixin/match-error.txt +1 -1
- data/test/snapshots/error_no_such_mixin/source.lt3 +1 -1
- data/test/snapshots/example_alpha/source.lt3 +2 -2
- data/test/snapshots/example_alpha2/expected-output.txt +0 -2
- data/test/snapshots/example_alpha2/source.lt3 +5 -4
- data/test/snapshots/{icanhaz → import}/expected-output.txt +2 -1
- data/test/snapshots/import/match-error.txt +1 -0
- data/test/snapshots/{icanhaz → import}/simple_import.rb +1 -1
- data/test/snapshots/{icanhaz → import}/source.lt3 +2 -2
- data/test/snapshots/{icanhaz2 → import2}/expected-error.txt +0 -0
- data/test/snapshots/{icanhaz2 → import2}/expected-output.txt +3 -1
- data/test/snapshots/{icanhaz2/simple_canhaz.rb → import2/simple_import.rb} +1 -1
- data/test/snapshots/import2/source.lt3 +8 -0
- data/test/snapshots/import_bookish/expected-error.txt +0 -0
- data/test/snapshots/import_bookish/expected-output.txt +10 -0
- data/test/snapshots/import_bookish/source.lt3 +7 -0
- data/test/snapshots/import_bookish/toc.tmp +0 -0
- data/test/snapshots/mixin_bookish/expected-error.txt +0 -0
- data/test/snapshots/mixin_bookish/expected-output.txt +10 -0
- data/test/snapshots/mixin_bookish/source.lt3 +7 -0
- data/test/snapshots/mixin_bookish/toc.tmp +0 -0
- data/test/snapshots/more_functions/expected-error.txt +0 -0
- data/test/snapshots/more_functions/expected-output.txt +37 -0
- data/test/snapshots/more_functions/source.lt3 +40 -0
- data/test/snapshots/raw_lines/expected-output.txt +0 -2
- data/test/snapshots/simple_import/expected-output.txt +2 -0
- data/test/snapshots/simple_import/simple_import.rb +1 -1
- data/test/snapshots/simple_import/source.lt3 +3 -1
- data/test/snapshots/simple_mixin/simple_mixin.rb +1 -1
- data/test/snapshots/single_raw_line/expected-output.txt +0 -2
- data/test/snapshots/subset.txt +14 -14
- data/test/snapshots.rb +30 -13
- data/test/unit/formatline.rb +253 -134
- data/test/unit/html.rb +2 -3
- data/test/unit/parser/general.rb +1 -2
- data/test/unit/parser/mixin.rb +1 -3
- data/test/unit/parser/set.rb +8 -12
- data/test/unit/parser/string.rb +6 -6
- data/test/unit/parser.rb +0 -1
- data/test/unit/standard.rb +0 -2
- metadata +47 -30
- data/imports/markdown_importable.rb +0 -45
- data/lib/handler/icanhaz.rb +0 -35
- data/lib/handler.rb +0 -1
- data/lib/livetext/importable.rb +0 -2
- data/lib/parser/file.rb +0 -8
- data/lib/parser/import.rb +0 -15
- data/lib/parser/mixin.rb +0 -38
- data/lib/processor.rb +0 -83
- data/lib/userapi.rb +0 -160
- data/test/snapshots/icanhaz/match-error.txt +0 -1
- data/test/snapshots/icanhaz2/source.lt3 +0 -6
- data/test/unit/parser/importable.rb +0 -19
data/test/unit/parser/mixin.rb
CHANGED
data/test/unit/parser/set.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
|
2
2
|
require 'minitest/autorun'
|
3
3
|
|
4
|
-
require_relative '
|
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
|
-
|
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
|
-
|
157
|
-
|
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="
|
157
|
+
line = %[bday="May 31", date='5/31']
|
162
158
|
set = ParseSet.new(line).parse
|
163
|
-
assert set == [["bday", "
|
159
|
+
assert set == [["bday", "May 31"], ["date", "5/31"]]
|
164
160
|
end
|
165
161
|
|
166
162
|
end
|
data/test/unit/parser/string.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
|
3
|
-
require_relative '
|
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?
|
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?
|
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
|
146
|
+
def test_lookahead
|
147
147
|
parse = StringParser.new("abcdef")
|
148
148
|
assert_equal parse.peek, "a"
|
149
|
-
assert_equal parse.
|
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.
|
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
data/test/unit/standard.rb
CHANGED
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.
|
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-
|
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/
|
40
|
-
- lib/
|
41
|
-
- lib/
|
42
|
-
- lib/
|
43
|
-
- lib/
|
44
|
-
- lib/
|
45
|
-
- lib/
|
46
|
-
- lib/
|
47
|
-
- lib/
|
48
|
-
- lib/
|
49
|
-
- lib/
|
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/
|
116
|
-
- test/snapshots/
|
117
|
-
- test/snapshots/
|
118
|
-
- test/snapshots/
|
119
|
-
- test/snapshots/
|
120
|
-
- test/snapshots/
|
121
|
-
- test/snapshots/
|
122
|
-
- test/snapshots/
|
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
|
data/lib/handler/icanhaz.rb
DELETED
@@ -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'
|
data/lib/livetext/importable.rb
DELETED
data/lib/parser/file.rb
DELETED
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,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
|