Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

242 lines (199 sloc) 8.279 kb
(*
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 }}
Jump to Line
Something went wrong with that request. Please try again.