version 0.8.10
This commit is contained in:
parent
53cd61546d
commit
765366c1f3
58 changed files with 768 additions and 30834 deletions
|
|
@ -1,181 +0,0 @@
|
|||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2010 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
## Parses & constructs URLs.
|
||||
|
||||
|
||||
# From the spec:
|
||||
#
|
||||
# This specification uses the Augmented Backus-Naur Form (ABNF)
|
||||
# notation of [RFC2234], including the following core ABNF syntax rules
|
||||
# defined by that specification: ALPHA (letters), CR (carriage return),
|
||||
# DIGIT (decimal digits), DQUOTE (double quote), HEXDIG (hexadecimal
|
||||
# digits), LF (line feed), and SP (space).
|
||||
#
|
||||
#
|
||||
# URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
|
||||
#
|
||||
# hier-part = "//" authority path-abempty
|
||||
# / path-absolute
|
||||
# / path-rootless
|
||||
# / path-empty
|
||||
#
|
||||
# URI-reference = URI / relative-ref
|
||||
#
|
||||
# absolute-URI = scheme ":" hier-part [ "?" query ]
|
||||
#
|
||||
# relative-ref = relative-part [ "?" query ] [ "#" fragment ]
|
||||
#
|
||||
# relative-part = "//" authority path-abempty
|
||||
# / path-absolute
|
||||
# / path-noscheme
|
||||
# / path-empty
|
||||
#
|
||||
# scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
|
||||
#
|
||||
# authority = [ userinfo "@" ] host [ ":" port ]
|
||||
# userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
|
||||
# host = IP-literal / IPv4address / reg-name
|
||||
# port = *DIGIT
|
||||
#
|
||||
# IP-literal = "[" ( IPv6address / IPvFuture ) "]"
|
||||
#
|
||||
# IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
|
||||
#
|
||||
# IPv6address = 6( h16 ":" ) ls32
|
||||
# / "::" 5( h16 ":" ) ls32
|
||||
# / [ h16 ] "::" 4( h16 ":" ) ls32
|
||||
# / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
|
||||
# / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
|
||||
# / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
|
||||
# / [ *4( h16 ":" ) h16 ] "::" ls32
|
||||
# / [ *5( h16 ":" ) h16 ] "::" h16
|
||||
# / [ *6( h16 ":" ) h16 ] "::"
|
||||
#
|
||||
# h16 = 1*4HEXDIG
|
||||
# ls32 = ( h16 ":" h16 ) / IPv4address
|
||||
# IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
|
||||
#
|
||||
# dec-octet = DIGIT ; 0-9
|
||||
# / %x31-39 DIGIT ; 10-99
|
||||
# / "1" 2DIGIT ; 100-199
|
||||
# / "2" %x30-34 DIGIT ; 200-249
|
||||
# / "25" %x30-35 ; 250-255
|
||||
#
|
||||
# reg-name = *( unreserved / pct-encoded / sub-delims )
|
||||
#
|
||||
# path = path-abempty ; begins with "/" or is empty
|
||||
# / path-absolute ; begins with "/" but not "//"
|
||||
# / path-noscheme ; begins with a non-colon segment
|
||||
# / path-rootless ; begins with a segment
|
||||
# / path-empty ; zero characters
|
||||
#
|
||||
# path-abempty = *( "/" segment )
|
||||
# path-absolute = "/" [ segment-nz *( "/" segment ) ]
|
||||
# path-noscheme = segment-nz-nc *( "/" segment )
|
||||
# path-rootless = segment-nz *( "/" segment )
|
||||
# path-empty = 0<pchar>
|
||||
#
|
||||
# segment = *pchar
|
||||
# segment-nz = 1*pchar
|
||||
# segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
|
||||
# ; non-zero-length segment without any colon ":"
|
||||
#
|
||||
# pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
||||
#
|
||||
# query = *( pchar / "/" / "?" )
|
||||
#
|
||||
# fragment = *( pchar / "/" / "?" )
|
||||
#
|
||||
# pct-encoded = "%" HEXDIG HEXDIG
|
||||
#
|
||||
# unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
||||
# reserved = gen-delims / sub-delims
|
||||
# gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
|
||||
# sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
||||
# / "*" / "+" / "," / ";" / "="
|
||||
#
|
||||
|
||||
|
||||
import strutils
|
||||
|
||||
type
|
||||
TUrl* = tuple[ ## represents a *Uniform Resource Locator* (URL)
|
||||
## any optional component is "" if it does not exist
|
||||
protocol: string ## for example ``http:``
|
||||
username: string ## for example ``paul`` (optional)
|
||||
password: string ## for example ``r2d2`` (optional)
|
||||
subdomain: string ##
|
||||
domain,
|
||||
port,
|
||||
path,
|
||||
query,
|
||||
anchor: string]
|
||||
|
||||
proc host*(u: TUrl): string =
|
||||
## returns the host of the URL
|
||||
|
||||
proc parse*(url: string): TURL =
|
||||
const pattern = r"([a-zA-Z]+://)?(.+@)?(.+\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?"
|
||||
var m: array[0..7, string] #Array with the matches
|
||||
discard regexprs.match(url, pattern, m)
|
||||
|
||||
var msplit = m[2].split(':')
|
||||
|
||||
var username: string = ""
|
||||
var password: string = ""
|
||||
if m[2] != "":
|
||||
username = msplit[0]
|
||||
if msplit.len() == 2:
|
||||
password = msplit[1].replace("@", "")
|
||||
|
||||
var path: string = ""
|
||||
var query: string = ""
|
||||
var anchor: string = ""
|
||||
|
||||
if m[7] != nil:
|
||||
msplit = m[7].split('?')
|
||||
path = msplit[0]
|
||||
query = ""
|
||||
anchor = ""
|
||||
if msplit.len() == 2:
|
||||
query = "?" & msplit[1]
|
||||
|
||||
msplit = path.split('#')
|
||||
if msplit.len() == 2:
|
||||
anchor = "#" & msplit[1]
|
||||
path = msplit[0]
|
||||
msplit = query.split('#')
|
||||
if msplit.len() == 2:
|
||||
anchor = "#" & msplit[1]
|
||||
query = msplit[0]
|
||||
|
||||
result = (protocol: m[1], username: username, password: password,
|
||||
subdomain: m[3], domain: m[4] & m[5], port: m[6], path: path, query: query, anchor: anchor)
|
||||
|
||||
when isMainModule:
|
||||
proc test(r: TURL) =
|
||||
echo("protocol=" & r.protocol)
|
||||
echo("username=" & r.username)
|
||||
echo("password=" & r.password)
|
||||
echo("subdomain=" & r.subdomain)
|
||||
echo("domain=" & r.domain)
|
||||
echo("port=" & r.port)
|
||||
echo("path=" & r.path)
|
||||
echo("query=" & r.query)
|
||||
echo("anchor=" & r.anchor)
|
||||
echo("---------------")
|
||||
|
||||
var r: TUrl
|
||||
r = parse(r"http://google.co.uk/search?var=bleahdhsad")
|
||||
test(r)
|
||||
r = parse(r"http://dom96:test@google.com:80/search.php?q=562gs6&foo=6gs6&bar=7hs6#test")
|
||||
test(r)
|
||||
r = parse(r"http://www.google.co.uk/search?q=multiple+subdomains&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:pl:official&client=firefox-a")
|
||||
test(r)
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
## Regular expression support for Nimrod. Consider using the pegs module
|
||||
## instead.
|
||||
## Currently this module is implemented by providing a wrapper around the
|
||||
## This module is implemented by providing a wrapper around the
|
||||
## `PRCE (Perl-Compatible Regular Expressions) <http://www.pcre.org>`_
|
||||
## C library. This means that your application will depend on the PRCE
|
||||
## library's licence when using this module, which should not be a problem
|
||||
|
|
@ -45,8 +45,8 @@ type
|
|||
proc rawCompile(pattern: string, flags: cint): PPcre =
|
||||
var
|
||||
msg: CString
|
||||
offset: int
|
||||
com = pcreCompile(pattern, flags, addr(msg), addr(offset), nil)
|
||||
offset: cint
|
||||
com = pcre.Compile(pattern, flags, addr(msg), addr(offset), nil)
|
||||
if com == nil:
|
||||
var e: ref EInvalidRegEx
|
||||
new(e)
|
||||
|
|
@ -54,7 +54,11 @@ proc rawCompile(pattern: string, flags: cint): PPcre =
|
|||
raise e
|
||||
return com
|
||||
|
||||
proc finalizeRegEx(x: TRegEx) = dealloc(x.h)
|
||||
proc finalizeRegEx(x: TRegEx) =
|
||||
# XXX This is a hack, but PCRE does not export it's "free" function properly.
|
||||
# Sigh. The hack relies on PCRE's implementation (see ``pcre_get.c``).
|
||||
# Fortunately the implementation is unlikely to change.
|
||||
pcre.free_substring(cast[cstring](x.h))
|
||||
|
||||
proc re*(s: string, flags = {reExtended}): TRegEx =
|
||||
## Constructor of regular expressions. Note that Nimrod's
|
||||
|
|
@ -67,7 +71,7 @@ proc matchOrFind(s: string, pattern: TRegEx, matches: var openarray[string],
|
|||
start, flags: cint): cint =
|
||||
var
|
||||
rawMatches: array[0..maxSubpatterns * 3 - 1, cint]
|
||||
res = pcreExec(pattern.h, nil, s, len(s), start, flags,
|
||||
res = pcre.Exec(pattern.h, nil, s, len(s), start, flags,
|
||||
cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3)
|
||||
if res < 0'i32: return res
|
||||
for i in 1..int(res)-1:
|
||||
|
|
@ -79,7 +83,7 @@ proc matchOrFind(s: string, pattern: TRegEx, matches: var openarray[string],
|
|||
|
||||
proc matchOrFind(s: string, pattern: TRegEx, start, flags: cint): cint =
|
||||
var rawMatches: array [0..maxSubpatterns * 3 - 1, cint]
|
||||
result = pcreExec(pattern.h, nil, s, len(s), start, flags,
|
||||
result = pcre.Exec(pattern.h, nil, s, len(s), start, flags,
|
||||
cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3)
|
||||
if result >= 0'i32:
|
||||
result = rawMatches[1] - rawMatches[0]
|
||||
|
|
@ -91,24 +95,24 @@ proc match*(s: string, pattern: TRegEx, matches: var openarray[string],
|
|||
## match, nothing is written into ``matches`` and ``false`` is
|
||||
## returned.
|
||||
return matchOrFind(s, pattern, matches, start,
|
||||
PCRE_ANCHORED) == cint(s.len - start)
|
||||
pcre.ANCHORED) == cint(s.len - start)
|
||||
|
||||
proc match*(s: string, pattern: TRegEx, start = 0): bool =
|
||||
## returns ``true`` if ``s[start..]`` matches the ``pattern``.
|
||||
return matchOrFind(s, pattern, start, PCRE_ANCHORED) == cint(s.len - start)
|
||||
return matchOrFind(s, pattern, start, pcre.ANCHORED) == cint(s.len - start)
|
||||
|
||||
proc matchLen*(s: string, pattern: TRegEx, matches: var openarray[string],
|
||||
start = 0): int =
|
||||
## the same as ``match``, but it returns the length of the match,
|
||||
## if there is no match, -1 is returned. Note that a match length
|
||||
## of zero can happen.
|
||||
return matchOrFind(s, pattern, matches, start, PCRE_ANCHORED)
|
||||
return matchOrFind(s, pattern, matches, start, pcre.ANCHORED)
|
||||
|
||||
proc matchLen*(s: string, pattern: TRegEx, start = 0): int =
|
||||
## the same as ``match``, but it returns the length of the match,
|
||||
## if there is no match, -1 is returned. Note that a match length
|
||||
## of zero can happen.
|
||||
return matchOrFind(s, pattern, start, PCRE_ANCHORED)
|
||||
return matchOrFind(s, pattern, start, pcre.ANCHORED)
|
||||
|
||||
proc find*(s: string, pattern: TRegEx, matches: var openarray[string],
|
||||
start = 0): int =
|
||||
|
|
@ -117,7 +121,7 @@ proc find*(s: string, pattern: TRegEx, matches: var openarray[string],
|
|||
## is written into ``matches`` and -1 is returned.
|
||||
var
|
||||
rawMatches: array[0..maxSubpatterns * 3 - 1, cint]
|
||||
res = pcreExec(pattern.h, nil, s, len(s), start, 0'i32,
|
||||
res = pcre.Exec(pattern.h, nil, s, len(s), start, 0'i32,
|
||||
cast[ptr cint](addr(rawMatches)), maxSubpatterns * 3)
|
||||
if res < 0'i32: return res
|
||||
for i in 1..int(res)-1:
|
||||
|
|
@ -64,7 +64,7 @@ proc rawCompile(pattern: string, flags: cint): PPcre =
|
|||
var
|
||||
msg: CString
|
||||
offset: int
|
||||
com = pcreCompile(pattern, flags, addr(msg), addr(offset), nil)
|
||||
com = pcre.Compile(pattern, flags, addr(msg), addr(offset), nil)
|
||||
if com == nil:
|
||||
var e: ref EInvalidRegEx
|
||||
new(e)
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ template gcTrace(cell, state: expr): stmt =
|
|||
|
||||
# forward declarations:
|
||||
proc collectCT(gch: var TGcHeap)
|
||||
proc IsOnStack(p: pointer): bool {.noinline.}
|
||||
proc IsOnStack*(p: pointer): bool {.noinline.}
|
||||
proc forAllChildren(cell: PCell, op: TWalkOp)
|
||||
proc doOperation(p: pointer, op: TWalkOp)
|
||||
proc forAllChildrenAux(dest: Pointer, mt: PNimType, op: TWalkOp)
|
||||
|
|
@ -223,6 +223,7 @@ proc decRef(c: PCell) {.inline.} =
|
|||
if c.refcount <% rcIncrement:
|
||||
writeCell("broken cell", c)
|
||||
assert(c.refcount >=% rcIncrement)
|
||||
#if c.refcount <% rcIncrement: quit("leck mich")
|
||||
if atomicDec(c.refcount, rcIncrement) <% rcIncrement:
|
||||
rtlAddZCT(c)
|
||||
elif canBeCycleRoot(c):
|
||||
|
|
@ -523,7 +524,7 @@ when defined(sparc): # For SPARC architecture.
|
|||
var b = cast[TAddress](stackBottom)
|
||||
var a = cast[TAddress](addr(stackTop))
|
||||
var x = cast[TAddress](p)
|
||||
result = x >=% a and x <=% b
|
||||
result = a <=% x and x <=% b
|
||||
|
||||
proc markStackAndRegisters(gch: var TGcHeap) {.noinline, cdecl.} =
|
||||
when defined(sparcv9):
|
||||
|
|
@ -553,7 +554,7 @@ elif stackIncreases:
|
|||
var a = cast[TAddress](stackBottom)
|
||||
var b = cast[TAddress](addr(stackTop))
|
||||
var x = cast[TAddress](p)
|
||||
result = x >=% a and x <=% b
|
||||
result = a <=% x and x <=% b
|
||||
|
||||
var
|
||||
jmpbufSize {.importc: "sizeof(jmp_buf)", nodecl.}: int
|
||||
|
|
@ -580,7 +581,7 @@ else:
|
|||
var b = cast[TAddress](stackBottom)
|
||||
var a = cast[TAddress](addr(stackTop))
|
||||
var x = cast[TAddress](p)
|
||||
result = x >=% a and x <=% b
|
||||
result = a <=% x and x <=% b
|
||||
|
||||
proc markStackAndRegisters(gch: var TGcHeap) {.noinline, cdecl.} =
|
||||
# We use a jmp_buf buffer that is in the C stack.
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ type
|
|||
DWORD_PTR* = ptr DWORD
|
||||
pHICON* = ptr HICON
|
||||
pBool* = ptr BOOL
|
||||
STARTUPINFOW* {.final.} = object # a guess. Omission should get fixed in Windows.
|
||||
STARTUPINFOW* {.final.} = object # a guess. Omission should get fixed in Windows.
|
||||
cb*: DWORD
|
||||
lpReserved*: LPTSTR
|
||||
lpDesktop*: LPTSTR
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ type
|
|||
PWideChar* = ptr int16
|
||||
|
||||
type # WinNT.h -- Defines the 32-Bit Windows types and constants
|
||||
CHAR* = int8
|
||||
SHORT* = int16
|
||||
LONG* = int
|
||||
# UNICODE (Wide Character) types
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ when not defined(expatDll):
|
|||
expatDll = "expat.dll"
|
||||
elif defined(macosx):
|
||||
const
|
||||
expatDll = "libexpat.dynlib"
|
||||
expatDll = "libexpat.dylib"
|
||||
else:
|
||||
const
|
||||
expatDll = "libexpat.so(.1|)"
|
||||
|
|
|
|||
|
|
@ -1,259 +0,0 @@
|
|||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2009 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
{.compile: "pcre_all.c".}
|
||||
type
|
||||
Pbyte = ptr byte
|
||||
PPchar = ptr cstring
|
||||
Pint = ptr cint
|
||||
PPcre* = ptr Tpcre
|
||||
Pcallout_block* = ptr tcallout_block
|
||||
Pextra* = ptr Textra
|
||||
Tpcre {.final, pure.} = object
|
||||
# The structure for passing additional data to pcre_exec(). This is defined
|
||||
# in such as way as to be extensible.
|
||||
# Bits for which fields are set
|
||||
# Opaque data from pcre_study()
|
||||
# Maximum number of calls to match()
|
||||
# Data passed back in callouts
|
||||
# Const before type ignored
|
||||
# Pointer to character tables
|
||||
Textra*{.final, pure.} = object # The structure for passing out data via the pcre_callout_function. We use a
|
||||
# structure so that new fields can be added on the end in future versions,
|
||||
# without changing the API of the function, thereby allowing old clients to
|
||||
# work without modification.
|
||||
# Identifies version of block
|
||||
# ------------------------ Version 0 -------------------------------
|
||||
# Number compiled into pattern
|
||||
# The offset vector
|
||||
# Const before type ignored
|
||||
# The subject being matched
|
||||
# The length of the subject
|
||||
# Offset to start of this match attempt
|
||||
# Where we currently are in the subject
|
||||
# Max current capture
|
||||
# Most recently closed capture
|
||||
# Data passed in with the call
|
||||
# ------------------- Added for Version 1 --------------------------
|
||||
# Offset to next item in the pattern
|
||||
# Length of next item in the pattern
|
||||
#
|
||||
# ------------------------------------------------------------------
|
||||
flags: cint
|
||||
study_data: pointer
|
||||
match_limit: cint
|
||||
callout_data: pointer
|
||||
tables: ptr byte
|
||||
|
||||
Tcallout_block*{.final, pure.} = object
|
||||
version: cint
|
||||
callout_number: cint
|
||||
offset_vector: ptr cint
|
||||
subject: ptr char
|
||||
subject_length: cint
|
||||
start_match: cint
|
||||
current_position: cint
|
||||
capture_top: cint
|
||||
capture_last: cint
|
||||
callout_data: pointer
|
||||
pattern_position: cint
|
||||
next_item_length: cint
|
||||
|
||||
|
||||
#************************************************
|
||||
#* Perl-Compatible Regular Expressions *
|
||||
#************************************************
|
||||
#
|
||||
# Modified by Andreas Rumpf for h2pas.
|
||||
|
||||
# In its original form, this is the .in file that is transformed by
|
||||
# "configure" into pcre.h.
|
||||
#
|
||||
# Copyright (c) 1997-2005 University of Cambridge
|
||||
#
|
||||
# -----------------------------------------------------------------------------
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# * Neither the name of the University of Cambridge nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# The file pcre.h is build by "configure". Do not edit it; instead
|
||||
# make changes to pcre.in.
|
||||
|
||||
const
|
||||
PCRE_MAJOR* = 6
|
||||
PCRE_MINOR* = 3
|
||||
PCRE_DATE* = "2005/11/29"
|
||||
# Options
|
||||
PCRE_CASELESS* = 0x00000001
|
||||
PCRE_MULTILINE* = 0x00000002
|
||||
PCRE_DOTALL* = 0x00000004
|
||||
PCRE_EXTENDED* = 0x00000008
|
||||
PCRE_ANCHORED* = 0x00000010
|
||||
PCRE_DOLLAR_ENDONLY* = 0x00000020
|
||||
PCRE_EXTRA* = 0x00000040
|
||||
PCRE_NOTBOL* = 0x00000080
|
||||
PCRE_NOTEOL* = 0x00000100
|
||||
PCRE_UNGREEDY* = 0x00000200
|
||||
PCRE_NOTEMPTY* = 0x00000400
|
||||
PCRE_UTF8* = 0x00000800
|
||||
PCRE_NO_AUTO_CAPTURE* = 0x00001000
|
||||
PCRE_NO_UTF8_CHECK* = 0x00002000
|
||||
PCRE_AUTO_CALLOUT* = 0x00004000
|
||||
PCRE_PARTIAL* = 0x00008000
|
||||
PCRE_DFA_SHORTEST* = 0x00010000
|
||||
PCRE_DFA_RESTART* = 0x00020000
|
||||
PCRE_FIRSTLINE* = 0x00040000
|
||||
# Exec-time and get/set-time error codes
|
||||
PCRE_ERROR_NOMATCH* = - (1)
|
||||
PCRE_ERROR_NULL* = - (2)
|
||||
PCRE_ERROR_BADOPTION* = - (3)
|
||||
PCRE_ERROR_BADMAGIC* = - (4)
|
||||
PCRE_ERROR_UNKNOWN_NODE* = - (5)
|
||||
PCRE_ERROR_NOMEMORY* = - (6)
|
||||
PCRE_ERROR_NOSUBSTRING* = - (7)
|
||||
PCRE_ERROR_MATCHLIMIT* = - (8)
|
||||
# Never used by PCRE itself
|
||||
PCRE_ERROR_CALLOUT* = - (9)
|
||||
PCRE_ERROR_BADUTF8* = - (10)
|
||||
PCRE_ERROR_BADUTF8_OFFSET* = - (11)
|
||||
PCRE_ERROR_PARTIAL* = - (12)
|
||||
PCRE_ERROR_BADPARTIAL* = - (13)
|
||||
PCRE_ERROR_INTERNAL* = - (14)
|
||||
PCRE_ERROR_BADCOUNT* = - (15)
|
||||
PCRE_ERROR_DFA_UITEM* = - (16)
|
||||
PCRE_ERROR_DFA_UCOND* = - (17)
|
||||
PCRE_ERROR_DFA_UMLIMIT* = - (18)
|
||||
PCRE_ERROR_DFA_WSSIZE* = - (19)
|
||||
PCRE_ERROR_DFA_RECURSE* = - (20)
|
||||
# Request types for pcre_fullinfo()
|
||||
PCRE_INFO_OPTIONS* = 0
|
||||
PCRE_INFO_SIZE* = 1
|
||||
PCRE_INFO_CAPTURECOUNT* = 2
|
||||
PCRE_INFO_BACKREFMAX* = 3
|
||||
PCRE_INFO_FIRSTBYTE* = 4
|
||||
# For backwards compatibility
|
||||
PCRE_INFO_FIRSTCHAR* = 4
|
||||
PCRE_INFO_FIRSTTABLE* = 5
|
||||
PCRE_INFO_LASTLITERAL* = 6
|
||||
PCRE_INFO_NAMEENTRYSIZE* = 7
|
||||
PCRE_INFO_NAMECOUNT* = 8
|
||||
PCRE_INFO_NAMETABLE* = 9
|
||||
PCRE_INFO_STUDYSIZE* = 10
|
||||
PCRE_INFO_DEFAULT_TABLES* = 11
|
||||
# Request types for pcre_config()
|
||||
PCRE_CONFIG_UTF8* = 0
|
||||
PCRE_CONFIG_NEWLINE* = 1
|
||||
PCRE_CONFIG_LINK_SIZE* = 2
|
||||
PCRE_CONFIG_POSIX_MALLOC_THRESHOLD* = 3
|
||||
PCRE_CONFIG_MATCH_LIMIT* = 4
|
||||
PCRE_CONFIG_STACKRECURSE* = 5
|
||||
PCRE_CONFIG_UNICODE_PROPERTIES* = 6
|
||||
# Bit flags for the pcre_extra structure
|
||||
PCRE_EXTRA_STUDY_DATA* = 0x00000001
|
||||
PCRE_EXTRA_MATCH_LIMIT* = 0x00000002
|
||||
PCRE_EXTRA_CALLOUT_DATA* = 0x00000004
|
||||
PCRE_EXTRA_TABLES* = 0x00000008
|
||||
|
||||
# Exported PCRE functions
|
||||
|
||||
proc pcre_compile*(para1: cstring, para2: cint, para3: ptr cstring,
|
||||
para4: ptr int, para5: Pbyte): PPcre{.importc: "pcre_compile",
|
||||
noconv.}
|
||||
proc pcre_compile2*(para1: cstring, para2: cint, para3: Pint, para4: PPchar,
|
||||
para5: ptr int, para6: Pbyte): PPcre{.importc: "pcre_compile2",
|
||||
noconv.}
|
||||
proc pcre_config*(para1: cint, para2: pointer): cint{.importc: "pcre_config",
|
||||
noconv.}
|
||||
proc pcre_copy_named_substring*(para1: PPcre, para2: cstring, para3: Pint,
|
||||
para4: cint, para5: cstring, para6: cstring,
|
||||
para7: cint): cint{.
|
||||
importc: "pcre_copy_named_substring", noconv.}
|
||||
proc pcre_copy_substring*(para1: cstring, para2: Pint, para3: cint, para4: cint,
|
||||
para5: cstring, para6: cint): cint{.
|
||||
importc: "pcre_copy_substring", noconv.}
|
||||
proc pcre_dfa_exec*(para1: PPcre, para2: Pextra, para3: cstring, para4: cint,
|
||||
para5: cint, para6: cint, para7: Pint, para8: cint,
|
||||
para9: Pint, para10: cint): cint{.importc: "pcre_dfa_exec",
|
||||
noconv.}
|
||||
proc pcre_exec*(para1: PPcre, para2: Pextra, para3: cstring, para4: cint,
|
||||
para5: cint, para6: cint, para7: Pint, para8: cint): cint{.
|
||||
importc: "pcre_exec", noconv.}
|
||||
proc pcre_free_substring*(para1: cstring){.importc: "pcre_free_substring",
|
||||
noconv.}
|
||||
proc pcre_free_substring_list*(para1: PPchar){.
|
||||
importc: "pcre_free_substring_list", noconv.}
|
||||
proc pcre_fullinfo*(para1: PPcre, para2: Pextra, para3: cint, para4: pointer): cint{.
|
||||
importc: "pcre_fullinfo", noconv.}
|
||||
proc pcre_get_named_substring*(para1: PPcre, para2: cstring, para3: Pint,
|
||||
para4: cint, para5: cstring, para6: PPchar): cint{.
|
||||
importc: "pcre_get_named_substring", noconv.}
|
||||
proc pcre_get_stringnumber*(para1: PPcre, para2: cstring): cint{.
|
||||
importc: "pcre_get_stringnumber", noconv.}
|
||||
proc pcre_get_substring*(para1: cstring, para2: Pint, para3: cint, para4: cint,
|
||||
para5: PPchar): cint{.importc: "pcre_get_substring",
|
||||
noconv.}
|
||||
proc pcre_get_substring_list*(para1: cstring, para2: Pint, para3: cint,
|
||||
para4: ptr PPchar): cint{.
|
||||
importc: "pcre_get_substring_list", noconv.}
|
||||
proc pcre_info*(para1: PPcre, para2: Pint, para3: Pint): cint{.importc: "pcre_info",
|
||||
noconv.}
|
||||
proc pcre_maketables*(): ptr byte{.importc: "pcre_maketables", noconv.}
|
||||
proc pcre_refcount*(para1: PPcre, para2: cint): cint{.importc: "pcre_refcount",
|
||||
noconv.}
|
||||
proc pcre_study*(para1: PPcre, para2: cint, para3: ptr CString): Pextra{.
|
||||
importc: "pcre_study", noconv.}
|
||||
proc pcre_version*(): CString{.importc: "pcre_version", noconv.}
|
||||
# Indirection for store get and free functions. These can be set to
|
||||
# alternative malloc/free functions if required. Special ones are used in the
|
||||
# non-recursive case for "frames". There is also an optional callout function
|
||||
# that is triggered by the (?) regex item.
|
||||
#
|
||||
|
||||
# we use Nimrod's memory manager (but not GC!) for these functions:
|
||||
|
||||
type
|
||||
TMalloc = proc (para1: int): pointer{.noconv.}
|
||||
TFree = proc (para1: pointer){.noconv.}
|
||||
|
||||
var
|
||||
pcre_malloc{.importc: "pcre_malloc".}: TMalloc
|
||||
pcre_free{.importc: "pcre_free".}: TFree
|
||||
pcre_stack_malloc{.importc: "pcre_stack_malloc".}: TMalloc
|
||||
pcre_stack_free{.importc: "pcre_stack_free".}: TFree
|
||||
pcre_callout{.importc: "pcre_callout".}: proc (para1: Pcallout_block): cint{.
|
||||
noconv.}
|
||||
|
||||
pcre_malloc = cast[TMalloc](system.alloc)
|
||||
pcre_free = cast[TFree](system.dealloc)
|
||||
pcre_stack_malloc = cast[TMalloc](system.alloc)
|
||||
pcre_stack_free = cast[TFree](system.dealloc)
|
||||
pcre_callout = nil
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue