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