Reviewed By: dulmarod Differential Revision: D4863095 fbshipit-source-id: c966d1dmaster
parent
a02b37a03c
commit
3c6f53c896
@ -0,0 +1,45 @@
|
||||
(*
|
||||
* Copyright (c) 2017 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*)
|
||||
|
||||
{
|
||||
open Lexing
|
||||
open Types_parser
|
||||
|
||||
exception SyntaxError of string
|
||||
|
||||
let next_line lexbuf =
|
||||
let pos = lexbuf.lex_curr_p in
|
||||
lexbuf.lex_curr_p <-
|
||||
{ pos with pos_bol = lexbuf.lex_curr_pos;
|
||||
pos_lnum = pos.pos_lnum + 1;
|
||||
pos_cnum = 1;
|
||||
}
|
||||
}
|
||||
|
||||
let comment = "//" [^'\n']*
|
||||
let whitespace = [' ' '\t']
|
||||
let id = ['a'-'z' 'A'-'Z' '_'] ['a'-'z' 'A'-'Z' '0'-'9' '_' ':']*
|
||||
let file_id = ['a'-'z' 'A'-'Z' '_' '~' '/' '.'] ['a'-'z' 'A'-'Z' '0'-'9' '_' ':' '.' '/' '-']*
|
||||
|
||||
rule token = parse
|
||||
| whitespace+ { token lexbuf }
|
||||
| whitespace*("\r")?"\n" { next_line lexbuf; token lexbuf }
|
||||
| comment { token lexbuf }
|
||||
| "char" { CHAR }
|
||||
| "char16_t" { CHAR16_T }
|
||||
| "char32_t" { CHAR32_T }
|
||||
| "wchar_t" { WCHAR_T }
|
||||
| "bool" { BOOL }
|
||||
| "short" { SHORT }
|
||||
| "int" { INT }
|
||||
| "long" { LONG }
|
||||
| "float" { FLOAT }
|
||||
| "double" { DOUBLE }
|
||||
| "void" { VOID }
|
||||
| _ { raise (SyntaxError ("Unexpected char: '" ^ (Lexing.lexeme lexbuf) ^"'")) }
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2017 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
%{
|
||||
|
||||
let dummy_ptr = { Clang_ast_t.ti_pointer = 0;
|
||||
Clang_ast_t.ti_desugared_type = None }
|
||||
|
||||
%}
|
||||
|
||||
%token CHAR
|
||||
%token CHAR16_T
|
||||
%token CHAR32_T
|
||||
%token WCHAR_T
|
||||
%token BOOL
|
||||
%token SHORT
|
||||
%token INT
|
||||
%token LONG
|
||||
%token FLOAT
|
||||
%token DOUBLE
|
||||
%token VOID
|
||||
|
||||
%start <Clang_ast_t.c_type> ctype_specifier
|
||||
%%
|
||||
|
||||
ctype_specifier:
|
||||
| simple_type_specifier { $1 }
|
||||
|
||||
simple_type_specifier:
|
||||
| CHAR { Clang_ast_t.BuiltinType(dummy_ptr, `Char_U) }
|
||||
| CHAR16_T { Clang_ast_t.BuiltinType(dummy_ptr, `Char16) }
|
||||
| CHAR32_T { Clang_ast_t.BuiltinType(dummy_ptr, `Char32) }
|
||||
| WCHAR_T { Clang_ast_t.BuiltinType(dummy_ptr, `WChar_U) }
|
||||
| BOOL { Clang_ast_t.BuiltinType(dummy_ptr, `Bool) }
|
||||
| SHORT { Clang_ast_t.BuiltinType(dummy_ptr, `Short) }
|
||||
| INT { Clang_ast_t.BuiltinType(dummy_ptr, `Int) }
|
||||
| LONG { Clang_ast_t.BuiltinType(dummy_ptr, `Long) }
|
||||
| FLOAT { Clang_ast_t.BuiltinType(dummy_ptr, `Float) }
|
||||
| DOUBLE { Clang_ast_t.BuiltinType(dummy_ptr, `Double) }
|
||||
| VOID { Clang_ast_t.BuiltinType(dummy_ptr, `Void) }
|
||||
;
|
||||
|
||||
%%
|
Loading…
Reference in new issue