Skip to content
This repository
tag: v1698
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 115 lines (94 sloc) 3.54 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
(*
    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/>.
*)

hexa <- [0-9A-Fa-f]
space <- [ \n\r\t]
spacing <- [ \n\r\t]
# FIXME: optimiser !eol = ![\r\n]
eol <- "\r\n" $ / [\r\n] $
eof <- !.

# FIXME: optimiser string + inverser les appellations
string <- stringnosp spacing {{ __1 }}
stringnosp <- [\"] stringchar* [\"] {{ Tgrammar.string_of_chars __2 }}
# FIXME: optimiser le code genere (= ne pas construire des expressions qui sont jetees)
stringquote <- stringnosp $_

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


# FIXME: fonctions !!!
charsinglequote <- [\'] singlequotechar_ [\'] {{ __2 }}

stringsinglequote <- [\'] stringsinglechar* [\'] $_
stringsinglechar <- "\\\\" {{ '\\' }} / "\\\'" {{ '\'' }} / "\\" stringcharspecial {{ __2 }} / ![\'] .

# FIXME: parenthèses INCLUES (et le SPACING de rparen !!)
parexpr <- lparen (parexpr $/ !rparen . $)* rparen $_
parexprexcluded <- lparen ((parexpr $/ !rparen . $)* $_) rparen {{ __2 }}
parexprnosp <- lparen (parexpr $/ !rparen . $)* [)] $_
# FIXME: parenthèses EXCLUES
accolexprcontent <- (accolexpr $ / !raccol . $)* $_
accolexpr <- laccol accolexprcontent raccol {{ __2 }}
bracketexprcontent <- (bracketexpr $ / !rbracket . $)* $_
bracketexpr <- lbracket bracketexprcontent rbracket {{ __2 }}

slash <- [/] spacing $
equal <- [=] spacing $
comma <- [,] spacing $
plus <- [+] spacing $
laccol <- [{] spacing $
raccol <- [}] spacing $
colon <- [:] spacing $
semi <- [;] spacing $
lparen <- [(] spacing $
rparen <- [)] spacing $
lbracket <- [\[] spacing $
rbracket <- [\]] spacing $
times <- [*] spacing $
bar <- [|] spacing $
bang <- [!] spacing $
question <- [?] spacing $
question_ <- [?] $
dot <- [.] spacing $
sharp <- [#] spacing $
bar <- [|] spacing $
at <- [@] spacing $
underscore <- [_] spacing $
tilde_ <- [~] $

leftarrow <- "<-" spacing $
rightarrow <- "->" spacing $

strbool <- ("true" / "false") $_
bool <- strbool {{ bool_of_string __1 }}

strint64 <- [-]? [0-9]+ $_
int64 <- strint64 {{ Int64.of_string __1 }}

strint <- [-]? [0-9]+ $_
int <- strint {{ int_of_string __1 }}

strfloat <- [-]? ([0-9]+ [.] [0-9]* / [0-9]* [.] [0-9]+) $_
float <- strfloat {{ float_of_string __1 }}

sharpcomment <- [#] (!eol .)* $
mlcomment <- mlCOMMENTSTART (!mlCOMMENTSTOP (mlcomment / . $))* mlCOMMENTSTOP $
mlCOMMENTSTART <- '(*' $
mlCOMMENTSTOP <- '*)' $

humanint <- int [kMG]?
{{ match __2 with
| Some 'k' -> __1 * 1024
| Some 'M' -> __1 * 1024 * 1024
| Some 'G' -> __1 * 1024 * 1024 * 1024 (* FIXME: overflow !!! *)
| _ -> __1
}}

int3 <- [2]([5][0-5] / [0-4][0-9]) / [0-1][0-9][0-9] / [0-9][0-9]?
str_ipaddr <- int3 [.] int3 [.] int3 [.] int3 $_
Something went wrong with that request. Please try again.