Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit 0fc5f82

Browse files
committed
changed parse() fn to take input and then options
1 parent 9d50460 commit 0fc5f82

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

api.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ namespace lib_ruby_parser
99

1010
extern "C"
1111
{
12-
ParserResultBlob LIB_RUBY_PARSER_parse(ParserOptionsBlob options, ByteListBlob input);
12+
ParserResultBlob LIB_RUBY_PARSER_parse(ByteListBlob input, ParserOptionsBlob options);
1313
}
1414

15-
ParserResult parse(ParserOptions options, ByteList input)
15+
ParserResult parse(ByteList input, ParserOptions options)
1616
{
1717
return from_blob<ParserResultBlob, ParserResult>(
1818
LIB_RUBY_PARSER_parse(
19-
into_blob<ParserOptions, ParserOptionsBlob>(std::move(options)),
20-
into_blob<ByteList, ByteListBlob>(std::move(input))));
19+
into_blob<ByteList, ByteListBlob>(std::move(input)),
20+
into_blob<ParserOptions, ParserOptionsBlob>(std::move(options))));
2121
}
2222
}
2323

@@ -39,7 +39,9 @@ namespace lib_ruby_parser
3939

4040
ByteList input = ByteList::Copied("2 + 3", 5);
4141

42-
ParserResult result = parse(std::move(options), std::move(input));
42+
ParserResult result = parse(
43+
std::move(input),
44+
std::move(options));
4345

4446
assert_eq(result.ast->tag, Node::Tag::SEND);
4547
assert_eq(result.tokens.len, 4); // tINT tPLUS tINT EOF

api.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace lib_ruby_parser
1010
Parses given `input` according to `option`.
1111
This is the main entrypoint API.
1212
*/
13-
ParserResult parse(ParserOptions options, ByteList input);
13+
ParserResult parse(ByteList input, ParserOptions options);
1414

1515
#ifdef TEST_ENV
1616
void run_test_group_api(void);

benchmark/benchmark.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ int main()
3030
lib_ruby_parser::ByteList input = std::move(file.content);
3131

3232
lib_ruby_parser::parse(
33-
std::move(options),
34-
std::move(input));
33+
std::move(input),
34+
std::move(options));
3535
}
3636

3737
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();

benchmark/cpp-parser

4.54 MB
Binary file not shown.

ruby-parser-cpp/src/parser_result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ pub extern "C" fn LIB_RUBY_PARSER_drop_parser_result(parser_result: *mut ParserR
8181

8282
#[no_mangle]
8383
pub extern "C" fn LIB_RUBY_PARSER_parse(
84-
options: ParserOptionsBlob,
8584
input: ByteListBlob,
85+
options: ParserOptionsBlob,
8686
) -> ParserResultBlob {
8787
let options = CParserOptions::from(options);
8888
let options = lib_ruby_parser::ParserOptions::from(options);

0 commit comments

Comments
 (0)