Skip to content
This repository has been archived by the owner on Aug 21, 2018. It is now read-only.

Commit

Permalink
Merge pull request #12 from vshaxe/ctnamed
Browse files Browse the repository at this point in the history
support named types
  • Loading branch information
nadako authored Jul 3, 2017
2 parents d83916a + 4860e2d commit 4273e06
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/syntax/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and complex_type =
| CTParent of type_hint
| CTExtend of placed_type_path list * class_field list
| CTOptional of type_hint
| CTNamed of placed_name * type_hint

and type_hint = complex_type * pos

Expand Down Expand Up @@ -311,6 +312,7 @@ let s_expr e =
| CTParent(t,_) -> "(" ^ s_complex_type tabs t ^ ")"
| CTOptional(t,_) -> "?" ^ s_complex_type tabs t
| CTExtend (tl, fl) -> "{> " ^ String.concat " >, " (List.map (s_complex_type_path tabs) tl) ^ ", " ^ String.concat ", " (List.map (s_class_field tabs) fl) ^ " }"
| CTNamed ((n,_),(t,_)) -> n ^ " : " ^ s_complex_type tabs t
and s_class_field tabs f =
match f.cff_doc with
| Some s -> "/**\n\t" ^ tabs ^ s ^ "\n**/\n"
Expand Down
1 change: 1 addition & 0 deletions src/syntax/astEmitter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ let emit_complex_type_parent ct p = CTParent ct,p
let emit_complex_type_extension paths fields p = CTExtend(paths,fields),p
let emit_complex_type_anonymous fields p = CTAnonymous fields,p
let emit_complex_type_optional ct p = CTOptional ct,p
let emit_complex_type_named n ct p = CTNamed (n,ct),p

let emit_complex_type_function ct1 ct2 p =
match fst ct2 with
Expand Down
1 change: 1 addition & 0 deletions src/syntax/basic/emitter.mli
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ module type Sig = sig
val emit_complex_type_anonymous : t_anonymous_type_fields -> pos -> t_complex_type
val emit_complex_type_optional : t_complex_type -> pos -> t_complex_type
val emit_complex_type_function : t_complex_type -> t_complex_type -> pos -> t_complex_type
val emit_complex_type_named : string t_pos -> t_complex_type -> pos -> t_complex_type

val emit_type_path_parameter_complex_type : t_complex_type -> t_type_path_parameter_kind
val emit_type_path_parameter_bracket : t_expr list -> pos -> t_type_path_parameter_kind
Expand Down
5 changes: 4 additions & 1 deletion src/syntax/grammars/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ complex_type_anonymous:
complex_type_optional:
| QUESTIONMARK; ct = complex_type; { emit_complex_type_optional ct (mk $startpos $endpos) }

complex_type_named:
| name = pos(dollar_ident); COLON; ct = complex_type { emit_complex_type_named name ct (mk $startpos $endpos) }

complex_type_path:
| tp = type_path { emit_complex_type_path tp (mk $startpos $endpos) }

Expand All @@ -358,7 +361,7 @@ complex_type_function:
}

complex_type:
| complex_type_parent | complex_type_extension | complex_type_anonymous | complex_type_optional
| complex_type_parent | complex_type_extension | complex_type_anonymous | complex_type_optional | complex_type_named
| complex_type_path | complex_type_function { $1 }

type_path_parameter_bracket:
Expand Down
4 changes: 4 additions & 0 deletions src/syntax/jsonEmitter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ module EnumApi = struct
| StructuralExtension
| AnonymousStructure
| Optional
| Named
| TypePath
| CTFunction

Expand Down Expand Up @@ -544,6 +545,9 @@ module JsonEmitter(Api : JsonApi) = struct
let emit_complex_type_optional ct p =
enum "ComplexType" Optional [tok;ct]

let emit_complex_type_named n ct p =
enum "ComplexType" Named [n;tok;ct]

let emit_complex_type_function ct1 ct2 p =
enum "ComplexType" Function [ct1;tok;ct2] (* TODO: Compose these here? *)

Expand Down
1 change: 1 addition & 0 deletions src/syntax/nullEmitter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ let emit_complex_type_parent ct p = ()
let emit_complex_type_extension paths fields p = ()
let emit_complex_type_anonymous fields p = ()
let emit_complex_type_optional ct p = ()
let emit_complex_type_named n ct p = ()

let emit_complex_type_function ct1 ct2 p = ()

Expand Down
1 change: 1 addition & 0 deletions src/syntax/symbolPrinter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ let s_xsymbol x =
| N_complex_type_extension -> "extension"
| N_complex_type_anonymous -> "anonymous"
| N_complex_type_optional -> "optional"
| N_complex_type_named -> "named"
| N_complex_type_path -> "path"
| N_complex_type_function -> "function"
| N_macro_expr_type_hint -> "macro_type_hint"
Expand Down

0 comments on commit 4273e06

Please sign in to comment.