Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 242 lines (199 sloc) 8.279 kB
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 types:{{
19 (**
20 Tiny shell parser for bslbrowser.
21 @author Mathieu Barbin
22 @author Mehdi Bouaziz
23 *)
24
25 (**
26 This module defines a pico set of commands for {b bslbrowser}.
27 It provides also the corresponding parser.
28 *)
29
30 (**
31 The type of the command you can use in bslbrowser.
32 *)
33 type key_command =
34 | CD
35 | LS
36 | PWD
37 | HELP
38 | FIND
39 | QUIT
40 | KTYPES
41 | KEY
42 | REGEXP_HELP
43 | QMLINIT
44
45 type toption =
46 | TYPES
47 | MODULES
48 | BYPASS
49 | LANG of string
50 | SPLIT
51 | VERBOSE
52
53 type command =
54 | BslShell of (key_command * toption list * string)
55 | Pipe of string * (key_command * toption list * string)
56
57 }}
58
59 decls:{{
60
61 (**
62 Help menu for the tiny shell commands.
63 Since the syntax is defined in the parser, it makes more sence
64 that the help menu too, so that the concrete syntax parsing and
65 the help menu are not too far from each other.
66 *)
67 val help : unit -> unit
68
69 (**
70 Help menu for
71 *)
72 val regexp : unit -> unit
73
74
75 val clash_option : toption -> string
76
77
78 }}
79
80
81 {{
82
83 (* for debug *)
84 let string_of_key = function
85 | CD -> "CD"
86 | LS -> "LS"
87 | PWD -> "PWD"
88 | HELP -> "HELP"
89 | FIND -> "FIND"
90 | QUIT -> "QUIT"
91 | KTYPES -> "KTYPES"
92 | KEY -> "KEY"
93 | REGEXP_HELP -> "REGEXP_HELP"
94 | QMLINIT -> "QMLINIT"
95
96 let string_of_toption = function
97 | TYPES -> "-TYPES"
98 | MODULES -> "-MODULES"
99 | BYPASS -> "-BYPASS"
100 | LANG s -> Printf.sprintf "-LANG:%s" s
101 | SPLIT -> "-SPLIT"
102 | VERBOSE -> "-VERBOSE"
103
104 let string_of_command = function
105 | BslShell (key, optlist, arg) -> Printf.sprintf "%s [%s] <%s>" (string_of_key key) (String.concat_map "; " string_of_toption optlist) arg
106 | 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
107
108 let clash_option o =
a9f8d34 [cleanup] Base: remove sprintf
Raja authored
109 let m = Printf.sprintf "option %s cannot be used in this context" (string_of_toption o) in
fccc685 Initial open-source release
MLstate authored
110 (* #<< dddw m; >>#; *)
111 m
112
113 let help () =
114 let p = print_endline in
115 p "Testing bsl-preprocessor :";
116 p "\t##format <name> <fmt> <sep>? : bslregister new format definition (see manual)";
117 p "\t##include <fmt> <sep>? link : bslregister include (#k : key - #n : name - #t : type)";
118 p "\t##include-type <regexp> : bslregister type definition inclusion";
119 p "\t##module <key> [\\ <name> ] : bslregister new module definition";
120 p "\t##endmodule";
121 p "\t##register key \\ impl : type : bslregister main directive";
122 p "";
123 p "bslbrowser command helper :";
124 p "\tqmlinit [-split]/[module] : plot qmlinit (from bslgenLoader)";
125 p "\tcd .. / ~ / module : navigation in modules";
126 p "\tls [-t -d -m -v] <regexp> : see contains of current location";
127 p "\tpwd : see current location";
128 p "\thelp : plot this help menu";
129 p "\ttypes [ -lang ] : see bsl types in differents format";
130 p "\tfind [-t -bypass] <regexp> : find module / or function in lib";
131 p "\tkey [-t] <regexp> : lookup in bsl keys";
132 p "\tbypass [-t] <regexp> : same as key";
133 p "\toption -t : match types, not names";
134 p "\toption -d -m : show modules only";
135 p "\tregexp : show ocaml manual of regexp";
136 p "\tcom | unix : pipe (you can use grep or cat)";
137 p "\tquit or exit : quit bslbrowser"
138
139 ;;
140
141 let regexp () =
142 let p = print_endline in
143 p "Ocaml Regexp : <http://caml.inria.fr/pub/docs/manual-ocaml/libref/Str.html>";
144 p " . : Matches any character except newline.";
145 p " * : (postfix) Matches the preceding expression zero, one or several times";
146 p " + : (postfix) Matches the preceding expression one or several times";
147 p " ? : (postfix) Matches the preceding expression once or not at all";
148 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.";
149 p " ^ : Matches at beginning of line (either at the beginning of the matched string, or just after a newline character).";
150 p " $ : Matches at end of line (either at the end of the matched string, or just before a newline character).";
151 p " \\| : (infix) Alternative between two expressions.";
152 p " \\(..\\) : Grouping and naming of the enclosed expression.";
153 p " \\1 : The text matched by the first \\(...\\) expression (\\2 for the second expression, and so on up to \\9).";
154 p " \\b : Matches word boundaries.";
155 p " \\ : Quotes special characters. The special characters are $^.*+?[].\n"
156 ;;
157
158 }}
159 space <- [ \r\t]
160 spacing <- [ \n\r\t]*
161 sspacing <- [ \n\r\t]+
162
163 stringcharspecial <-
164 [n] {{ '\n' }} / [r] {{ '\r' }} / [t] {{ '\t' }}
165 / [\'] {{ '\'' }} / [\"] {{ '\"' }} / [\\] {{ '\\' }}
166 / [0-9]+ {{ char_of_int (int_of_chars __1) }}
167 stringchar <-
168 [\\] stringcharspecial {{ __2 }}
169 / ![\\\"] .
170 string <- [\"] stringchar* [\"] {{ string_of_chars __2 }}
171
172 PIPE <- "|"
173
174 KCD <- "cd"
175 KLS <- "ls"
176 KPWD <- "pwd"
177 KHELP <- "help"
178 KKTYPES <- "types"
179 KFIND <- "find"
180 KKEY <- "key"
181 KQUIT <- "quit" / "exit"
182 KREG <- "regexp"
183 KQMLINIT <- "qmlinit"
184
185 OBYPASS <- "-bypass" {{ BYPASS }}
186 OLANG <- "-ml" {{ LANG "ml" }} / "-qml" {{ LANG "qml" }} / "-opa" {{ LANG "opa" }} / "-js" {{ LANG "js" }} / "-c" {{ LANG "c" }}
187 OTYPES <- "-t" {{ TYPES }} / "-l" {{ TYPES }}
188 OMODULES <- "-d" {{ MODULES }} / "-m" {{ MODULES }}
189 OSPLIT <- "-split" {{ SPLIT }}
190 OVERB <- "-v" {{ VERBOSE }}
191
192 unquoteregexp <- [a-zA-Z_ *+\-.<>{}0-9$?\[\]^\'/]+ $_
193 regexp <- [\"]? unquoteregexp [\"]? {{ String.trim __2 }}
194
195 Coption <- OTYPES / OBYPASS / OLANG / OMODULES / OVERB
196 CoptionSp <- Coption spacing {{ __1 }}
197 Coptions <- CoptionSp+ {{ __1 }}
198
199 Cread <-
200 / KKTYPES sspacing Coptions regexp {{ KTYPES, __3, __4 }}
201 / KKTYPES sspacing Coptions {{ KTYPES, __3, "" }}
202 / KKTYPES sspacing regexp {{ KTYPES, [], __3 }}
203 / KKTYPES {{ KTYPES, [], "" }}
204
205 #/ "##include" spacing string spacing string spacing regexp {{ INCLUDE (__3, __5, __7), [], "" }}
206 / KCD sspacing regexp {{ CD, [], __3 }}
207 / KCD {{ CD, [], "" }}
208 / KQUIT {{ QUIT, [], "" }}
209
210 / KQMLINIT sspacing OSPLIT {{ QMLINIT, [SPLIT], "" }}
211 / KQMLINIT sspacing regexp {{ QMLINIT, [], __3 }}
212 / KQMLINIT {{ QMLINIT, [], "" }}
213
214
215 / KLS sspacing Coptions regexp {{ LS, __3, __4 }}
216 / KLS sspacing Coptions {{ LS, __3, "" }}
217 / KLS sspacing regexp {{ LS, [], __3 }}
218 / KLS {{ LS, [], "" }}
219
220 / KPWD {{ PWD, [], "" }}
221 / KHELP {{ HELP, [], "" }}
222 / KREG {{ REGEXP_HELP, [], "" }}
223
224 / KFIND sspacing Coptions regexp {{ FIND, __3, __4 }}
225 / KFIND sspacing Coptions {{ FIND, __3, ""}}
226 / KFIND sspacing regexp {{ FIND, [], __3 }}
227 / KFIND {{ FIND, [], ""}}
228
229 / KKEY sspacing Coptions regexp {{ KEY, __3, __4 }}
230 / KKEY sspacing Coptions {{ KEY, __3, ""}}
231 / KKEY sspacing regexp {{ KEY, [], __3 }}
232 / KKEY {{ KEY, [], ""}}
233
234
235 +Ccom : {command} <-
236 / spacing Cread spacing PIPE spacing regexp {{ let r = Pipe (__6, __2) in
237 (* #<< dddp (string_of_command r); >>#; *)
238 r }}
239 / spacing Cread spacing {{ let r = BslShell __2 in
240 (* #<< dddp (string_of_command r); >>#; *)
241 r }}
Something went wrong with that request. Please try again.