Skip to content

Commit

Permalink
[documentation] Add support for dotted syntax signatures [#95]
Browse files Browse the repository at this point in the history
  • Loading branch information
cipriancraciun committed Jun 26, 2018
1 parent 63c702d commit 1a842c0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
25 changes: 17 additions & 8 deletions sources/documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ pub struct SyntaxSignatureVariant {
}

pub enum SyntaxSignaturePattern {
List (StdBox<[SyntaxSignaturePattern]>),
List (StdBox<[SyntaxSignaturePattern]>, Option<StdBox<SyntaxSignaturePattern>>),
Keyword (StdRc<SyntaxSignatureKeyword>),
Variadic (StdBox<SyntaxSignaturePattern>),
SyntaxIdentifier,
Expand Down Expand Up @@ -1390,7 +1390,7 @@ impl SyntaxSignaturePattern {
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn format (&self) -> (Value) {
match self {
SyntaxSignaturePattern::List (patterns) => {
SyntaxSignaturePattern::List (patterns, pattern_dotted) => {
let mut tokens = StdVec::with_capacity (patterns.len ());
for pattern in patterns.iter () {
match pattern {
Expand All @@ -1402,7 +1402,13 @@ impl SyntaxSignaturePattern {
tokens.push (pattern.format ()),
}
}
let tokens = list_collect (tokens, Some (true));
let token_dotted = if let Some (pattern_dotted) = pattern_dotted {
let token_dotted = pattern_dotted.format ();
Some (token_dotted)
} else {
None
};
let tokens = list_collect_dotted (tokens, token_dotted, Some (true));
return tokens;
},
SyntaxSignaturePattern::Variadic (pattern) => {
Expand Down Expand Up @@ -2058,9 +2064,6 @@ fn parse_syntax_signature_variant (token : Value, keywords : &StdMap<StdString,

#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
fn parse_syntax_signature_patterns (tokens : StdVec<Value>, token_dotted : Option<Value>, keywords : &StdMap<StdString, StdRc<SyntaxSignatureKeyword>>) -> (Outcome<SyntaxSignaturePattern>) {
if token_dotted.is_some () {
fail_unimplemented! (0x5b4f1c87);
}
let mut patterns = StdVec::with_capacity (tokens.len ());
let mut end_expected = false;
for token in tokens.into_iter () {
Expand Down Expand Up @@ -2090,7 +2093,13 @@ fn parse_syntax_signature_patterns (tokens : StdVec<Value>, token_dotted : Optio
fail! (0x60d8e7c6),
}
}
let pattern = SyntaxSignaturePattern::List (patterns.into_boxed_slice ());
let pattern_dotted = if let Some (token_dotted) = token_dotted {
let pattern_dotted = try! (parse_syntax_signature_pattern (token_dotted, keywords));
Some (StdBox::new (pattern_dotted))
} else {
None
};
let pattern = SyntaxSignaturePattern::List (patterns.into_boxed_slice (), pattern_dotted);
succeed! (pattern);
}

Expand Down Expand Up @@ -2119,7 +2128,7 @@ fn parse_syntax_signature_pattern (token : Value, keywords : &StdMap<StdString,
return parse_syntax_signature_patterns (tokens, token_dotted, keywords);
},
ValueClassMatchInto::Null =>
succeed! (SyntaxSignaturePattern::List (StdBox::new ([]))),
succeed! (SyntaxSignaturePattern::List (StdBox::new ([]), None)),
_ =>
fail! (0x2274e06a),
}
Expand Down
12 changes: 10 additions & 2 deletions sources/tools_documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,16 @@ fn dump_json_syntax_signature_variant (variant : &SyntaxSignatureVariant) -> (js
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
fn dump_json_syntax_signature_pattern (pattern : &SyntaxSignaturePattern) -> (json::Value) {
match pattern {
SyntaxSignaturePattern::List (patterns) =>
json::Value::Array (vec_map! (patterns.iter (), pattern, dump_json_syntax_signature_pattern (pattern))),
SyntaxSignaturePattern::List (patterns, pattern_dotted) =>
if let Some (pattern_dotted) = pattern_dotted {
json! ([
".",
json::Value::Array (vec_map! (patterns.iter (), pattern, dump_json_syntax_signature_pattern (pattern))),
dump_json_syntax_signature_pattern (pattern_dotted),
])
} else {
json::Value::Array (vec_map! (patterns.iter (), pattern, dump_json_syntax_signature_pattern (pattern)))
},
SyntaxSignaturePattern::Keyword (keyword) =>
json::Value::String (StdString::from (keyword.identifier_clone ())),
SyntaxSignaturePattern::Variadic (pattern) =>
Expand Down

0 comments on commit 1a842c0

Please sign in to comment.