[ruby/yarp] Add source to ParseResult
https://github.com/ruby/yarp/commit/f3802e03e0
This commit is contained in:
parent
61efa9c823
commit
31f83a6fea
@ -143,13 +143,14 @@ module YARP
|
|||||||
# the AST, any comments that were encounters, and any errors that were
|
# the AST, any comments that were encounters, and any errors that were
|
||||||
# encountered.
|
# encountered.
|
||||||
class ParseResult
|
class ParseResult
|
||||||
attr_reader :value, :comments, :errors, :warnings
|
attr_reader :value, :comments, :errors, :warnings, :source
|
||||||
|
|
||||||
def initialize(value, comments, errors, warnings)
|
def initialize(value, comments, errors, warnings, source)
|
||||||
@value = value
|
@value = value
|
||||||
@comments = comments
|
@comments = comments
|
||||||
@errors = errors
|
@errors = errors
|
||||||
@warnings = warnings
|
@warnings = warnings
|
||||||
|
@source = source
|
||||||
end
|
end
|
||||||
|
|
||||||
def deconstruct_keys(keys)
|
def deconstruct_keys(keys)
|
||||||
@ -224,6 +225,10 @@ module YARP
|
|||||||
def self.load(source, serialized)
|
def self.load(source, serialized)
|
||||||
Serialize.load(source, serialized)
|
Serialize.load(source, serialized)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.newlines(source)
|
||||||
|
YARP.parse(source).source.offsets
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require_relative "yarp/lex_compat"
|
require_relative "yarp/lex_compat"
|
||||||
|
@ -700,7 +700,7 @@ module YARP
|
|||||||
raise StandardError, "Lost tokens when performing lex_compat"
|
raise StandardError, "Lost tokens when performing lex_compat"
|
||||||
end
|
end
|
||||||
|
|
||||||
ParseResult.new(tokens, result.comments, result.errors, result.warnings)
|
ParseResult.new(tokens, result.comments, result.errors, result.warnings, [])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -391,10 +391,11 @@ lex_input(input_t *input, const char *filepath) {
|
|||||||
lex_data.tokens,
|
lex_data.tokens,
|
||||||
parser_comments(&parser, source),
|
parser_comments(&parser, source),
|
||||||
parser_errors(&parser, lex_data.encoding, source),
|
parser_errors(&parser, lex_data.encoding, source),
|
||||||
parser_warnings(&parser, lex_data.encoding, source)
|
parser_warnings(&parser, lex_data.encoding, source),
|
||||||
|
source
|
||||||
};
|
};
|
||||||
|
|
||||||
VALUE result = rb_class_new_instance(4, result_argv, rb_cYARPParseResult);
|
VALUE result = rb_class_new_instance(5, result_argv, rb_cYARPParseResult);
|
||||||
|
|
||||||
yp_node_destroy(&parser, node);
|
yp_node_destroy(&parser, node);
|
||||||
yp_parser_free(&parser);
|
yp_parser_free(&parser);
|
||||||
@ -446,10 +447,11 @@ parse_input(input_t *input, const char *filepath) {
|
|||||||
yp_ast_new(&parser, node, encoding),
|
yp_ast_new(&parser, node, encoding),
|
||||||
parser_comments(&parser, source),
|
parser_comments(&parser, source),
|
||||||
parser_errors(&parser, encoding, source),
|
parser_errors(&parser, encoding, source),
|
||||||
parser_warnings(&parser, encoding, source)
|
parser_warnings(&parser, encoding, source),
|
||||||
|
source
|
||||||
};
|
};
|
||||||
|
|
||||||
VALUE result = rb_class_new_instance(4, result_argv, rb_cYARPParseResult);
|
VALUE result = rb_class_new_instance(5, result_argv, rb_cYARPParseResult);
|
||||||
|
|
||||||
yp_node_destroy(&parser, node);
|
yp_node_destroy(&parser, node);
|
||||||
yp_parser_free(&parser);
|
yp_parser_free(&parser);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user