Skip to content

Commit

Permalink
Syntax and printing for attribute spec
Browse files Browse the repository at this point in the history
Summary: Syntax support and pretty printing for attribute specification. There are two kinds of syntax introduced: attribute spec and attribute which is the child of attribute spec.

Reviewed By: ericlippert

Differential Revision: D3498440

fbshipit-source-id: 664f7e6a25d1aec839adb70e1bf7465f471965b8
  • Loading branch information
shiyu-wang-999 authored and Hhvm Bot committed Jun 30, 2016
1 parent c4967c1 commit 1bd6789
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
12 changes: 12 additions & 0 deletions hphp/hack/src/full_fidelity/full_fidelity_pretty_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ let rec get_doc node =
let def_equal = get_doc (default_equal x) in
let def_value = get_doc (default_value x) in
group_doc (def_equal ^| def_value)
| AttributeSpecification x ->
let left = get_doc (attribute_spec_left_double_angle x) in
let right = get_doc (attribute_spec_right_double_angle x) in
let specs = get_doc (attribute_spec_attribute_list x) in
indent_block_no_space left specs right indt
| Attribute x ->
let name = get_doc (attribute_name x) in
let left = get_doc (attribute_left_paren x) in
let right = get_doc (attribute_right_paren x) in
let values = get_doc (attribute_values x) in
let left_part = group_doc (name ^^| left) in
indent_block_no_space left_part values right indt
| CompoundStatement x ->
let left = get_doc (compound_left_brace x) in
let right = get_doc (compound_right_brace x) in
Expand Down
66 changes: 66 additions & 0 deletions hphp/hack/src/full_fidelity/full_fidelity_syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ module WithToken(Token: TokenType) = struct
default_equal : t;
default_value : t
}
and attribute_specification = {
attribute_spec_left_double_angle : t;
attribute_spec_attribute_list : t;
attribute_spec_right_double_angle : t
}
and attribute = {
attribute_name : t;
attribute_left_paren : t;
attribute_values : t;
attribute_right_paren : t
}
and compound_statement = {
compound_left_brace : t;
compound_statements : t;
Expand Down Expand Up @@ -390,6 +401,8 @@ module WithToken(Token: TokenType) = struct
| FunctionDeclaration of function_declaration
| ParameterDeclaration of parameter_declaration
| DefaultArgumentSpecifier of default_argument_specifier
| AttributeSpecification of attribute_specification
| Attribute of attribute

| CompoundStatement of compound_statement
| ExpressionStatement of expression_statement
Expand Down Expand Up @@ -468,6 +481,8 @@ module WithToken(Token: TokenType) = struct
| FunctionDeclaration _ -> SyntaxKind.FunctionDeclaration
| ParameterDeclaration _ -> SyntaxKind.ParameterDeclaration
| DefaultArgumentSpecifier _ -> SyntaxKind.DefaultArgumentSpecifier
| AttributeSpecification _ -> SyntaxKind.AttributeSpecification
| Attribute _ -> SyntaxKind.Attribute
| CompoundStatement _ -> SyntaxKind.CompoundStatement
| ExpressionStatement _ -> SyntaxKind.ExpressionStatement
| WhileStatement _ -> SyntaxKind.WhileStatement
Expand Down Expand Up @@ -531,6 +546,9 @@ module WithToken(Token: TokenType) = struct
let is_parameter node = kind node = SyntaxKind.ParameterDeclaration
let is_default_arg_specifier node =
kind node = SyntaxKind.DefaultArgumentSpecifier
let is_attribute_specification node =
kind node = SyntaxKind.AttributeSpecification
let is_attribute node = kind node = SyntaxKind.Attribute
let is_compound_statement node = kind node = SyntaxKind.CompoundStatement
let is_expression_statement node =
kind node = SyntaxKind.ExpressionStatement
Expand Down Expand Up @@ -621,6 +639,16 @@ module WithToken(Token: TokenType) = struct
| DefaultArgumentSpecifier
{ default_equal; default_value } ->
[ default_equal; default_value ]
| AttributeSpecification
{ attribute_spec_left_double_angle; attribute_spec_attribute_list ;
attribute_spec_right_double_angle } ->
[ attribute_spec_left_double_angle; attribute_spec_attribute_list ;
attribute_spec_right_double_angle ]
| Attribute
{ attribute_name; attribute_left_paren; attribute_values;
attribute_right_paren } ->
[ attribute_name; attribute_left_paren; attribute_values;
attribute_right_paren ]
| CompoundStatement
{ compound_left_brace; compound_statements; compound_right_brace } ->
[ compound_left_brace; compound_statements; compound_right_brace ]
Expand Down Expand Up @@ -829,6 +857,16 @@ module WithToken(Token: TokenType) = struct
| DefaultArgumentSpecifier
{ default_equal; default_value } ->
[ "default_equal"; "default_value" ]
| AttributeSpecification
{ attribute_spec_left_double_angle; attribute_spec_attribute_list ;
attribute_spec_right_double_angle } ->
[ "attribute_spec_left_double_angle"; "attribute_spec_attribute_list" ;
"attribute_spec_right_double_angle" ]
| Attribute
{ attribute_name; attribute_left_paren; attribute_values;
attribute_right_paren } ->
[ "attribute_name"; "attribute_left_paren"; "attribute_values";
"attribute_right_paren" ]
| CompoundStatement
{ compound_left_brace; compound_statements; compound_right_brace } ->
[ "compound_left_brace"; "compound_statements"; "compound_right_brace" ]
Expand Down Expand Up @@ -1049,6 +1087,14 @@ module WithToken(Token: TokenType) = struct
let param_default x = x.param_default
let default_equal x = x.default_equal
let default_value x = x.default_value
let attribute_spec_left_double_angle x = x.attribute_spec_left_double_angle
let attribute_spec_attribute_list x = x.attribute_spec_attribute_list
let attribute_spec_right_double_angle x =
x.attribute_spec_right_double_angle
let attribute_name x = x.attribute_name
let attribute_left_paren x = x.attribute_left_paren
let attribute_values x = x.attribute_values
let attribute_right_paren x = x.attribute_right_paren
let compound_left_brace x = x.compound_left_brace
let compound_statements x = x.compound_statements
let compound_right_brace x = x.compound_right_brace
Expand Down Expand Up @@ -1233,6 +1279,14 @@ module WithToken(Token: TokenType) = struct
| (SyntaxKind.DefaultArgumentSpecifier, [ default_equal;
default_value ]) ->
DefaultArgumentSpecifier { default_equal; default_value }
| SyntaxKind.AttributeSpecification, [ attribute_spec_left_double_angle;
attribute_spec_attribute_list; attribute_spec_right_double_angle ] ->
AttributeSpecification { attribute_spec_left_double_angle;
attribute_spec_attribute_list; attribute_spec_right_double_angle }
| SyntaxKind.Attribute, [ attribute_name; attribute_left_paren;
attribute_values; attribute_right_paren ] ->
Attribute { attribute_name; attribute_left_paren; attribute_values;
attribute_right_paren }
| (SyntaxKind.CompoundStatement, [ compound_left_brace;
compound_statements; compound_right_brace ]) ->
CompoundStatement { compound_left_brace; compound_statements;
Expand Down Expand Up @@ -1556,6 +1610,18 @@ module WithToken(Token: TokenType) = struct
from_children SyntaxKind.DefaultArgumentSpecifier
[ default_equal; default_value ]

let make_attribute_specification attribute_spec_left_double_angle
attribute_spec_attribute_list attribute_spec_right_double_angle =
from_children SyntaxKind.AttributeSpecification
[ attribute_spec_left_double_angle; attribute_spec_attribute_list;
attribute_spec_right_double_angle ]

let make_attribute attribute_name attribute_left_paren attribute_values
attribute_right_paren =
from_children SyntaxKind.Attribute
[ attribute_name; attribute_left_paren; attribute_values;
attribute_right_paren ]

let make_compound_statement
compound_left_brace compound_statements compound_right_brace =
from_children SyntaxKind.CompoundStatement
Expand Down
4 changes: 4 additions & 0 deletions hphp/hack/src/full_fidelity/full_fidelity_syntax_kind.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type t =
| FunctionDeclaration
| ParameterDeclaration
| DefaultArgumentSpecifier
| AttributeSpecification
| Attribute

(* Statements *)
| CompoundStatement
Expand Down Expand Up @@ -90,6 +92,8 @@ let to_string kind =
| Script -> "script"
| FunctionDeclaration -> "function_declaration"
| ParameterDeclaration -> "parameter_declaration"
| AttributeSpecification -> "attribute_specification"
| Attribute -> "attribute"
| CompoundStatement -> "compound_statement"
| ExpressionStatement -> "expression_statement"
| WhileStatement -> "while_statement"
Expand Down

0 comments on commit 1bd6789

Please sign in to comment.