Class: Code
- Inherits:
-
Object
show all
- Defined in:
- lib/code.rb,
lib/code/node.rb,
lib/code/type.rb,
lib/code/error.rb,
lib/code/object.rb,
lib/code/parser.rb,
lib/code/node/if.rb,
lib/code/type/or.rb,
lib/code/concerns.rb,
lib/code/node/not.rb,
lib/code/type/sig.rb,
lib/code/node/call.rb,
lib/code/node/code.rb,
lib/code/node/list.rb,
lib/code/parser/if.rb,
lib/code/type/hash.rb,
lib/code/node/splat.rb,
lib/code/node/while.rb,
lib/code/type/maybe.rb,
lib/code/node/base_2.rb,
lib/code/node/base_8.rb,
lib/code/node/number.rb,
lib/code/node/string.rb,
lib/code/object/code.rb,
lib/code/object/date.rb,
lib/code/object/html.rb,
lib/code/object/http.rb,
lib/code/object/json.rb,
lib/code/object/list.rb,
lib/code/object/smtp.rb,
lib/code/object/time.rb,
lib/code/parser/call.rb,
lib/code/parser/code.rb,
lib/code/parser/list.rb,
lib/code/parser/name.rb,
lib/code/type/repeat.rb,
lib/code/node/base_10.rb,
lib/code/node/base_16.rb,
lib/code/node/boolean.rb,
lib/code/node/decimal.rb,
lib/code/node/nothing.rb,
lib/code/node/ternary.rb,
lib/code/object/class.rb,
lib/code/object/range.rb,
lib/code/parser/class.rb,
lib/code/parser/equal.rb,
lib/code/parser/group.rb,
lib/code/parser/power.rb,
lib/code/parser/range.rb,
lib/code/parser/shift.rb,
lib/code/parser/splat.rb,
lib/code/parser/while.rb,
lib/code/node/function.rb,
lib/code/node/negation.rb,
lib/code/object/global.rb,
lib/code/object/number.rb,
lib/code/object/string.rb,
lib/code/parser/number.rb,
lib/code/parser/rescue.rb,
lib/code/parser/string.rb,
lib/code/node/statement.rb,
lib/code/object/base_64.rb,
lib/code/object/boolean.rb,
lib/code/object/context.rb,
lib/code/object/decimal.rb,
lib/code/object/integer.rb,
lib/code/object/nothing.rb,
lib/code/parser/boolean.rb,
lib/code/parser/greater.rb,
lib/code/parser/nothing.rb,
lib/code/parser/ternary.rb,
lib/code/concerns/shared.rb,
lib/code/node/dictionary.rb,
lib/code/object/duration.rb,
lib/code/object/function.rb,
lib/code/parser/addition.rb,
lib/code/parser/equality.rb,
lib/code/parser/function.rb,
lib/code/parser/negation.rb,
lib/code/node/unary_minus.rb,
lib/code/object/parameter.rb,
lib/code/parser/statement.rb,
lib/code/object/dictionary.rb,
lib/code/parser/bitwise_or.rb,
lib/code/parser/dictionary.rb,
lib/code/parser/or_keyword.rb,
lib/code/parser/whitespace.rb,
lib/code/node/call_argument.rb,
lib/code/parser/bitwise_and.rb,
lib/code/parser/if_modifier.rb,
lib/code/parser/not_keyword.rb,
lib/code/parser/or_operator.rb,
lib/code/parser/unary_minus.rb,
lib/code/node/left_operation.rb,
lib/code/node/square_bracket.rb,
lib/code/parser/and_operator.rb,
lib/code/parser/chained_call.rb,
lib/code/node/right_operation.rb,
lib/code/parser/left_operation.rb,
lib/code/parser/multiplication.rb,
lib/code/parser/square_bracket.rb,
lib/code/object/identifier_list.rb,
lib/code/parser/right_operation.rb,
lib/code/node/function_parameter.rb
Defined Under Namespace
Modules: Concerns
Classes: Error, Node, Object, Parser, Type
Constant Summary
collapse
- GLOBALS =
i[context error input object output source].freeze
- DEFAULT_TIMEOUT =
0
- Version =
Gem::Version.new(File.read(File.expand_path("../../VERSION", __dir__)))
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(source, context: Object::Context.new, error: StringIO.new, input: StringIO.new, object: Object::Global.new, output: StringIO.new, timeout: DEFAULT_TIMEOUT) ⇒ Code
Returns a new instance of Code.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/code.rb', line 7
def initialize(
source,
context: Object::Context.new,
error: StringIO.new,
input: StringIO.new,
object: Object::Global.new,
output: StringIO.new,
timeout: DEFAULT_TIMEOUT
)
@context = context
@error = error
@input = input
@object = object
@output = output
@source = source
@timeout = timeout
end
|
Class Method Details
31
32
33
|
# File 'lib/code.rb', line 31
def self.evaluate(...)
new(...).evaluate
end
|
.parse(source, timeout: DEFAULT_TIMEOUT) ⇒ Object
25
26
27
28
29
|
# File 'lib/code.rb', line 25
def self.parse(source, timeout: DEFAULT_TIMEOUT)
Timeout.timeout(timeout) { Parser.parse(source).to_raw }
rescue Timeout::Error
raise Error, "timeout"
end
|
Instance Method Details
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/code.rb', line 35
def evaluate
Timeout.timeout(timeout) do
Node::Code.new(Code.parse(source)).evaluate(
context: context,
error: error,
input: input,
object: object,
output: output,
source: source,
timeout: timeout
)
end
rescue Timeout::Error
raise Error, "timeout"
rescue Interrupt
raise Error, "interrupt"
end
|