diff --git a/squawk-vscode/package.json b/squawk-vscode/package.json index 9544f82c..c81050a7 100644 --- a/squawk-vscode/package.json +++ b/squawk-vscode/package.json @@ -27,8 +27,7 @@ "Linters" ], "activationEvents": [ - "onLanguage:sql", - "onLanguage:postgres" + "onLanguage:sql" ], "publisher": "sbdchd", "main": "./dist/extension.js", @@ -80,24 +79,23 @@ "category": "Squawk" } ], - "languages": [ + "grammars": [ { - "id": "sql", - "extensions": [ - ".sql" - ], - "aliases": [ - "SQL", - "sql" - ], - "configuration": "./sql-language-configuration.json" - }, + "language": "postgres", + "scopeName": "source.pgsql", + "path": "./syntaxes/pgsql.tmLanguage.json" + } + ], + "languages": [ { "id": "postgres", "extensions": [ + ".sql", ".psql" ], "aliases": [ + "SQL", + "sql", "PostgreSQL", "postgres" ], diff --git a/squawk-vscode/syntaxes/LICENSE b/squawk-vscode/syntaxes/LICENSE new file mode 100644 index 00000000..4052471d --- /dev/null +++ b/squawk-vscode/syntaxes/LICENSE @@ -0,0 +1,27 @@ +Copyright © 2010-2011 by John DeSoi, Ph.D. +All rights reserved. + +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 pgEdit 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 HOLDER 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. diff --git a/squawk-vscode/syntaxes/pgsql.tmLanguage.json b/squawk-vscode/syntaxes/pgsql.tmLanguage.json new file mode 100644 index 00000000..110c075b --- /dev/null +++ b/squawk-vscode/syntaxes/pgsql.tmLanguage.json @@ -0,0 +1,265 @@ +{ + "fileTypes": ["sql", "pgsql", "psql"], + "foldingStartMarker": "\\s*\\(\\s*$", + "foldingStopMarker": "^\\s*\\)", + "name": "SQL (PostgreSQL)", + "patterns": [ + { + "include": "#comments" + }, + { + "begin": "(?i)^\\s*(create)\\s+(or\\s+replace\\s+)?(function|view)\\s+((?:(?:[\\w]+|\".+\")\\.)?(?:[\\w]+|\".+\"))", + "beginCaptures": { + "1": { + "name": "keyword.other.create.pgsql" + }, + "2": { + "name": "keyword.other.pgsql" + }, + "3": { + "name": "keyword.other.pgsql" + }, + "4": { + "name": "entity.name.function.pgsql" + } + }, + "end": ";\\s*", + "name": "meta.statement.pgsql.create", + "patterns": [ + { + "include": "#dollar_quotes" + }, + { + "include": "#comments" + }, + { + "include": "#strings" + }, + { + "include": "#keywords" + }, + { + "include": "#misc" + } + ] + }, + { + "begin": "(?i:^\\s*(create)\\s+(aggregate|collation|conversion|database|domain|event trigger|group|(?:unique\\s+)?index|language|operator class|operator|rule|schema|sequence|(?:global\\s+|local\\s+)?(?:temp\\s+|temporary\\s+|unlogged\\s+)?table|tablespace|trigger|type|user|(?:materialized\\s+)?view)\\s+)(if\\s+not\\s+exists\\s+)?((?:(?:[\\w]+|\".+\")\\.)?(?:[\\w]+|\".+\"))", + "beginCaptures": { + "1": { + "name": "keyword.other.create.pgsql" + }, + "2": { + "name": "keyword.other.pgsql" + }, + "3": { + "name": "keyword.other.pgsql" + }, + "4": { + "name": "entity.name.function.pgsql" + } + }, + "end": ";\\s*", + "name": "meta.statement.pgsql.create", + "patterns": [ + { + "include": "#dollar_quotes" + }, + { + "include": "#comments" + }, + { + "include": "#strings" + }, + { + "include": "#keywords" + }, + { + "include": "#misc" + } + ] + }, + { + "begin": "(^\\s*[a-zA-Z]+)", + "beginCaptures": { + "0": { + "name": "keyword.other.pgsql" + } + }, + "comment": "Last update (including keywords below) using postgres 9.3. See classes/Help.php for update method. Testing change below to just assume starting word is a SQL keyword.", + "end": ";\\s*", + "name": "meta.statement.pgsql", + "patterns": [ + { + "include": "#dollar_quotes" + }, + { + "include": "#comments" + }, + { + "include": "#strings" + }, + { + "include": "#keywords" + }, + { + "include": "#misc" + } + ] + }, + { + "begin": "^(\\\\[\\S]+)", + "beginCaptures": { + "0": { + "name": "meta.preprocessor.pgsql" + } + }, + "comment": "psql directives", + "end": "\\n", + "name": "meta.statement.pgsql.psql" + } + ], + "repository": { + "comments": { + "patterns": [ + { + "captures": { + "1": { + "name": "punctuation.definition.comment.pgsql" + } + }, + "match": "(--).*$\\n?", + "name": "comment.line.double-dash.pgsql" + }, + { + "begin": "/\\*", + "captures": { + "0": { + "name": "punctuation.definition.comment.pgsql" + } + }, + "end": "\\*/", + "name": "comment.block.c" + } + ] + }, + "dollar_quotes": { + "patterns": [ + { + "begin": "(\\$[\\w_0-9]*\\$)$", + "comment": "Assume multiline dollar quote is SQL; start if quote is at the end of the line.\n\t\t This could easily support other PL languages like PHP and Ruby -- see PHP heredoc as an example.", + "end": "\\1", + "name": "meta.dollar-quote.pgsql", + "patterns": [ + { + "include": "#dollar_quotes" + }, + { + "include": "#comments" + }, + { + "include": "#strings" + }, + { + "include": "#keywords" + }, + { + "include": "#misc" + } + ] + } + ] + }, + "keywords": { + "patterns": [ + { + "captures": { + "1": { + "name": "keyword.other.pgsql" + } + }, + "match": "(?xi)\\b(abort|absolute|access|action|add|admin|after|aggregate|all|also|alter|always|analyse|analyze|and|any|array|as|asc|assertion|assignment|asymmetric|at|attribute|authorization|backward|before|begin|between|bigint|binary|bit|boolean|both|by|cache|called|cascade|cascaded|case|cast|catalog|chain|char|character|characteristics|check|checkpoint|class|close|cluster|coalesce|collate|collation|column|comment|comments|commit|committed|concurrently|configuration|connection|constraint|constraints|content|continue|conversion|copy|cost|create|cross|csv|current|current_catalog|current_date|current_role|current_schema|current_time|current_timestamp|current_user|cursor|cycle|data|database|day|deallocate|dec|decimal|declare|default|defaults|deferrable|deferred|definer|delete|delimiter|delimiters|desc|dictionary|disable|discard|distinct|do|document|domain|double|drop|each|else|enable|encoding|encrypted|end|enum|escape|event|except|exclude|excluding|exclusive|execute|exists|explain|extension|external|extract|false|family|fetch|first|float|following|for|force|foreign|forward|freeze|from|full|function|functions|global|grant|granted|greatest|group|handler|having|header|hold|hour|identity|if|ilike|immediate|immutable|implicit|in|including|increment|index|indexes|inherit|inherits|initially|inline|inner|inout|input|insensitive|insert|instead|int|integer|intersect|interval|into|invoker|is|isnull|isolation|join|key|label|language|large|last|lateral|lc_collate|lc_ctype|leading|leakproof|least|left|level|like|limit|listen|load|local|localtime|localtimestamp|location|lock|mapping|match|materialized|maxvalue|minute|minvalue|mode|month|move|name|names|national|natural|nchar|next|no|none|not|nothing|notify|notnull|nowait|null|nullif|nulls|numeric|object|of|off|offset|oids|on|only|operator|option|options|or|order|out|outer|over|overlaps|overlay|owned|owner|parser|partial|partition|passing|password|placing|plans|position|preceding|precision|prepare|prepared|preserve|primary|prior|privileges|procedural|procedure|program|quote|range|read|real|reassign|recheck|recursive|ref|references|refresh|reindex|relative|release|rename|repeatable|replace|replica|reset|restart|restrict|returning|returns|revoke|right|role|rollback|row|rows|rule|savepoint|schema|scroll|search|second|security|select|sequence|sequences|serializable|server|session|session_user|set|setof|share|show|similar|simple|smallint|snapshot|some|stable|standalone|start|statement|statistics|stdin|stdout|storage|strict|strip|substring|symmetric|sysid|system|table|tables|tablespace|temp|template|temporary|text|then|time|timestamp|to|trailing|transaction|treat|trigger|trim|true|truncate|trusted|type|types|unbounded|uncommitted|unencrypted|union|unique|unknown|unlisten|unlogged|until|update|user|using|vacuum|valid|validate|validator|value|values|varchar|variadic|varying|verbose|version|view|volatile|when|where|whitespace|window|with|without|work|wrapper|write|xml|xmlattributes|xmlconcat|xmlelement|xmlexists|xmlforest|xmlparse|xmlpi|xmlroot|xmlserialize|year|yes|zone)\\b" + } + ] + }, + "misc": { + "patterns": [ + { + "match": "\\b\\d+\\b", + "name": "constant.numeric.pgsql" + }, + { + "match": "\\*", + "name": "keyword.operator.star.pgsql" + }, + { + "match": "[!<>]?=|<>|<|>", + "name": "keyword.operator.comparison.pgsql" + }, + { + "match": "-|\\+|/", + "name": "keyword.operator.math.pgsql" + }, + { + "match": "\\|\\|", + "name": "keyword.operator.concatenator.pgsql" + } + ] + }, + "string_escape": { + "match": "\\\\.", + "name": "constant.character.escape.pgsql" + }, + "strings": { + "patterns": [ + { + "captures": { + "1": { + "name": "punctuation.definition.string.begin.pgsql" + }, + "3": { + "name": "punctuation.definition.string.end.pgsql" + } + }, + "comment": "This is faster than the next begin/end rule since sub-pattern will match till end-of-line and SQL files tend to have very long lines.", + "match": "(')[^'\\\\]*(')", + "name": "string.quoted.single.pgsql" + }, + { + "begin": "'", + "beginCaptures": { + "0": { + "name": "punctuation.definition.string.begin.pgsql" + } + }, + "comment": "Need to implement escape rule with two single quotes in a row. Lots of other escaping issues with single quotes.", + "end": "'", + "endCaptures": { + "0": { + "name": "punctuation.definition.string.end.pgsql" + } + }, + "name": "string.quoted.single.pgsql", + "patterns": [ + { + "include": "#string_escape" + } + ] + }, + { + "comment": "Double quoting treated like strings, but they are really identifiers.", + "match": "(\")[^\"#]*(\")", + "name": "variable.other.pgsql" + }, + { + "begin": "(\\$[\\w_0-9]*\\$)", + "comment": "Color as a string if dollar quote did not start at the end of a line.", + "end": "\\1", + "name": "string.unquoted.dollar.pgsql" + } + ] + } + }, + "scopeName": "source.pgsql", + "uuid": "4D6B679D-111C-4529-B558-3F25487D9E27" +}