livetext 0.9.23 → 0.9.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.lt3 +6 -6
- data/bin/livetext +57 -40
- data/imports/bookish.rb +81 -81
- data/imports/calibre.rb +3 -3
- data/imports/livemagick.rb +17 -17
- data/imports/markdown.rb +10 -10
- data/imports/pyggish.rb +13 -13
- data/imports/tutorial.rb +15 -15
- data/lib/cmdargs.rb +7 -4
- data/lib/{errors.rb → livetext/errors.rb} +4 -3
- data/lib/{formatline.rb → livetext/formatline.rb} +119 -18
- data/lib/livetext/funcall.rb +168 -0
- data/lib/{functions.rb → livetext/functions.rb} +0 -2
- data/lib/{global_helpers.rb → livetext/global_helpers.rb} +6 -3
- data/lib/{handler → livetext/handler}/import.rb +5 -9
- data/lib/livetext/handler/mixin.rb +33 -0
- data/lib/{handler.rb → livetext/handler.rb} +1 -1
- data/lib/{helpers.rb → livetext/helpers.rb} +78 -66
- data/lib/{html.rb → livetext/html.rb} +2 -3
- data/lib/livetext/lineparser.rb +441 -0
- data/lib/livetext/more.rb +158 -0
- data/lib/{parser → livetext/parser}/general.rb +0 -0
- data/lib/{parser → livetext/parser}/set.rb +0 -0
- data/lib/{parser → livetext/parser}/string.rb +0 -0
- data/lib/{parser.rb → livetext/parser.rb} +0 -3
- data/lib/{parsing.rb → livetext/parsing.rb} +0 -2
- data/lib/livetext/paths.rb +13 -0
- data/lib/{processor.rb → livetext/processor.rb} +18 -8
- data/lib/livetext/reopen.rb +12 -0
- data/lib/livetext/skeleton.rb +22 -0
- data/lib/{standard.rb → livetext/standard.rb} +150 -127
- data/lib/livetext/userapi.rb +170 -0
- data/lib/livetext/version.rb +6 -0
- data/lib/livetext.rb +14 -152
- data/plugin/bookish.rb +82 -81
- data/plugin/calibre.rb +3 -3
- data/plugin/livemagick.rb +17 -17
- data/plugin/markdown.rb +10 -10
- data/plugin/pyggish.rb +118 -118
- data/plugin/tutorial.rb +15 -15
- data/test/all.rb +6 -0
- data/test/snapshots/{error_inc_line_num → basic_formatting}/actual-error.txt +0 -0
- data/test/snapshots/basic_formatting/actual-output.txt +13 -0
- data/test/snapshots/basic_formatting/err-sdiff.txt +1 -0
- data/test/snapshots/basic_formatting/out-sdiff.txt +14 -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 → README.txt} +11 -8
- 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_invalid_name/foo +5 -0
- 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/expected-output.txt +1 -0
- 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/import/expected-output.txt +2 -1
- data/test/snapshots/import/match-error.txt +1 -1
- data/test/snapshots/import/simple_import.rb +1 -1
- data/test/snapshots/import2/simple_import.rb +1 -1
- data/test/snapshots/import_bookish/expected-output.txt +4 -4
- data/test/snapshots/{error_invalid_name/actual-output.txt → more_functions/actual-error.txt} +0 -0
- data/test/snapshots/more_functions/actual-output.txt +37 -0
- data/test/snapshots/more_functions/err-sdiff.txt +1 -0
- data/test/snapshots/more_functions/expected-output.txt +1 -1
- data/test/snapshots/more_functions/out-sdiff.txt +38 -0
- data/test/snapshots/more_functions/source.lt3 +1 -1
- data/test/snapshots/raw_lines/expected-output.txt +0 -2
- data/test/snapshots/simple_import/simple_import.rb +1 -1
- data/test/snapshots/simple_mixin/simple_mixin.rb +1 -1
- data/test/snapshots/{error_missing_end/actual-output.txt → simple_vars/actual-error.txt} +0 -0
- data/test/snapshots/simple_vars/actual-output.txt +6 -0
- data/test/snapshots/simple_vars/err-sdiff.txt +1 -0
- data/test/snapshots/simple_vars/out-sdiff.txt +7 -0
- data/test/snapshots/single_raw_line/expected-output.txt +0 -2
- data/test/snapshots/subset.txt +9 -7
- data/test/snapshots/{error_no_such_copy/actual-output.txt → var_into_func/actual-error.txt} +0 -0
- data/test/snapshots/var_into_func/actual-output.txt +16 -0
- data/test/snapshots/var_into_func/err-sdiff.txt +1 -0
- data/test/snapshots/{error_no_such_inc/actual-output.txt → var_into_func/expected-error.txt} +0 -0
- data/test/snapshots/var_into_func/expected-output.txt +16 -0
- data/test/snapshots/var_into_func/out-sdiff.txt +17 -0
- data/test/snapshots/var_into_func/source.lt3 +16 -0
- data/test/snapshots.rb +16 -7
- data/test/unit/all.rb +3 -1
- data/test/unit/formatline.rb +145 -276
- data/test/unit/html.rb +1 -2
- data/test/unit/lineparser.rb +650 -0
- data/test/unit/parser/set.rb +13 -12
- data/test/unit/standard.rb +0 -1
- data/test/unit/tokenizer.rb +534 -0
- metadata +49 -39
- data/lib/funcall.rb +0 -93
- data/lib/parser/file.rb +0 -6
- data/lib/parser/mixin.rb +0 -34
- data/lib/userapi.rb +0 -164
- data/test/snapshots/error_inc_line_num/actual-output.txt +0 -17
- data/test/snapshots/error_invalid_name/actual-error.txt +0 -10
- data/test/snapshots/error_invalid_name/out-sdiff.txt +0 -6
- data/test/snapshots/error_missing_end/actual-error.txt +0 -10
- data/test/snapshots/error_missing_end/out-sdiff.txt +0 -6
- data/test/snapshots/error_no_such_copy/actual-error.txt +0 -10
- data/test/snapshots/error_no_such_copy/out-sdiff.txt +0 -5
- data/test/snapshots/error_no_such_inc/actual-error.txt +0 -10
- data/test/snapshots/error_no_such_inc/out-sdiff.txt +0 -6
- data/test/snapshots/error_no_such_mixin/actual-error.txt +0 -13
- data/test/snapshots/error_no_such_mixin/actual-output.txt +0 -0
- data/test/snapshots/error_no_such_mixin/out-sdiff.txt +0 -6
@@ -0,0 +1,158 @@
|
|
1
|
+
|
2
|
+
# Class Livetext reopened (top level).
|
3
|
+
|
4
|
+
class Livetext
|
5
|
+
|
6
|
+
include Helpers
|
7
|
+
|
8
|
+
class Variables
|
9
|
+
def initialize(hash = {})
|
10
|
+
@vars = {}
|
11
|
+
hash.each_pair {|k, v| @vars[k.to_sym] = v }
|
12
|
+
end
|
13
|
+
|
14
|
+
def [](var)
|
15
|
+
@vars[var.to_sym]
|
16
|
+
end
|
17
|
+
|
18
|
+
def []=(var, value)
|
19
|
+
@vars[var.to_sym] = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Vars = Variables.new
|
24
|
+
|
25
|
+
TTY = ::File.open("/dev/tty", "w")
|
26
|
+
|
27
|
+
attr_reader :main, :sources
|
28
|
+
attr_accessor :nopass, :nopara
|
29
|
+
attr_accessor :body, :indentation
|
30
|
+
|
31
|
+
class << self
|
32
|
+
attr_accessor :output # bad solution?
|
33
|
+
end
|
34
|
+
|
35
|
+
def vars
|
36
|
+
@_vars
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.interpolate(str)
|
40
|
+
parse = Livetext::LineParser.new(str)
|
41
|
+
parse.var_func_parse
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.customize(mix: [], call: [], vars: {})
|
45
|
+
obj = self.new
|
46
|
+
mix = Array(mix)
|
47
|
+
call = Array(call)
|
48
|
+
mix.each {|lib| obj.mixin(lib) }
|
49
|
+
call.each {|cmd| obj.main.send(cmd[1..-1]) } # ignores leading dot, no param
|
50
|
+
vars.each_pair {|var, val| obj.setvar(var, val.to_s) }
|
51
|
+
obj
|
52
|
+
end
|
53
|
+
|
54
|
+
def peek_nextline
|
55
|
+
@main.peek_nextline # delegate
|
56
|
+
end
|
57
|
+
|
58
|
+
def nextline
|
59
|
+
@main.nextline # delegate
|
60
|
+
end
|
61
|
+
|
62
|
+
def sources
|
63
|
+
@main.sources # delegate
|
64
|
+
end
|
65
|
+
|
66
|
+
def save_location
|
67
|
+
@save_location # delegate
|
68
|
+
end
|
69
|
+
|
70
|
+
def save_location=(where)
|
71
|
+
@save_location = where # delegate
|
72
|
+
end
|
73
|
+
|
74
|
+
def dump(file = nil) # not a dot command!
|
75
|
+
file ||= ::STDOUT
|
76
|
+
file.puts @body
|
77
|
+
rescue => err
|
78
|
+
TTY.puts "#dump had an error: #{err.inspect}"
|
79
|
+
end
|
80
|
+
|
81
|
+
def graceful_error(err)
|
82
|
+
dump
|
83
|
+
raise err
|
84
|
+
end
|
85
|
+
|
86
|
+
def customize(mix: [], call: [], vars: {})
|
87
|
+
mix = Array(mix)
|
88
|
+
call = Array(call)
|
89
|
+
mix.each {|lib| mixin(lib) }
|
90
|
+
call.each {|cmd| @main.send(cmd[1..-1]) } # ignores leading dot, no param
|
91
|
+
vars.each_pair {|var, val| @api.setvar(var, val.to_s) }
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
def initialize(output = ::STDOUT)
|
96
|
+
@source = nil
|
97
|
+
@_mixins = []
|
98
|
+
@_imports = []
|
99
|
+
@_outdir = "."
|
100
|
+
@no_puts = output.nil?
|
101
|
+
@body = ""
|
102
|
+
@main = Processor.new(self, output)
|
103
|
+
@indentation = [0]
|
104
|
+
@_vars = Livetext::Vars
|
105
|
+
@api = UserAPI.new(self)
|
106
|
+
initial_vars
|
107
|
+
end
|
108
|
+
|
109
|
+
def api
|
110
|
+
@api
|
111
|
+
end
|
112
|
+
|
113
|
+
def initial_vars
|
114
|
+
# Other predefined variables (see also setfile)
|
115
|
+
@api.setvar(:User, `whoami`.chomp)
|
116
|
+
@api.setvar(:Version, Livetext::VERSION)
|
117
|
+
end
|
118
|
+
|
119
|
+
def transform(text)
|
120
|
+
setfile!("(string)")
|
121
|
+
enum = text.each_line
|
122
|
+
front = text.match(/.*?\n/).to_a.first.chomp rescue ""
|
123
|
+
@main.source(enum, "STDIN: '#{front}...'", 0)
|
124
|
+
loop do
|
125
|
+
line = @main.nextline
|
126
|
+
break if line.nil?
|
127
|
+
process_line(line)
|
128
|
+
end
|
129
|
+
result = @body
|
130
|
+
# @body = ""
|
131
|
+
result
|
132
|
+
end
|
133
|
+
|
134
|
+
# EXPERIMENTAL and incomplete
|
135
|
+
def xform(*args, file: nil, text: nil, vars: {})
|
136
|
+
case
|
137
|
+
when file && text.nil?
|
138
|
+
xform_file(file)
|
139
|
+
when file.nil? && text
|
140
|
+
transform(text)
|
141
|
+
when file.nil? && text.nil?
|
142
|
+
raise "Must specify file or text"
|
143
|
+
when file && text
|
144
|
+
raise "Cannot specify file and text"
|
145
|
+
end
|
146
|
+
self.process_file(file)
|
147
|
+
self.body
|
148
|
+
end
|
149
|
+
|
150
|
+
def xform_file(file, vars: nil)
|
151
|
+
Livetext::Vars.replace(vars) unless vars.nil?
|
152
|
+
@_vars.replace(vars) unless vars.nil?
|
153
|
+
self.process_file(file)
|
154
|
+
self.body
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Reopening for paths... do differently?
|
2
|
+
|
3
|
+
class Livetext
|
4
|
+
def self.get_path(dir = "")
|
5
|
+
path = File.join(File.dirname(__FILE__), dir)
|
6
|
+
File.expand_path(path)
|
7
|
+
end
|
8
|
+
|
9
|
+
Path = self.get_path
|
10
|
+
Plugins = self.get_path("../plugin")
|
11
|
+
Imports = self.get_path("../imports")
|
12
|
+
end
|
13
|
+
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# p __FILE__
|
2
|
-
|
3
1
|
|
4
2
|
# Class Processor does the actual work of processing input.
|
5
3
|
|
@@ -8,7 +6,6 @@ class Processor
|
|
8
6
|
GenericError = Class.new(StandardError)
|
9
7
|
|
10
8
|
include Livetext::Standard
|
11
|
-
include Livetext::UserAPI
|
12
9
|
|
13
10
|
Disallowed =
|
14
11
|
%i[ __binding__ __id__ __send__ class
|
@@ -26,15 +23,22 @@ class Processor
|
|
26
23
|
instance_variable_get instance_variable_set
|
27
24
|
remove_instance_variable instance_variables ]
|
28
25
|
|
26
|
+
attr_reader :parent, :sources
|
27
|
+
|
29
28
|
def initialize(parent, output = nil)
|
30
29
|
@parent = parent
|
31
|
-
@
|
32
|
-
@
|
30
|
+
@nopass = false
|
31
|
+
@nopara = false
|
33
32
|
# Meh?
|
34
33
|
@output = ::Livetext.output = (output || File.open("/dev/null", "w"))
|
35
34
|
@sources = []
|
36
35
|
@indentation = @parent.indentation
|
37
36
|
@_mixins = []
|
37
|
+
@_imports = []
|
38
|
+
end
|
39
|
+
|
40
|
+
def api
|
41
|
+
@parent.api # FIXME Is this weird??
|
38
42
|
end
|
39
43
|
|
40
44
|
def output=(io)
|
@@ -46,14 +50,16 @@ class Processor
|
|
46
50
|
end
|
47
51
|
|
48
52
|
def _error!(err, raise_error=false, trace=false) # FIXME much bullshit happens here
|
49
|
-
where = @sources.last || @save_location
|
53
|
+
where = @sources.last || @live.save_location
|
50
54
|
error "Error: #{err} (at #{where[1]} line #{where[2]})"
|
51
55
|
error(err.backtrace) rescue nil
|
52
56
|
raise GenericError.new("Error: #{err}") if raise_error
|
53
57
|
end
|
54
58
|
|
55
59
|
def disallowed?(name)
|
56
|
-
Disallowed.include?(name.to_sym)
|
60
|
+
flag = Disallowed.include?(name.to_sym)
|
61
|
+
# api.tty "disa name = #{name.inspect} flag = #{flag}"
|
62
|
+
flag
|
57
63
|
end
|
58
64
|
|
59
65
|
def source(enum, file, line)
|
@@ -61,11 +67,15 @@ class Processor
|
|
61
67
|
end
|
62
68
|
|
63
69
|
def peek_nextline
|
64
|
-
|
70
|
+
return nil if @sources.empty?
|
71
|
+
source = @sources.last
|
72
|
+
line = source[0].peek
|
73
|
+
line
|
65
74
|
rescue StopIteration
|
66
75
|
@sources.pop
|
67
76
|
nil
|
68
77
|
rescue => err
|
78
|
+
TTY.puts "#{__method__}: RESCUE err = #{err.inspect}"
|
69
79
|
nil
|
70
80
|
end
|
71
81
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'parser/string' # FIXME eh, should fix this
|
2
|
+
|
3
|
+
# Class Livetext skeleton (top level).
|
4
|
+
|
5
|
+
class Livetext
|
6
|
+
module Handler
|
7
|
+
end
|
8
|
+
|
9
|
+
module ParsingConstants
|
10
|
+
end
|
11
|
+
|
12
|
+
class LineParser < StringParser
|
13
|
+
module FunCall
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class FormatLine < StringParser
|
18
|
+
module FunCall
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|