Skip to content

Commit

Permalink
Continue to functorize parser
Browse files Browse the repository at this point in the history
Summary:
The type parser is now functorized in the syntax tree it produces. 
 
 

Differential Revision: D6166849

fbshipit-source-id: 5ee6593eeed11e9477e9837fc02dfd903ae276de
  • Loading branch information
ericlippert authored and hhvm-bot committed Oct 27, 2017
1 parent 16a76f7 commit 2bae7f3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
5 changes: 4 additions & 1 deletion hphp/hack/src/parser/full_fidelity_parser.ml
Expand Up @@ -34,6 +34,9 @@ module type TypeParser_S = Full_fidelity_type_parser_type
.WithLexer(Full_fidelity_lexer.WithToken(Full_fidelity_minimal_token))
.TypeParser_S

module TypeParserSyntax =
Full_fidelity_type_parser.WithSyntax(Full_fidelity_minimal_syntax)

module rec ExpressionParser : ExpressionParser_S =
Full_fidelity_expression_parser.WithStatementAndDeclAndTypeParser
(StatementParser) (DeclParser) (TypeParser)
Expand All @@ -44,7 +47,7 @@ and DeclParser : DeclarationParser_S =
Full_fidelity_declaration_parser.WithExpressionAndStatementAndTypeParser
(ExpressionParser) (StatementParser) (TypeParser)
and TypeParser : TypeParser_S =
Full_fidelity_type_parser.WithExpressionParser(ExpressionParser)
TypeParserSyntax.WithExpressionParser(ExpressionParser)

type t = {
lexer : Lexer.t;
Expand Down
2 changes: 0 additions & 2 deletions hphp/hack/src/parser/full_fidelity_parser_helpers.ml
Expand Up @@ -729,5 +729,3 @@ end (* WithSyntax *)
module MinimalParserSyntax = WithSyntax(Full_fidelity_minimal_syntax)
module MinimalParserHelper = MinimalParserSyntax
.WithLexer(Full_fidelity_lexer.WithToken(Full_fidelity_minimal_token))
module MinimalTypeParserHelper = MinimalParserSyntax
.WithLexer(Full_fidelity_type_lexer.WithToken(Full_fidelity_minimal_token))
27 changes: 16 additions & 11 deletions hphp/hack/src/parser/full_fidelity_type_parser.ml
Expand Up @@ -8,32 +8,36 @@
*
*)

module Token = Full_fidelity_minimal_token
module WithSyntax(Syntax : Syntax_sig.Syntax_S) = struct

module Token = Syntax.Token
module SyntaxKind = Full_fidelity_syntax_kind
module TokenKind = Full_fidelity_token_kind
module SourceText = Full_fidelity_source_text
module SyntaxError = Full_fidelity_syntax_error
module SimpleParserSyntax =
Full_fidelity_simple_parser.WithSyntax(Full_fidelity_minimal_syntax)
module SimpleParserSyntax = Full_fidelity_simple_parser.WithSyntax(Syntax)
module SimpleParser = SimpleParserSyntax.WithLexer(
Full_fidelity_type_lexer.WithToken(Full_fidelity_minimal_token))
Full_fidelity_type_lexer.WithToken(Syntax.Token))

open TokenKind
open Full_fidelity_minimal_syntax
open Syntax

module WithExpressionParser (
ExpressionParser : Full_fidelity_expression_parser_type
.WithSyntax(Full_fidelity_minimal_syntax)
.WithLexer(Full_fidelity_lexer.WithToken(Full_fidelity_minimal_token))
.WithSyntax(Syntax)
.WithLexer(Full_fidelity_lexer.WithToken(Syntax.Token))
.ExpressionParser_S) :
Full_fidelity_type_parser_type
.WithSyntax(Full_fidelity_minimal_syntax)
.WithLexer(Full_fidelity_type_lexer.WithToken(Full_fidelity_minimal_token))
.WithSyntax(Syntax)
.WithLexer(Full_fidelity_type_lexer.WithToken(Syntax.Token))
.TypeParser_S = struct

module ParserHelperSyntax = Full_fidelity_parser_helpers.WithSyntax(Syntax)
module ParserHelper =
ParserHelperSyntax.WithLexer(Full_fidelity_type_lexer.WithToken(Syntax.Token))

include SimpleParser
include
Full_fidelity_parser_helpers.MinimalTypeParserHelper.WithParser(SimpleParser)
include ParserHelper.WithParser(SimpleParser)

let parse_expression parser =
let expr_parser = ExpressionParser.make
Expand Down Expand Up @@ -707,3 +711,4 @@ and parse_return_type parser =
parse_type_specifier parser

end
end (* WithSyntax *)

0 comments on commit 2bae7f3

Please sign in to comment.