Skip to content

Commit

Permalink
Fix comment rendering of code blocks in rust generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Dec 1, 2023
1 parent 685c10e commit 841a48f
Show file tree
Hide file tree
Showing 17 changed files with 555 additions and 365 deletions.
4 changes: 3 additions & 1 deletion lib/xdrgen/generators/rust.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,13 @@ def render_source_comment(out, defn)
out.puts <<-EOS.strip_heredoc
/// #{name defn} is an XDR #{defn.class.name.demodulize} defines as:
///
/// ```text
EOS

out.puts "/// " + defn.text_value.split("\n").join("\n/// ")
out.puts "/// " + defn.text_value.split("\n").join("\n/// ")

out.puts <<-EOS.strip_heredoc
/// ```
///
EOS
end
Expand Down
10 changes: 6 additions & 4 deletions spec/output/generator_spec_rust/block_comments.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2688,10 +2688,12 @@ mod test {

/// AccountFlags is an XDR Enum defines as:
///
/// enum AccountFlags
/// { // masks for each flag
/// AUTH_REQUIRED_FLAG = 0x1
/// };
/// ```text
/// enum AccountFlags
/// { // masks for each flag
/// AUTH_REQUIRED_FLAG = 0x1
/// };
/// ```
///
// enum
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
12 changes: 9 additions & 3 deletions spec/output/generator_spec_rust/const.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2688,19 +2688,25 @@ mod test {

/// Foo is an XDR Const defines as:
///
/// const FOO = 1;
/// ```text
/// const FOO = 1;
/// ```
///
pub const FOO: u64 = 1;

/// TestArray is an XDR Typedef defines as:
///
/// typedef int TestArray[FOO];
/// ```text
/// typedef int TestArray[FOO];
/// ```
///
pub type TestArray = [i32; Foo];

/// TestArray2 is an XDR Typedef defines as:
///
/// typedef int TestArray2<FOO>;
/// ```text
/// typedef int TestArray2<FOO>;
/// ```
///
pub type TestArray2 = VecM::<i32, 1>;

Expand Down
72 changes: 39 additions & 33 deletions spec/output/generator_spec_rust/enum.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2688,29 +2688,31 @@ mod test {

/// MessageType is an XDR Enum defines as:
///
/// enum MessageType
/// {
/// ERROR_MSG,
/// HELLO,
/// DONT_HAVE,
///
/// GET_PEERS, // gets a list of peers this guy knows about
/// PEERS,
///
/// GET_TX_SET, // gets a particular txset by hash
/// TX_SET,
///
/// GET_VALIDATIONS, // gets validations for a given ledger hash
/// VALIDATIONS,
///
/// TRANSACTION, //pass on a tx you have heard about
/// JSON_TRANSACTION,
///
/// // FBA
/// GET_FBA_QUORUMSET,
/// FBA_QUORUMSET,
/// FBA_MESSAGE
/// };
/// ```text
/// enum MessageType
/// {
/// ERROR_MSG,
/// HELLO,
/// DONT_HAVE,
///
/// GET_PEERS, // gets a list of peers this guy knows about
/// PEERS,
///
/// GET_TX_SET, // gets a particular txset by hash
/// TX_SET,
///
/// GET_VALIDATIONS, // gets validations for a given ledger hash
/// VALIDATIONS,
///
/// TRANSACTION, //pass on a tx you have heard about
/// JSON_TRANSACTION,
///
/// // FBA
/// GET_FBA_QUORUMSET,
/// FBA_QUORUMSET,
/// FBA_MESSAGE
/// };
/// ```
///
// enum
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -2867,11 +2869,13 @@ Self::FbaMessage => "FbaMessage",

/// Color is an XDR Enum defines as:
///
/// enum Color {
/// RED=0,
/// GREEN=1,
/// BLUE=2
/// };
/// ```text
/// enum Color {
/// RED=0,
/// GREEN=1,
/// BLUE=2
/// };
/// ```
///
// enum
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -2973,11 +2977,13 @@ Self::Blue => "Blue",

/// Color2 is an XDR Enum defines as:
///
/// enum Color2 {
/// RED2=RED,
/// GREEN2=1,
/// BLUE2=2
/// };
/// ```text
/// enum Color2 {
/// RED2=RED,
/// GREEN2=1,
/// BLUE2=2
/// };
/// ```
///
// enum
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
68 changes: 39 additions & 29 deletions spec/output/generator_spec_rust/nesting.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2688,11 +2688,13 @@ mod test {

/// UnionKey is an XDR Enum defines as:
///
/// enum UnionKey {
/// ONE = 1,
/// TWO = 2,
/// OFFER = 3
/// };
/// ```text
/// enum UnionKey {
/// ONE = 1,
/// TWO = 2,
/// OFFER = 3
/// };
/// ```
///
// enum
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -2794,15 +2796,19 @@ Self::Offer => "Offer",

/// Foo is an XDR Typedef defines as:
///
/// typedef int Foo;
/// ```text
/// typedef int Foo;
/// ```
///
pub type Foo = i32;

/// MyUnionOne is an XDR NestedStruct defines as:
///
/// struct {
/// int someInt;
/// }
/// ```text
/// struct {
/// int someInt;
/// }
/// ```
///
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
Expand Down Expand Up @@ -2834,10 +2840,12 @@ impl WriteXdr for MyUnionOne {

/// MyUnionTwo is an XDR NestedStruct defines as:
///
/// struct {
/// int someInt;
/// Foo foo;
/// }
/// ```text
/// struct {
/// int someInt;
/// Foo foo;
/// }
/// ```
///
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
Expand Down Expand Up @@ -2872,22 +2880,24 @@ self.foo.write_xdr(w)?;

/// MyUnion is an XDR Union defines as:
///
/// union MyUnion switch (UnionKey type)
/// {
/// case ONE:
/// struct {
/// int someInt;
/// } one;
///
/// case TWO:
/// struct {
/// int someInt;
/// Foo foo;
/// } two;
///
/// case OFFER:
/// void;
/// };
/// ```text
/// union MyUnion switch (UnionKey type)
/// {
/// case ONE:
/// struct {
/// int someInt;
/// } one;
///
/// case TWO:
/// struct {
/// int someInt;
/// Foo foo;
/// } two;
///
/// case OFFER:
/// void;
/// };
/// ```
///
// union with discriminant UnionKey
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
18 changes: 11 additions & 7 deletions spec/output/generator_spec_rust/optional.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2688,18 +2688,22 @@ mod test {

/// Arr is an XDR Typedef defines as:
///
/// typedef int Arr[2];
/// ```text
/// typedef int Arr[2];
/// ```
///
pub type Arr = [i32; 2];

/// HasOptions is an XDR Struct defines as:
///
/// struct HasOptions
/// {
/// int* firstOption;
/// int *secondOption;
/// Arr *thirdOption;
/// };
/// ```text
/// struct HasOptions
/// {
/// int* firstOption;
/// int *secondOption;
/// Arr *thirdOption;
/// };
/// ```
///
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
Expand Down
22 changes: 13 additions & 9 deletions spec/output/generator_spec_rust/struct.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2688,20 +2688,24 @@ mod test {

/// Int64 is an XDR Typedef defines as:
///
/// typedef hyper int64;
/// ```text
/// typedef hyper int64;
/// ```
///
pub type Int64 = i64;

/// MyStruct is an XDR Struct defines as:
///
/// struct MyStruct
/// {
/// int someInt;
/// int64 aBigInt;
/// opaque someOpaque[10];
/// string someString<>;
/// string maxString<100>;
/// };
/// ```text
/// struct MyStruct
/// {
/// int someInt;
/// int64 aBigInt;
/// opaque someOpaque[10];
/// string someString<>;
/// string maxString<100>;
/// };
/// ```
///
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
Expand Down
Loading

0 comments on commit 841a48f

Please sign in to comment.