Skip to content
This repository
tag: v1309
Fetching contributors…

Cannot retrieve contributors at this time

file 241 lines (199 sloc) 8.279 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
(*
    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/>.
*)
types:{{
(**
   Tiny shell parser for bslbrowser.
   @author Mathieu Barbin
   @author Mehdi Bouaziz
*)

(**
   This module defines a pico set of commands for {b bslbrowser}.
   It provides also the corresponding parser.
*)

(**
   The type of the command you can use in bslbrowser.
*)
  type key_command =
    | CD
    | LS
    | PWD
    | HELP
    | FIND
    | QUIT
    | KTYPES
    | KEY
    | REGEXP_HELP
    | QMLINIT

   type toption =
    | TYPES
    | MODULES
    | BYPASS
    | LANG of string
    | SPLIT
    | VERBOSE

   type command =
     | BslShell of (key_command * toption list * string)
     | Pipe of string * (key_command * toption list * string)

}}

decls:{{

   (**
      Help menu for the tiny shell commands.
      Since the syntax is defined in the parser, it makes more sence
      that the help menu too, so that the concrete syntax parsing and
      the help menu are not too far from each other.
   *)
   val help : unit -> unit

   (**
      Help menu for
   *)
   val regexp : unit -> unit


   val clash_option : toption -> string


}}


{{

   (* for debug *)
   let string_of_key = function
     | CD -> "CD"
     | LS -> "LS"
     | PWD -> "PWD"
     | HELP -> "HELP"
     | FIND -> "FIND"
     | QUIT -> "QUIT"
     | KTYPES -> "KTYPES"
     | KEY -> "KEY"
     | REGEXP_HELP -> "REGEXP_HELP"
     | QMLINIT -> "QMLINIT"

   let string_of_toption = function
     | TYPES -> "-TYPES"
     | MODULES -> "-MODULES"
     | BYPASS -> "-BYPASS"
     | LANG s -> Printf.sprintf "-LANG:%s" s
     | SPLIT -> "-SPLIT"
     | VERBOSE -> "-VERBOSE"

   let string_of_command = function
     | BslShell (key, optlist, arg) -> Printf.sprintf "%s [%s] <%s>" (string_of_key key) (String.concat_map "; " string_of_toption optlist) arg
     | Pipe (p, (key, optlist, arg)) -> Printf.sprintf "%s [%s] <%s> | unix:\"%s\"" (string_of_key key) (String.concat_map "; " string_of_toption optlist) arg p

   let clash_option o =
     let m = Printf.sprintf "option %s cannot be used in this context" (string_of_toption o) in
(* #<< dddw m; >>#; *)
     m

   let help () =
     let p = print_endline in
     p "Testing bsl-preprocessor :";
     p "\t##format <name> <fmt> <sep>? : bslregister new format definition (see manual)";
     p "\t##include <fmt> <sep>? link : bslregister include (#k : key - #n : name - #t : type)";
     p "\t##include-type <regexp> : bslregister type definition inclusion";
     p "\t##module <key> [\\ <name> ] : bslregister new module definition";
     p "\t##endmodule";
     p "\t##register key \\ impl : type : bslregister main directive";
     p "";
     p "bslbrowser command helper :";
     p "\tqmlinit [-split]/[module] : plot qmlinit (from bslgenLoader)";
     p "\tcd .. / ~ / module : navigation in modules";
     p "\tls [-t -d -m -v] <regexp> : see contains of current location";
     p "\tpwd : see current location";
     p "\thelp : plot this help menu";
     p "\ttypes [ -lang ] : see bsl types in differents format";
     p "\tfind [-t -bypass] <regexp> : find module / or function in lib";
     p "\tkey [-t] <regexp> : lookup in bsl keys";
     p "\tbypass [-t] <regexp> : same as key";
     p "\toption -t : match types, not names";
     p "\toption -d -m : show modules only";
     p "\tregexp : show ocaml manual of regexp";
     p "\tcom | unix : pipe (you can use grep or cat)";
     p "\tquit or exit : quit bslbrowser"

;;

   let regexp () =
     let p = print_endline in
     p "Ocaml Regexp : <http://caml.inria.fr/pub/docs/manual-ocaml/libref/Str.html>";
     p " . : Matches any character except newline.";
     p " * : (postfix) Matches the preceding expression zero, one or several times";
     p " + : (postfix) Matches the preceding expression one or several times";
     p " ? : (postfix) Matches the preceding expression once or not at all";
     p " [..] : Character set. Ranges are denoted with -, as in [a-z]. \n\t An initial ^, as in [^0-9], complements the set. \n\t To include a ] character in a set, make it the first character of the set. \n\t To include a - character in a set, make it the first or the last character of the set.";
     p " ^ : Matches at beginning of line (either at the beginning of the matched string, or just after a newline character).";
     p " $ : Matches at end of line (either at the end of the matched string, or just before a newline character).";
     p " \\| : (infix) Alternative between two expressions.";
     p " \\(..\\) : Grouping and naming of the enclosed expression.";
     p " \\1 : The text matched by the first \\(...\\) expression (\\2 for the second expression, and so on up to \\9).";
     p " \\b : Matches word boundaries.";
     p " \\ : Quotes special characters. The special characters are $^.*+?[].\n"
;;

}}
space <- [ \r\t]
spacing <- [ \n\r\t]*
sspacing <- [ \n\r\t]+

stringcharspecial <-
          [n] {{ '\n' }} / [r] {{ '\r' }} / [t] {{ '\t' }}
        / [\'] {{ '\'' }} / [\"] {{ '\"' }} / [\\] {{ '\\' }}
        / [0-9]+ {{ char_of_int (int_of_chars __1) }}
stringchar <-
          [\\] stringcharspecial {{ __2 }}
        / ![\\\"] .
string <- [\"] stringchar* [\"] {{ string_of_chars __2 }}

PIPE <- "|"

KCD <- "cd"
KLS <- "ls"
KPWD <- "pwd"
KHELP <- "help"
KKTYPES <- "types"
KFIND <- "find"
KKEY <- "key"
KQUIT <- "quit" / "exit"
KREG <- "regexp"
KQMLINIT <- "qmlinit"

OBYPASS <- "-bypass" {{ BYPASS }}
OLANG <- "-ml" {{ LANG "ml" }} / "-qml" {{ LANG "qml" }} / "-opa" {{ LANG "opa" }} / "-js" {{ LANG "js" }} / "-c" {{ LANG "c" }}
OTYPES <- "-t" {{ TYPES }} / "-l" {{ TYPES }}
OMODULES <- "-d" {{ MODULES }} / "-m" {{ MODULES }}
OSPLIT <- "-split" {{ SPLIT }}
OVERB <- "-v" {{ VERBOSE }}

unquoteregexp <- [a-zA-Z_ *+\-.<>{}0-9$?\[\]^\'/]+ $_
regexp <- [\"]? unquoteregexp [\"]? {{ String.trim __2 }}

Coption <- OTYPES / OBYPASS / OLANG / OMODULES / OVERB
CoptionSp <- Coption spacing {{ __1 }}
Coptions <- CoptionSp+ {{ __1 }}

Cread <-
/ KKTYPES sspacing Coptions regexp {{ KTYPES, __3, __4 }}
/ KKTYPES sspacing Coptions {{ KTYPES, __3, "" }}
/ KKTYPES sspacing regexp {{ KTYPES, [], __3 }}
/ KKTYPES {{ KTYPES, [], "" }}

#/ "##include" spacing string spacing string spacing regexp {{ INCLUDE (__3, __5, __7), [], "" }}
/ KCD sspacing regexp {{ CD, [], __3 }}
/ KCD {{ CD, [], "" }}
/ KQUIT {{ QUIT, [], "" }}

/ KQMLINIT sspacing OSPLIT {{ QMLINIT, [SPLIT], "" }}
/ KQMLINIT sspacing regexp {{ QMLINIT, [], __3 }}
/ KQMLINIT {{ QMLINIT, [], "" }}


/ KLS sspacing Coptions regexp {{ LS, __3, __4 }}
/ KLS sspacing Coptions {{ LS, __3, "" }}
/ KLS sspacing regexp {{ LS, [], __3 }}
/ KLS {{ LS, [], "" }}

/ KPWD {{ PWD, [], "" }}
/ KHELP {{ HELP, [], "" }}
/ KREG {{ REGEXP_HELP, [], "" }}

/ KFIND sspacing Coptions regexp {{ FIND, __3, __4 }}
/ KFIND sspacing Coptions {{ FIND, __3, ""}}
/ KFIND sspacing regexp {{ FIND, [], __3 }}
/ KFIND {{ FIND, [], ""}}

/ KKEY sspacing Coptions regexp {{ KEY, __3, __4 }}
/ KKEY sspacing Coptions {{ KEY, __3, ""}}
/ KKEY sspacing regexp {{ KEY, [], __3 }}
/ KKEY {{ KEY, [], ""}}


+Ccom : {command} <-
/ spacing Cread spacing PIPE spacing regexp {{ let r = Pipe (__6, __2) in
(* #<< dddp (string_of_command r); >>#; *)
                                               r }}
/ spacing Cread spacing {{ let r = BslShell __2 in
(* #<< dddp (string_of_command r); >>#; *)
                           r }}
Something went wrong with that request. Please try again.