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

Commit afc72b8

Browse files
committed
switch to doxygen
1 parent 4f15e7b commit afc72b8

17 files changed

+2739
-227
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ benchmark/c-parser
2222
benchmark/filelist
2323
benchmark/stats
2424
*.benchmark-out
25+
docs/

Doxyfile

Lines changed: 2632 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ clean:
6464
rm -f *.$(A)
6565
rm -rf *.dSYM
6666

67-
check:
68-
CC=$(CC) ruby assert_defs.rb bindings.hpp bindings.cpp bindings_messages.cpp bindings_nodes.cpp
67+
doxygen: messages.hpp nodes.hpp token_ids.hpp
68+
rm -rf docs
69+
doxygen

README.md

Lines changed: 38 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,55 @@
11
# C++ bindings for `lib-ruby-parser`
22

3-
tldr; You can find examples in `test/test.cpp`. Valgrind and ASAN give no errors.
3+
[Documentation](https://lib-ruby-parser.github.io/cpp-bindings/)
44

5-
## API
5+
All classes/methods are defined under `lib_ruby_parser` namespace. API mostly mirrors Rust version.
66

7-
All classes/methods are defined in the `lib_ruby_parser` namespace.
7+
Pre-compiled library and header file are available on [Releases](https://github.com/lib-ruby-parser/cpp-bindings/releases), supported platforms:
88

9-
1. `ParserResult::from_source(Bytes source, ParserOptions options)`
9+
+ `x86_64-apple-darwin`
10+
+ `x86_64-unknown-linux-gnu`
11+
+ `x86_64-pc-windows-msvc`
12+
+ `x86_64-pc-windows-gnu`
1013

11-
Parses given input into `ParserResult`, has the following fields:
12-
```cpp
13-
// AST
14-
std::unique_ptr<Node> ast;
14+
## Basic API
1515

16-
// List of tokns
17-
std::vector<Token> tokens;
16+
```cpp
17+
// Configure parsing options
18+
lib_ruby_parser::ParserOptions options(
19+
/* 1. filename */
20+
lib_ruby_parser::String::Copied("(eval)"),
1821

19-
// List of diagnostic messages
20-
std::vector<Diagnostic> diagnostics;
22+
/* 2. decoder */
23+
lib_ruby_parser::MaybeDecoder(lib_ruby_parser::Decoder(nullptr)),
2124

22-
// List of comments
23-
std::vector<Comment> comments;
25+
/* 3. token_rewriter */
26+
lib_ruby_parser::MaybeTokenRewriter(lib_ruby_parser::TokenRewriter(nullptr)),
2427

25-
// List of magic comments
26-
std::vector<MagicComment> magic_comments;
28+
/* 4. record_tokens */
29+
true);
2730

28-
// Decoded input
29-
Input input;
30-
```
31+
// Setup input to parse
32+
lib_ruby_parser::ByteList input = lib_ruby_parser::ByteList::Copied("2 + 3", 5);
3133

32-
2. `Node::is<T>` where `T` is one of the ~100 node types.
34+
lib_ruby_parser::ParserResult result = lib_ruby_parser::parse(
35+
std::move(input),
36+
std::move(options));
3337

34-
```cpp
35-
ast.is<Args>()
36-
// => true
38+
assert_eq(result.ast->tag, lib_ruby_parser::Node::Tag::SEND);
39+
assert_eq(result.tokens.len, 4); // tINT tPLUS tINT EOF
40+
assert_eq(result.comments.len, 0);
41+
assert_eq(result.magic_comments.len, 0);
42+
assert_byte_list(result.input.bytes, "2 + 3");
43+
```
3744
38-
ast.is<Defs>()
39-
// => false
40-
```
45+
`ParserResult` contains the following fields:
4146
42-
3. `Node::get<T>` where `T` is one of the ~100 node locs
47+
1. `Node* ast` - potentually nullable AST, tagged enum
48+
2. `TokenList tokens` - list of tokens
49+
3. `DiagnosticList diagnostics` - list of diagnostics
50+
4. `CommentList comments` - list of comments
51+
5. `MagicCommentList magic_comments` - list of magic comments
52+
6. `DecodedInput input` - decoded input
4353
44-
```cpp
45-
Args *args = ast.get<Args>()
46-
```
54+
All node classes fully match node structs of the original Rust implementation. You can check [full documentation](https://docs.rs/lib-ruby-parser) (`nodes` module)
4755
48-
4. All node classes fully match node structs of the original Rust implementation. You can check [full documentation](https://docs.rs/lib-ruby-parser) (`nodes` module)
49-
50-
5. `Token` has the following fields and methods:
51-
52-
```cpp
53-
std::string token_value;
54-
std::unique_ptr<Loc> loc; // has numeric "begin" and "end" fields
55-
std::string name();
56-
```
57-
58-
Also it has a numeric `token_type` field that probably could be used for fast comparison. It is used to get `name()`, so it's different for different token types.
59-
60-
6. `Diagnostic` has the following fields:
61-
62-
```cpp
63-
ErrorLevel level; // enum with WARNING and ERROR values
64-
std::unique_ptr<DiagnosticMessage> message;
65-
std::unique_ptr<Loc> loc;
66-
```
67-
68-
can be rendered either using `render_message()` or `render(const Bytes &)`
69-
70-
7. `Comment` has the following fields:
71-
72-
```cpp
73-
CommentType kind; // enum with INLINE, DOCUMENT and UNKNOWN values
74-
std::unique_ptr<Loc> location;
75-
```
76-
77-
8. `Loc` has the following fields and methods:
78-
79-
```cpp
80-
uint32_t begin;
81-
uint32_t end;
82-
std::string source(Input &input);
83-
```
84-
85-
`input` is what you get from `ParserResult::from`. It can be different from your original source if it has magic encoding comment.
86-
87-
9. `MagicComment` has the following fields:
88-
89-
```cpp
90-
MagicCommentKind kind; // enum with ENCODING, FROZEN_STRING_LITERAL, WARN_INDENT values
91-
92-
// location of key/value
93-
// "# encoding: utf-8"
94-
// ~~~~~~~~ key
95-
// ~~~~~ value
96-
std::unique_ptr<Loc> key_l;
97-
std::unique_ptr<Loc> value_l;
98-
```

api.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
namespace lib_ruby_parser
88
{
9-
/*
10-
Parses given `input` according to `option`.
11-
This is the main entrypoint API.
12-
*/
9+
/// Parses given `input` according to `option`.
10+
/// This is the main entrypoint API.
1311
ParserResult parse(ByteList input, ParserOptions options);
1412

1513
#ifdef TEST_ENV

bytes.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
namespace lib_ruby_parser
77
{
8-
/*
9-
Representation of a Vec<u8>.
10-
`capacity` doesn't matter.
11-
*/
8+
/// Representation of a Vec<u8>.
9+
/// `capacity` doesn't matter.
1210
class ByteList
1311
{
1412
public:
@@ -27,12 +25,15 @@ namespace lib_ruby_parser
2725

2826
~ByteList();
2927

28+
/// Constructs an "owned" version of `ByteList`,
29+
/// takes ownership of the given pointer.
3030
static ByteList Owned(char *s, size_t len);
31+
32+
/// Constructs a `ByteList` by copying given pointer
3133
static ByteList Copied(const char *s, size_t len);
3234
};
33-
/*
34-
Rerpresentation of `Bytes` struct from lib-ruby-parser.
35-
*/
35+
36+
/// Rerpresentation of `Bytes` struct from lib-ruby-parser.
3637
class Bytes
3738
{
3839
public:

comment.hpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,22 @@
66

77
namespace lib_ruby_parser
88
{
9-
/*
10-
Equivalent of `lib_ruby_parser::source::CommentType`
11-
*/
9+
/// Equivalent of `lib_ruby_parser::source::CommentType`
1210
enum class CommentType
1311
{
1412
INLINE,
1513
DOCUMENT,
1614
UNKNOWN,
1715
};
1816

19-
/*
20-
Equivalent of `lib_ruby_parser::source::Comment`
21-
*/
17+
/// Equivalent of `lib_ruby_parser::source::Comment`
2218
class Comment
2319
{
2420
public:
25-
/*
26-
Location of the comment
27-
*/
21+
/// Location of the comment
2822
Loc location;
2923

30-
/*
31-
Kind of the comment (inline/document/unknown)
32-
*/
24+
/// Kind of the comment (inline/document/unknown)
3325
CommentType kind;
3426

3527
Comment() = delete;
@@ -42,9 +34,7 @@ namespace lib_ruby_parser
4234
Comment &operator=(Comment &&) = default;
4335
};
4436

45-
/*
46-
Equivalent of `Vec<lib_ruby_parser::source::Comment>`
47-
*/
37+
/// Equivalent of `Vec<lib_ruby_parser::source::Comment>`
4838
class CommentList
4939
{
5040
public:

decoded_input.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
namespace lib_ruby_parser
99
{
10-
/*
11-
Equivalent of `lib_ruby_parser::source::DecodedInput`
12-
*/
10+
/// Equivalent of `lib_ruby_parser::source::DecodedInput`
1311
class DecodedInput
1412
{
1513
public:

diagnostic.hpp

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,24 @@
88

99
namespace lib_ruby_parser
1010
{
11-
/*
12-
Equivalent of `lib_ruby_parser::ErrorLevel`
13-
*/
11+
/// Equivalent of `lib_ruby_parser::ErrorLevel`
1412
enum class ErrorLevel
1513
{
1614
WARNING,
1715
ERROR
1816
};
1917

20-
/*
21-
Equivalent of `lib_ruby_parser::Diagnostic`
22-
*/
18+
/// Equivalent of `lib_ruby_parser::Diagnostic`
2319
class Diagnostic
2420
{
2521
public:
26-
/*
27-
Level of the diagnostic (error/warning)
28-
*/
22+
/// Level of the diagnostic (error/warning)
2923
ErrorLevel level;
3024

31-
/*
32-
Message of the diagnsotic
33-
*/
25+
/// Message of the diagnsotic
3426
DiagnosticMessage message;
3527

36-
/*
37-
Location of the diagnostic
38-
*/
28+
/// Location of the diagnostic
3929
Loc loc;
4030

4131
Diagnostic() = delete;
@@ -47,17 +37,13 @@ namespace lib_ruby_parser
4737
Diagnostic(Diagnostic &&) = default;
4838
Diagnostic &operator=(Diagnostic &&) = default;
4939

50-
/*
51-
Render given diagnsostic on a given source input.
52-
Equivalent of lib_ruby_parser::Diagnostic::render.
53-
Return owned NULL-terminated string.
54-
*/
40+
/// Render given diagnsostic on a given source input.
41+
/// Equivalent of lib_ruby_parser::Diagnostic::render.
42+
/// Return owned NULL-terminated string.
5543
std::string render(const DecodedInput &input) const;
5644
};
5745

58-
/*
59-
Equivalent of `Vec<lib_ruby_parser::Diagnostic`
60-
*/
46+
/// Equivalent of `Vec<lib_ruby_parser::Diagnostic`
6147
class DiagnosticList
6248
{
6349
public:

loc.hpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
namespace lib_ruby_parser
1010
{
11-
/*
12-
`Loc` struct from `lib-ruby-parser`
13-
*/
11+
/// `Loc` struct from `lib-ruby-parser`
1412
class Loc
1513
{
1614
public:
@@ -22,15 +20,7 @@ namespace lib_ruby_parser
2220
std::string source(const DecodedInput &decoded_input) const;
2321
};
2422

25-
/*
26-
Returns source code of the given location.
27-
Equivalent of `lib_ruby_parser::Loc::source`
28-
*/
29-
// char *loc_source(const Loc *loc, const DecodedInput *input);
30-
31-
/*
32-
Equivalent of `Option<Loc>`
33-
*/
23+
/// Equivalent of `Option<Loc>`
3424
class MaybeLoc
3525
{
3626
public:

0 commit comments

Comments
 (0)