Skip to content
This repository
tag: v1813
Fetching contributors…

Cannot retrieve contributors at this time

file 79 lines (56 sloc) 2.322 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
(*
    Copyright © 2011 MLstate

    This file is part of OPA.

    OPA is free software: you can redistribute it and/or modify it under the
    terms of the GNU Affero General Public License, version 3, as published by
    the Free Software Foundation.

    OPA is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
    more details.

    You should have received a copy of the GNU Affero General Public License
    along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
read default.trx

types:{{
open Ocaml
open Tgrammar

type pt_type =
  | PT_Record of (string * pt_type) list
  | PT_Option of pt_type option
  | PT_List of pt_type list
  | PT_Tuple of pt_type list
  | PT_Cons of (string * pt_type option)
  | PT_String of string
  | PT_Char of char
  | PT_Int of int
  | PT_Int64 of int64
  | PT_Float of float
  | PT_Bool of bool
  | PT_Unit

}}

quote <- '"'
literal <- quote (Default.stringchar* $_) quote {{ __2 }}

recel <- "(" literal "," pt ")" {{ (__2,__4) }}

recels <- recel ("," recel {{ __2 }})* {{ __1::__2 }}

record <- "{" "Record" "=" "[" recels "]" "}" {{ PT_Record __5 }}

optel <- "(" quote "Some" quote "," pt ")" {{ Some __6 }}
       / "(" quote "None" quote ")" {{ None }}

option <- "{" "Option" "=" "[" optel "]" "}" {{ PT_Option __5 }}

lstel <- "(" pt ")" {{ __2 }}

lstels <- lstel (";" lstel {{ __2 }})* {{ __1::__2 }}

list <- "{" "List" "=" "[" lstels ";"? "]" "}" {{ PT_List __5 }}

tupel <- "(" pt ")" {{ __2 }}

tupels <- tupel ("," tupel {{ __2 }})* {{ __1::__2 }}

tuple <- "{" "Tuple" "=" "[" tupels ","? "]" "}" {{ PT_Tuple __5 }}

cnsel <- "(" literal "," pt ")" {{ (__2,Some __4) }}
       / "(" literal ")" {{ (__2,None) }}

cons <- "{" "Cons" "=" "[" cnsel "]" "}" {{ PT_Cons __5 }}

string <- literal {{ PT_String __1 }}
char <- Default.charsinglequote {{ PT_Char __1 }}
integer <- Default.int {{ PT_Int __1 }}
integer64 <- Default.int64 {{ PT_Int64 __1 }}
float <- Default.float {{ PT_Float __1 }}
bool <- Default.bool {{ PT_Bool __1 }}
unit <- "()" {{ PT_Unit }}

+pt : { pt_type } <- (record / option / list / tuple / cons / string / char / float / integer / integer64 / bool / unit) {{ __1 }}
Something went wrong with that request. Please try again.