]> gitweb.factorcode.org Git - factor.git/blob - basis/db/postgresql/errors/errors.factor
7fa94f8055733c53c754f7344574239c5992be27
[factor.git] / basis / db / postgresql / errors / errors.factor
1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel db.errors peg.ebnf strings sequences math
4 combinators.short-circuit accessors math.parser quoting
5 locals multiline ;
6 IN: db.postgresql.errors
7
8 EBNF: parse-postgresql-sql-error [=[
9
10 Error = "ERROR:" [ ]+
11
12 TableError =
13     Error ("relation "|"table ")(!(" already exists").)+:table " already exists"
14         => [[ table >string unquote <sql-table-exists> ]]
15     | Error ("relation "|"table ")(!(" does not exist").)+:table " does not exist"
16         => [[ table >string unquote <sql-table-missing> ]]
17
18 DatabaseError =
19     Error ("database")(!(" already exists").)+:database " already exists"
20         => [[ database >string <sql-database-exists> ]]
21
22 FunctionError =
23     Error "function" (!(" already exists").)+:table " already exists"
24         => [[ table >string <sql-function-exists> ]]
25     | Error "function" (!(" does not exist").)+:table " does not exist"
26         => [[ table >string <sql-function-missing> ]]
27
28 SyntaxError =
29     Error "syntax error at end of input":error
30         => [[ error >string <sql-syntax-error> ]]
31     | Error "syntax error at or near " .+:syntaxerror
32         => [[ syntaxerror >string unquote <sql-syntax-error> ]]
33
34 UnknownError = .* => [[ >string <sql-unknown-error> ]]
35
36 PostgresqlSqlError = (TableError | DatabaseError | FunctionError | SyntaxError | UnknownError) 
37
38 ]=]
39
40
41 TUPLE: parse-postgresql-location column line text ;
42 C: <parse-postgresql-location> parse-postgresql-location
43
44 EBNF: parse-postgresql-line-error [=[
45
46 Line = "LINE " [0-9]+:line ": " .+:sql
47     => [[ f line >string string>number sql >string <parse-postgresql-location> ]] 
48
49 ]=]
50
51 :: set-caret-position ( error caret-line -- error )
52     caret-line length
53     error line>> number>string length "LINE : " length +
54     - [ error ] dip >>column ;
55
56 : postgresql-location ( line column -- obj )
57     [ parse-postgresql-line-error ] dip
58     set-caret-position ;