diff --git a/gulpfile.js b/gulpfile.js index 5e7479b7..eb068c65 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -77,7 +77,11 @@ gulp.task('release', ['clean-release','compile'], function() { bundleOne('src/xml'), bundleOne('src/yaml'), bundleOne('src/solidity'), - bundleOne('src/sb') + bundleOne('src/sb'), + bundleOne('src/mysql'), + bundleOne('src/redshift'), + bundleOne('src/pgsql'), + bundleOne('src/redis') ) .pipe(uglify({ output: { diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts index 55879f3a..8aafcc9a 100644 --- a/src/monaco.contribution.ts +++ b/src/monaco.contribution.ts @@ -272,3 +272,31 @@ registerLanguage({ aliases: ['Small Basic', 'sb'], module: './sb' }); + +registerLanguage({ + id: 'mysql', + extensions: [], + aliases: ['MySQL', 'mysql'], + module: './mysql' +}); + +registerLanguage({ + id: 'pgsql', + extensions: [], + aliases: ['PostgreSQL', 'postgres', 'pg', 'postgre'], + module: './pgsql' +}); + +registerLanguage({ + id: 'redshift', + extensions: [], + aliases: ['Redshift', 'redshift'], + module: './redshift' +}); + +registerLanguage({ + id: 'redis', + extensions: ['.redis'], + aliases: ['redis'], + module: './redis' +}); diff --git a/src/mysql.ts b/src/mysql.ts new file mode 100644 index 00000000..c1485d24 --- /dev/null +++ b/src/mysql.ts @@ -0,0 +1,221 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration; +import ILanguage = monaco.languages.IMonarchLanguage; + +export const conf: IRichLanguageConfiguration = { + comments: { + lineComment: '--', + blockComment: ['/*', '*/'], + }, + brackets: [ + ['{', '}'], + ['[', ']'], + ['(', ')'] + ], + autoClosingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '"', close: '"' }, + { open: '\'', close: '\'' }, + ], + surroundingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '"', close: '"' }, + { open: '\'', close: '\'' }, + ] +}; + +export const language = { + defaultToken: '', + tokenPostfix: '.sql', + ignoreCase: true, + + brackets: [ + { open: '[', close: ']', token: 'delimiter.square' }, + { open: '(', close: ')', token: 'delimiter.parenthesis' } + ], + + keywords: [ + "ACCESSIBLE", "ACCOUNT", "ACTION", "ADD", "AFTER", "AGAINST", "AGGREGATE", "ALGORITHM", "ALL", "ALTER", "ALWAYS", "ANALYSE", "ANALYZE", + "AND", "ANY", "AS", "ASC", "ASCII", "ASENSITIVE", "AT", "AUTOEXTEND_SIZE", "AUTO_INCREMENT", "AVG", "AVG_ROW_LENGTH", "BACKUP", "BEFORE", + "BEGIN", "BETWEEN", "BIGINT", "BINARY", "BINLOG", "BIT", "BLOB", "BLOCK", "BOOL", "BOOLEAN", "BOTH", "BTREE", "BY", "BYTE", "CACHE", "CALL", + "CASCADE", "CASCADED", "CASE", "CATALOG_NAME", "CHAIN", "CHANGE", "CHANGED", "CHANNEL", "CHAR", "CHARACTER", "CHARSET", "CHECK", "CHECKSUM", + "CIPHER", "CLASS_ORIGIN", "CLIENT", "CLOSE", "COALESCE", "CODE", "COLLATE", "COLLATION", "COLUMN", "COLUMNS", "COLUMN_FORMAT", "COLUMN_NAME", + "COMMENT", "COMMIT", "COMMITTED", "COMPACT", "COMPLETION", "COMPRESSED", "COMPRESSION", "CONCURRENT", "CONDITION", "CONNECTION", "CONSISTENT", + "CONSTRAINT", "CONSTRAINT_CATALOG", "CONSTRAINT_NAME", "CONSTRAINT_SCHEMA", "CONTAINS", "CONTEXT", "CONTINUE", "CONVERT", "CPU", "CREATE", + "CROSS", "CUBE", "CURRENT", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_USER", "CURSOR", "CURSOR_NAME", "DATA", "DATABASE", + "DATABASES", "DATAFILE", "DATE", "DATETIME", "DAY", "DAY_HOUR", "DAY_MICROSECOND", "DAY_MINUTE", "DAY_SECOND", "DEALLOCATE", "DEC", "DECIMAL", + "DECLARE", "DEFAULT", "DEFAULT_AUTH", "DEFINER", "DELAYED", "DELAY_KEY_WRITE", "DELETE", "DESC", "DESCRIBE", "DES_KEY_FILE", "DETERMINISTIC", + "DIAGNOSTICS", "DIRECTORY", "DISABLE", "DISCARD", "DISK", "DISTINCT", "DISTINCTROW", "DIV", "DO", "DOUBLE", "DROP", "DUAL", "DUMPFILE", + "DUPLICATE", "DYNAMIC", "EACH", "ELSE", "ELSEIF", "ENABLE", "ENCLOSED", "ENCRYPTION", "END", "ENDS", "ENGINE", "ENGINES", "ENUM", "ERROR", + "ERRORS", "ESCAPE", "ESCAPED", "EVENT", "EVENTS", "EVERY", "EXCHANGE", "EXECUTE", "EXISTS", "EXIT", "EXPANSION", "EXPIRE", "EXPLAIN", "EXPORT", + "EXTENDED", "EXTENT_SIZE", "FALSE", "FAST", "FAULTS", "FETCH", "FIELDS", "FILE", "FILE_BLOCK_SIZE", "FILTER", "FIRST", "FIXED", "FLOAT", "FLOAT4", + "FLOAT8", "FLUSH", "FOLLOWS", "FOR", "FORCE", "FOREIGN", "FORMAT", "FOUND", "FROM", "FULL", "FULLTEXT", "FUNCTION", "GENERAL", "GENERATED", + "GEOMETRY", "GEOMETRYCOLLECTION", "GET", "GET_FORMAT", "GLOBAL", "GRANT", "GRANTS", "GROUP", "GROUP_REPLICATION", "HANDLER", "HASH", "HAVING", + "HELP", "HIGH_PRIORITY", "HOST", "HOSTS", "HOUR", "HOUR_MICROSECOND", "HOUR_MINUTE", "HOUR_SECOND", "IDENTIFIED", "IF", "IGNORE", "IGNORE_SERVER_IDS", + "IMPORT", "INDEX", "INDEXES", "INFILE", "INITIAL_SIZE", "INNER", "INOUT", "INSENSITIVE", "INSERT", "INSERT_METHOD", "INSTALL", "INSTANCE", + "INT", "INT1", "INT2", "INT3", "INT4", "INT8", "INTEGER", "INTERVAL", "INTO", "INVOKER", "IO", "IO_AFTER_GTIDS", "IO_BEFORE_GTIDS", "IO_THREAD", + "IPC", "ISOLATION", "ISSUER", "ITERATE", "JOIN", "JSON", "KEY", "KEYS", "KEY_BLOCK_SIZE", "KILL", "LANGUAGE", "LAST", "LEADING", "LEAVE", + "LEAVES", "LEFT", "LESS", "LEVEL", "LIKE", "LIMIT", "LINEAR", "LINES", "LINESTRING", "LIST", "LOAD", "LOCAL", "LOCALTIME", "LOCALTIMESTAMP", "LOCK", + "LOCKS", "LOGFILE", "LOGS", "LONG", "LONGBLOB", "LONGTEXT", "LOOP", "LOW_PRIORITY", "MASTER", "MASTER_AUTO_POSITION", "MASTER_BIND", "MASTER_CONNECT_RETRY", + "MASTER_DELAY", "MASTER_HEARTBEAT_PERIOD", "MASTER_HOST", "MASTER_LOG_FILE", "MASTER_LOG_POS", "MASTER_PASSWORD", "MASTER_PORT", "MASTER_RETRY_COUNT", + "MASTER_SERVER_ID", "MASTER_SSL", "MASTER_SSL_CA", "MASTER_SSL_CAPATH", "MASTER_SSL_CERT", "MASTER_SSL_CIPHER", "MASTER_SSL_CRL", "MASTER_SSL_CRLPATH", + "MASTER_SSL_KEY", "MASTER_SSL_VERIFY_SERVER_CERT", "MASTER_TLS_VERSION", "MASTER_USER", "MATCH", "MAXVALUE", "MAX_CONNECTIONS_PER_HOUR", "MAX_QUERIES_PER_HOUR", + "MAX_ROWS", "MAX_SIZE", "MAX_STATEMENT_TIME", "MAX_UPDATES_PER_HOUR", "MAX_USER_CONNECTIONS", "MEDIUM", "MEDIUMBLOB", "MEDIUMINT", "MEDIUMTEXT", "MEMORY", + "MERGE", "MESSAGE_TEXT", "MICROSECOND", "MIDDLEINT", "MIGRATE", "MINUTE", "MINUTE_MICROSECOND", "MINUTE_SECOND", "MIN_ROWS", "MOD", "MODE", "MODIFIES", + "MODIFY", "MONTH", "MULTILINESTRING", "MULTIPOINT", "MULTIPOLYGON", "MUTEX", "MYSQL_ERRNO", "NAME", "NAMES", "NATIONAL", "NATURAL", "NCHAR", "NDB", + "NDBCLUSTER", "NEVER", "NEW", "NEXT", "NO", "NODEGROUP", "NONBLOCKING", "NONE", "NO_WAIT", "NO_WRITE_TO_BINLOG", "NUMBER", "NUMERIC", + "NVARCHAR", "OFFSET", "OLD_PASSWORD", "ON", "ONE", "ONLY", "OPEN", "OPTIMIZE", "OPTIMIZER_COSTS", "OPTION", "OPTIONALLY", "OPTIONS", "OR", "ORDER", + "OUT", "OUTER", "OUTFILE", "OWNER", "PACK_KEYS", "PAGE", "PARSER", "PARSE_GCOL_EXPR", "PARTIAL", "PARTITION", "PARTITIONING", "PARTITIONS", "PASSWORD", + "PHASE", "PLUGIN", "PLUGINS", "PLUGIN_DIR", "POINT", "POLYGON", "PORT", "PRECEDES", "PRECISION", "PREPARE", "PRESERVE", "PREV", "PRIMARY", "PRIVILEGES", + "PROCEDURE", "PROCESSLIST", "PROFILE", "PROFILES", "PROXY", "PURGE", "QUARTER", "QUERY", "QUICK", "RANGE", "READ", "READS", "READ_ONLY", "READ_WRITE", + "REAL", "REBUILD", "RECOVER", "REDOFILE", "REDO_BUFFER_SIZE", "REDUNDANT", "REFERENCES", "REGEXP", "RELAY", "RELAYLOG", "RELAY_LOG_FILE", "RELAY_LOG_POS", + "RELAY_THREAD", "RELEASE", "RELOAD", "REMOVE", "RENAME", "REORGANIZE", "REPAIR", "REPEAT", "REPEATABLE", "REPLACE", "REPLICATE_DO_DB", "REPLICATE_DO_TABLE", + "REPLICATE_IGNORE_DB", "REPLICATE_IGNORE_TABLE", "REPLICATE_REWRITE_DB", "REPLICATE_WILD_DO_TABLE", "REPLICATE_WILD_IGNORE_TABLE", "REPLICATION", "REQUIRE", + "RESET", "RESIGNAL", "RESTORE", "RESTRICT", "RESUME", "RETURN", "RETURNED_SQLSTATE", "RETURNS", "REVERSE", "REVOKE", "RIGHT", "RLIKE", "ROLLBACK", "ROLLUP", + "ROTATE", "ROUTINE", "ROW", "ROWS", "ROW_COUNT", "ROW_FORMAT", "RTREE", "SAVEPOINT", "SCHEDULE", "SCHEMA", "SCHEMAS", "SCHEMA_NAME", "SECOND", "SECOND_MICROSECOND", + "SECURITY", "SELECT", "SENSITIVE", "SEPARATOR", "SERIAL", "SERIALIZABLE", "SERVER", "SESSION", "SET", "SHARE", "SHOW", "SHUTDOWN", "SIGNAL", "SIGNED", "SIMPLE", + "SLAVE", "SLOW", "SMALLINT", "SNAPSHOT", "SOCKET", "SOME", "SONAME", "SOUNDS", "SOURCE", "SPATIAL", "SPECIFIC", "SQL", "SQLEXCEPTION", "SQLSTATE", "SQLWARNING", + "SQL_AFTER_GTIDS", "SQL_AFTER_MTS_GAPS", "SQL_BEFORE_GTIDS", "SQL_BIG_RESULT", "SQL_BUFFER_RESULT", "SQL_CACHE", "SQL_CALC_FOUND_ROWS", "SQL_NO_CACHE", + "SQL_SMALL_RESULT", "SQL_THREAD", "SQL_TSI_DAY", "SQL_TSI_HOUR", "SQL_TSI_MINUTE", "SQL_TSI_MONTH", "SQL_TSI_QUARTER", "SQL_TSI_SECOND", "SQL_TSI_WEEK", + "SQL_TSI_YEAR", "SSL", "STACKED", "START", "STARTING", "STARTS", "STATS_AUTO_RECALC", "STATS_PERSISTENT", "STATS_SAMPLE_PAGES", "STATUS", "STOP", "STORAGE", + "STORED", "STRAIGHT_JOIN", "STRING", "SUBCLASS_ORIGIN", "SUBJECT", "SUBPARTITION", "SUBPARTITIONS", "SUPER", "SUSPEND", "SWAPS", "SWITCHES", "TABLE", "TABLES", + "TABLESPACE", "TABLE_CHECKSUM", "TABLE_NAME", "TEMPORARY", "TEMPTABLE", "TERMINATED", "TEXT", "THAN", "THEN", "TIME", "TIMESTAMP", "TIMESTAMPADD", "TIMESTAMPDIFF", + "TINYBLOB", "TINYINT", "TINYTEXT", "TO", "TRAILING", "TRANSACTION", "TRIGGER", "TRIGGERS", "TRUE", "TRUNCATE", "TYPE", "TYPES", "UNCOMMITTED", "UNDEFINED", "UNDO", + "UNDOFILE", "UNDO_BUFFER_SIZE", "UNICODE", "UNINSTALL", "UNION", "UNIQUE", "UNKNOWN", "UNLOCK", "UNSIGNED", "UNTIL", "UPDATE", "UPGRADE", "USAGE", "USE", "USER", + "USER_RESOURCES", "USE_FRM", "USING", "UTC_DATE", "UTC_TIME", "UTC_TIMESTAMP", "VALIDATION", "VALUE", "VALUES", "VARBINARY", "VARCHAR", "VARCHARACTER", "VARIABLES", + "VARYING", "VIEW", "VIRTUAL", "WAIT", "WARNINGS", "WEEK", "WEIGHT_STRING", "WHEN", "WHERE", "WHILE", "WITH", "WITHOUT", "WORK", "WRAPPER", "WRITE", "X509", "XA", + "XID", "XML", "XOR", "YEAR", "YEAR_MONTH", "ZEROFILL" + ], + operators: [ + "AND", "BETWEEN", "IN", "LIKE", "NOT", "OR", "IS", "NULL", "INTERSECT", "UNION", "INNER", "JOIN", "LEFT", "OUTER", "RIGHT" + ], + builtinFunctions: [ + "ABS", "ACOS", "ADDDATE", "ADDTIME", "AES_DECRYPT", "AES_ENCRYPT", "ANY_VALUE", "Area", "AsBinary", "AsWKB", "ASCII", "ASIN", + "AsText", "AsWKT", "ASYMMETRIC_DECRYPT", "ASYMMETRIC_DERIVE", "ASYMMETRIC_ENCRYPT", "ASYMMETRIC_SIGN", "ASYMMETRIC_VERIFY", + "ATAN", "ATAN2", "ATAN", "AVG", "BENCHMARK", "BIN", "BIT_AND", "BIT_COUNT", "BIT_LENGTH", "BIT_OR", "BIT_XOR", "Buffer", "CAST", + "CEIL", "CEILING", "Centroid", "CHAR", "CHAR_LENGTH", "CHARACTER_LENGTH", "CHARSET", "COALESCE", "COERCIBILITY", "COLLATION", + "COMPRESS", "CONCAT", "CONCAT_WS", "CONNECTION_ID", "Contains", "CONV", "CONVERT", "CONVERT_TZ", "ConvexHull", "COS", "COT", + "COUNT", "CRC32", "CREATE_ASYMMETRIC_PRIV_KEY", "CREATE_ASYMMETRIC_PUB_KEY", "CREATE_DH_PARAMETERS", "CREATE_DIGEST", "Crosses", + "CURDATE", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_USER", "CURTIME", "DATABASE", "DATE", "DATE_ADD", + "DATE_FORMAT", "DATE_SUB", "DATEDIFF", "DAY", "DAYNAME", "DAYOFMONTH", "DAYOFWEEK", "DAYOFYEAR", "DECODE", "DEFAULT", "DEGREES", + "DES_DECRYPT", "DES_ENCRYPT", "Dimension", "Disjoint", "Distance", "ELT", "ENCODE", "ENCRYPT", "EndPoint", "Envelope", "Equals", + "EXP", "EXPORT_SET", "ExteriorRing", "EXTRACT", "ExtractValue", "FIELD", "FIND_IN_SET", "FLOOR", "FORMAT", "FOUND_ROWS", "FROM_BASE64", + "FROM_DAYS", "FROM_UNIXTIME", "GeomCollFromText", "GeometryCollectionFromText", "GeomCollFromWKB", "GeometryCollectionFromWKB", + "GeometryCollection", "GeometryN", "GeometryType", "GeomFromText", "GeometryFromText", "GeomFromWKB", "GeometryFromWKB", "GET_FORMAT", + "GET_LOCK", "GLength", "GREATEST", "GROUP_CONCAT", "GTID_SUBSET", "GTID_SUBTRACT", "HEX", "HOUR", "IF", "IFNULL", "INET_ATON", + "INET_NTOA", "INET6_ATON", "INET6_NTOA", "INSERT", "INSTR", "InteriorRingN", "Intersects", "INTERVAL", "IS_FREE_LOCK", "IS_IPV4", + "IS_IPV4_COMPAT", "IS_IPV4_MAPPED", "IS_IPV6", "IS_USED_LOCK", "IsClosed", "IsEmpty", "ISNULL", "IsSimple", "JSON_APPEND", "JSON_ARRAY", + "JSON_ARRAY_APPEND", "JSON_ARRAY_INSERT", "JSON_CONTAINS", "JSON_CONTAINS_PATH", "JSON_DEPTH", "JSON_EXTRACT", "JSON_INSERT", "JSON_KEYS", + "JSON_LENGTH", "JSON_MERGE", "JSON_MERGE_PRESERVE", "JSON_OBJECT", "JSON_QUOTE", "JSON_REMOVE", "JSON_REPLACE", "JSON_SEARCH", "JSON_SET", + "JSON_TYPE", "JSON_UNQUOTE", "JSON_VALID", "LAST_INSERT_ID", "LCASE", "LEAST", "LEFT", "LENGTH", "LineFromText", "LineStringFromText", + "LineFromWKB", "LineStringFromWKB", "LineString", "LN", "LOAD_FILE", "LOCALTIME", "LOCALTIMESTAMP", "LOCATE", "LOG", "LOG10", "LOG2", + "LOWER", "LPAD", "LTRIM", "MAKE_SET", "MAKEDATE", "MAKETIME", "MASTER_POS_WAIT", "MAX", "MBRContains", "MBRCoveredBy", "MBRCovers", + "MBRDisjoint", "MBREqual", "MBREquals", "MBRIntersects", "MBROverlaps", "MBRTouches", "MBRWithin", "MD5", "MICROSECOND", "MID", + "MIN", "MINUTE", "MLineFromText", "MultiLineStringFromText", "MLineFromWKB", "MultiLineStringFromWKB", "MOD", "MONTH", "MONTHNAME", + "MPointFromText", "MultiPointFromText", "MPointFromWKB", "MultiPointFromWKB", "MPolyFromText", "MultiPolygonFromText", "MPolyFromWKB", + "MultiPolygonFromWKB", "MultiLineString", "MultiPoint", "MultiPolygon", "NAME_CONST", "NOT IN", "NOW", "NULLIF", "NumGeometries", + "NumInteriorRings", "NumPoints", "OCT", "OCTET_LENGTH", "OLD_PASSWORD", "ORD", "Overlaps", "PASSWORD", "PERIOD_ADD", "PERIOD_DIFF", + "PI", "Point", "PointFromText", "PointFromWKB", "PointN", "PolyFromText", "PolygonFromText", "PolyFromWKB", "PolygonFromWKB", "Polygon", + "POSITION", "POW", "POWER", "PROCEDURE ANALYSE", "QUARTER", "QUOTE", "RADIANS", "RAND", "RANDOM_BYTES", "RELEASE_ALL_LOCKS", "RELEASE_LOCK", + "REPEAT", "REPLACE", "REVERSE", "RIGHT", "ROUND", "ROW_COUNT", "RPAD", "RTRIM", "SCHEMA", "SEC_TO_TIME", "SECOND", "SESSION_USER", "SHA1", + "SHA", "SHA2", "SIGN", "SIN", "SLEEP", "SOUNDEX", "SPACE", "SQRT", "SRID", "ST_Area", "ST_AsBinary", "ST_AsWKB", "ST_AsGeoJSON", "ST_AsText", + "ST_AsWKT", "ST_Buffer", "ST_Buffer_Strategy", "ST_Centroid", "ST_Contains", "ST_ConvexHull", "ST_Crosses", "ST_Difference", "ST_Dimension", + "ST_Disjoint", "ST_Distance", "ST_Distance_Sphere", "ST_EndPoint", "ST_Envelope", "ST_Equals", "ST_ExteriorRing", "ST_GeoHash", + "ST_GeomCollFromText", "ST_GeometryCollectionFromText", "ST_GeomCollFromTxt", "ST_GeomCollFromWKB", "ST_GeometryCollectionFromWKB", + "ST_GeometryN", "ST_GeometryType", "ST_GeomFromGeoJSON", "ST_GeomFromText", "ST_GeometryFromText", "ST_GeomFromWKB", "ST_GeometryFromWKB", + "ST_InteriorRingN", "ST_Intersection", "ST_Intersects", "ST_IsClosed", "ST_IsEmpty", "ST_IsSimple", "ST_IsValid", "ST_LatFromGeoHash", + "ST_Length", "ST_LineFromText", "ST_LineStringFromText", "ST_LineFromWKB", "ST_LineStringFromWKB", "ST_LongFromGeoHash", "ST_MakeEnvelope", + "ST_MLineFromText", "ST_MultiLineStringFromText", "ST_MLineFromWKB", "ST_MultiLineStringFromWKB", "ST_MPointFromText", "ST_MultiPointFromText", + "ST_MPointFromWKB", "ST_MultiPointFromWKB", "ST_MPolyFromText", "ST_MultiPolygonFromText", "ST_MPolyFromWKB", "ST_MultiPolygonFromWKB", + "ST_NumGeometries", "ST_NumInteriorRing", "ST_NumInteriorRings", "ST_NumPoints", "ST_Overlaps", "ST_PointFromGeoHash", "ST_PointFromText", + "ST_PointFromWKB", "ST_PointN", "ST_PolyFromText", "ST_PolygonFromText", "ST_PolyFromWKB", "ST_PolygonFromWKB", "ST_Simplify", "ST_SRID", + "ST_StartPoint", "ST_SymDifference", "ST_Touches", "ST_Union", "ST_Validate", "ST_Within", "ST_X", "ST_Y", "StartPoint", "STD", "STDDEV", + "STDDEV_POP", "STDDEV_SAMP", "STR_TO_DATE", "STRCMP", "SUBDATE", "SUBSTR", "SUBSTRING", "SUBSTRING_INDEX", "SUBTIME", "SUM", "SYSDATE", + "SYSTEM_USER", "TAN", "TIME", "TIME_FORMAT", "TIME_TO_SEC", "TIMEDIFF", "TIMESTAMP", "TIMESTAMPADD", "TIMESTAMPDIFF", "TO_BASE64", "TO_DAYS", + "TO_SECONDS", "Touches", "TRIM", "TRUNCATE", "UCASE", "UNCOMPRESS", "UNCOMPRESSED_LENGTH", "UNHEX", "UNIX_TIMESTAMP", "UpdateXML", "UPPER", + "USER", "UTC_DATE", "UTC_TIME", "UTC_TIMESTAMP", "UUID", "UUID_SHORT", "VALIDATE_PASSWORD_STRENGTH", "VALUES", "VAR_POP", "VAR_SAMP", "VARIANCE", + "VERSION", "WAIT_FOR_EXECUTED_GTID_SET", "WAIT_UNTIL_SQL_THREAD_AFTER_GTIDS", "WEEK", "WEEKDAY", "WEEKOFYEAR", "WEIGHT_STRING", "Within", + "X", "Y", "YEAR", "YEARWEEK" + ], + builtinVariables: [ + // NOT SUPPORTED + ], + tokenizer: { + root: [ + { include: '@comments' }, + { include: '@whitespace' }, + { include: '@numbers' }, + { include: '@strings' }, + { include: '@complexIdentifiers' }, + { include: '@scopes' }, + [/[;,.]/, 'delimiter'], + [/[()]/, '@brackets'], + [/[\w@]+/, { + cases: { + '@keywords': 'keyword', + '@operators': 'operator', + '@builtinVariables': 'predefined', + '@builtinFunctions': 'predefined', + '@default': 'identifier' + } + }], + [/[<>=!%&+\-*/|~^]/, 'operator'], + ], + whitespace: [ + [/\s+/, 'white'] + ], + comments: [ + [/--+.*/, 'comment'], + [/#+.*/, 'comment'], + [/\/\*/, { token: 'comment.quote', next: '@comment' }] + ], + comment: [ + [/[^*/]+/, 'comment'], + // Not supporting nested comments, as nested comments seem to not be standard? + // i.e. http://stackoverflow.com/questions/728172/are-there-multiline-comment-delimiters-in-sql-that-are-vendor-agnostic + // [/\/\*/, { token: 'comment.quote', next: '@push' }], // nested comment not allowed :-( + [/\*\//, { token: 'comment.quote', next: '@pop' }], + [/./, 'comment'] + ], + numbers: [ + [/0[xX][0-9a-fA-F]*/, 'number'], + [/[$][+-]*\d*(\.\d*)?/, 'number'], + [/((\d+(\.\d*)?)|(\.\d+))([eE][\-+]?\d+)?/, 'number'] + ], + strings: [ + [/'/, { token: 'string', next: '@string' }], + [/"/, { token: 'string.double', next: '@stringDouble' }] + ], + string: [ + [/[^']+/, 'string'], + [/''/, 'string'], + [/'/, { token: 'string', next: '@pop' }], + ], + stringDouble: [ + [/[^"]+/, 'string.double'], + [/""/, 'string.double'], + [/"/, { token: 'string.double', next: '@pop' }] + ], + complexIdentifiers: [ + [/`/, { token: 'identifier.quote', next: '@quotedIdentifier' }] + ], + quotedIdentifier: [ + [/[^`]+/, 'identifier'], + [/``/, 'identifier'], + [/`/, { token: 'identifier.quote', next: '@pop' }] + ], + scopes: [ + // NOT SUPPORTED + ] + } +}; diff --git a/src/pgsql.ts b/src/pgsql.ts new file mode 100644 index 00000000..1367bbbd --- /dev/null +++ b/src/pgsql.ts @@ -0,0 +1,257 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration; +import ILanguage = monaco.languages.IMonarchLanguage; + +export const conf: IRichLanguageConfiguration = { + comments: { + lineComment: '--', + blockComment: ['/*', '*/'], + }, + brackets: [ + ['{', '}'], + ['[', ']'], + ['(', ')'] + ], + autoClosingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '"', close: '"' }, + { open: '\'', close: '\'' }, + ], + surroundingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '"', close: '"' }, + { open: '\'', close: '\'' }, + ] +}; + +export const language = { + defaultToken: '', + tokenPostfix: '.sql', + ignoreCase: true, + + brackets: [ + { open: '[', close: ']', token: 'delimiter.square' }, + { open: '(', close: ')', token: 'delimiter.parenthesis' } + ], + + keywords: [ + "A", "ABORT", "ABS", "ABSENT", "ABSOLUTE", "ACCESS", "ACCORDING", "ACTION", "ADA", "ADD", "ADMIN", "AFTER", "AGGREGATE", "ALL", + "ALLOCATE", "ALSO", "ALTER", "ALWAYS", "ANALYSE", "ANALYZE", "AND", "ANY", "ARE", "ARRAY", "ARRAY_AGG", "ARRAY_MAX_CARDINALITY", + "AS", "ASC", "ASENSITIVE", "ASSERTION", "ASSIGNMENT", "ASYMMETRIC", "AT", "ATOMIC", "ATTRIBUTE", "ATTRIBUTES", "AUTHORIZATION", + "AVG", "BACKWARD", "BASE64", "BEFORE", "BEGIN", "BEGIN_FRAME", "BEGIN_PARTITION", "BERNOULLI", "BETWEEN", "BIGINT", "BINARY", + "BIT", "BIT_LENGTH", "BLOB", "BLOCKED", "BOM", "BOOLEAN", "BOTH", "BREADTH", "BY", "C", "CACHE", "CALL", "CALLED", "CARDINALITY", + "CASCADE", "CASCADED", "CASE", "CAST", "CATALOG", "CATALOG_NAME", "CEIL", "CEILING", "CHAIN", "CHAR", "CHARACTER", + "CHARACTERISTICS", "CHARACTERS", "CHARACTER_LENGTH", "CHARACTER_SET_CATALOG", "CHARACTER_SET_NAME", "CHARACTER_SET_SCHEMA", + "CHAR_LENGTH", "CHECK", "CHECKPOINT", "CLASS", "CLASS_ORIGIN", "CLOB", "CLOSE", "CLUSTER", "COALESCE", "COBOL", "COLLATE", + "COLLATION", "COLLATION_CATALOG", "COLLATION_NAME", "COLLATION_SCHEMA", "COLLECT", "COLUMN", "COLUMNS", "COLUMN_NAME", + "COMMAND_FUNCTION", "COMMAND_FUNCTION_CODE", "COMMENT", "COMMENTS", "COMMIT", "COMMITTED", "CONCURRENTLY", "CONDITION", + "CONDITION_NUMBER", "CONFIGURATION", "CONFLICT", "CONNECT", "CONNECTION", "CONNECTION_NAME", "CONSTRAINT", "CONSTRAINTS", + "CONSTRAINT_CATALOG", "CONSTRAINT_NAME", "CONSTRAINT_SCHEMA", "CONSTRUCTOR", "CONTAINS", "CONTENT", "CONTINUE", "CONTROL", + "CONVERSION", "CONVERT", "COPY", "CORR", "CORRESPONDING", "COST", "COUNT", "COVAR_POP", "COVAR_SAMP", "CREATE", "CROSS", "CSV", + "CUBE", "CUME_DIST", "CURRENT", "CURRENT_CATALOG", "CURRENT_DATE", "CURRENT_DEFAULT_TRANSFORM_GROUP", "CURRENT_PATH", + "CURRENT_ROLE", "CURRENT_ROW", "CURRENT_SCHEMA", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_TRANSFORM_GROUP_FOR_TYPE", + "CURRENT_USER", "CURSOR", "CURSOR_NAME", "CYCLE", "DATA", "DATABASE", "DATALINK", "DATE", "DATETIME_INTERVAL_CODE", + "DATETIME_INTERVAL_PRECISION", "DAY", "DB", "DEALLOCATE", "DEC", "DECIMAL", "DECLARE", "DEFAULT", "DEFAULTS", "DEFERRABLE", + "DEFERRED", "DEFINED", "DEFINER", "DEGREE", "DELETE", "DELIMITER", "DELIMITERS", "DENSE_RANK", "DEPENDS", "DEPTH", "DEREF", + "DERIVED", "DESC", "DESCRIBE", "DESCRIPTOR", "DETERMINISTIC", "DIAGNOSTICS", "DICTIONARY", "DISABLE", "DISCARD", "DISCONNECT", + "DISPATCH", "DISTINCT", "DLNEWCOPY", "DLPREVIOUSCOPY", "DLURLCOMPLETE", "DLURLCOMPLETEONLY", "DLURLCOMPLETEWRITE", "DLURLPATH", + "DLURLPATHONLY", "DLURLPATHWRITE", "DLURLSCHEME", "DLURLSERVER", "DLVALUE", "DO", "DOCUMENT", "DOMAIN", "DOUBLE", "DROP", + "DYNAMIC", "DYNAMIC_FUNCTION", "DYNAMIC_FUNCTION_CODE", "EACH", "ELEMENT", "ELSE", "EMPTY", "ENABLE", "ENCODING", "ENCRYPTED", + "END", "END-EXEC", "END_FRAME", "END_PARTITION", "ENFORCED", "ENUM", "EQUALS", "ESCAPE", "EVENT", "EVERY", "EXCEPT", "EXCEPTION", + "EXCLUDE", "EXCLUDING", "EXCLUSIVE", "EXEC", "EXECUTE", "EXISTS", "EXP", "EXPLAIN", "EXPRESSION", "EXTENSION", "EXTERNAL", + "EXTRACT", "FALSE", "FAMILY", "FETCH", "FILE", "FILTER", "FINAL", "FIRST", "FIRST_VALUE", "FLAG", "FLOAT", "FLOOR", "FOLLOWING", + "FOR", "FORCE", "FOREIGN", "FORTRAN", "FORWARD", "FOUND", "FRAME_ROW", "FREE", "FREEZE", "FROM", "FS", "FULL", "FUNCTION", + "FUNCTIONS", "FUSION", "G", "GENERAL", "GENERATED", "GET", "GLOBAL", "GO", "GOTO", "GRANT", "GRANTED", "GREATEST", "GROUP", + "GROUPING", "GROUPS", "HANDLER", "HAVING", "HEADER", "HEX", "HIERARCHY", "HOLD", "HOUR", "ID", "IDENTITY", "IF", "IGNORE", + "ILIKE", "IMMEDIATE", "IMMEDIATELY", "IMMUTABLE", "IMPLEMENTATION", "IMPLICIT", "IMPORT", "IN", "INCLUDING", "INCREMENT", + "INDENT", "INDEX", "INDEXES", "INDICATOR", "INHERIT", "INHERITS", "INITIALLY", "INLINE", "INNER", "INOUT", "INPUT", + "INSENSITIVE", "INSERT", "INSTANCE", "INSTANTIABLE", "INSTEAD", "INT", "INTEGER", "INTEGRITY", "INTERSECT", "INTERSECTION", + "INTERVAL", "INTO", "INVOKER", "IS", "ISNULL", "ISOLATION", "JOIN", "K", "KEY", "KEY_MEMBER", "KEY_TYPE", "LABEL", "LAG", + "LANGUAGE", "LARGE", "LAST", "LAST_VALUE", "LATERAL", "LEAD", "LEADING", "LEAKPROOF", "LEAST", "LEFT", "LENGTH", "LEVEL", + "LIBRARY", "LIKE", "LIKE_REGEX", "LIMIT", "LINK", "LISTEN", "LN", "LOAD", "LOCAL", "LOCALTIME", "LOCALTIMESTAMP", "LOCATION", + "LOCATOR", "LOCK", "LOCKED", "LOGGED", "LOWER", "M", "MAP", "MAPPING", "MATCH", "MATCHED", "MATERIALIZED", "MAX", "MAXVALUE", + "MAX_CARDINALITY", "MEMBER", "MERGE", "MESSAGE_LENGTH", "MESSAGE_OCTET_LENGTH", "MESSAGE_TEXT", "METHOD", "MIN", "MINUTE", + "MINVALUE", "MOD", "MODE", "MODIFIES", "MODULE", "MONTH", "MORE", "MOVE", "MULTISET", "MUMPS", "NAME", "NAMES", "NAMESPACE", + "NATIONAL", "NATURAL", "NCHAR", "NCLOB", "NESTING", "NEW", "NEXT", "NFC", "NFD", "NFKC", "NFKD", "NIL", "NO", "NONE", + "NORMALIZE", "NORMALIZED", "NOT", "NOTHING", "NOTIFY", "NOTNULL", "NOWAIT", "NTH_VALUE", "NTILE", "NULL", "NULLABLE", "NULLIF", + "NULLS", "NUMBER", "NUMERIC", "OBJECT", "OCCURRENCES_REGEX", "OCTETS", "OCTET_LENGTH", "OF", "OFF", "OFFSET", "OIDS", "OLD", + "ON", "ONLY", "OPEN", "OPERATOR", "OPTION", "OPTIONS", "OR", "ORDER", "ORDERING", "ORDINALITY", "OTHERS", "OUT", "OUTER", + "OUTPUT", "OVER", "OVERLAPS", "OVERLAY", "OVERRIDING", "OWNED", "OWNER", "P", "PAD", "PARALLEL", "PARAMETER", "PARAMETER_MODE", + "PARAMETER_NAME", "PARAMETER_ORDINAL_POSITION", "PARAMETER_SPECIFIC_CATALOG", "PARAMETER_SPECIFIC_NAME", + "PARAMETER_SPECIFIC_SCHEMA", "PARSER", "PARTIAL", "PARTITION", "PASCAL", "PASSING", "PASSTHROUGH", "PASSWORD", "PATH", + "PERCENT", "PERCENTILE_CONT", "PERCENTILE_DISC", "PERCENT_RANK", "PERIOD", "PERMISSION", "PLACING", "PLANS", "PLI", "POLICY", + "PORTION", "POSITION", "POSITION_REGEX", "POWER", "PRECEDES", "PRECEDING", "PRECISION", "PREPARE", "PREPARED", "PRESERVE", + "PRIMARY", "PRIOR", "PRIVILEGES", "PROCEDURAL", "PROCEDURE", "PROGRAM", "PUBLIC", "QUOTE", "RANGE", "RANK", "READ", "READS", + "REAL", "REASSIGN", "RECHECK", "RECOVERY", "RECURSIVE", "REF", "REFERENCES", "REFERENCING", "REFRESH", "REGR_AVGX", "REGR_AVGY", + "REGR_COUNT", "REGR_INTERCEPT", "REGR_R2", "REGR_SLOPE", "REGR_SXX", "REGR_SXY", "REGR_SYY", "REINDEX", "RELATIVE", "RELEASE", + "RENAME", "REPEATABLE", "REPLACE", "REPLICA", "REQUIRING", "RESET", "RESPECT", "RESTART", "RESTORE", "RESTRICT", "RESULT", + "RETURN", "RETURNED_CARDINALITY", "RETURNED_LENGTH", "RETURNED_OCTET_LENGTH", "RETURNED_SQLSTATE", "RETURNING", "RETURNS", + "REVOKE", "RIGHT", "ROLE", "ROLLBACK", "ROLLUP", "ROUTINE", "ROUTINE_CATALOG", "ROUTINE_NAME", "ROUTINE_SCHEMA", "ROW", "ROWS", + "ROW_COUNT", "ROW_NUMBER", "RULE", "SAVEPOINT", "SCALE", "SCHEMA", "SCHEMA_NAME", "SCOPE", "SCOPE_CATALOG", "SCOPE_NAME", + "SCOPE_SCHEMA", "SCROLL", "SEARCH", "SECOND", "SECTION", "SECURITY", "SELECT", "SELECTIVE", "SELF", "SENSITIVE", "SEQUENCE", + "SEQUENCES", "SERIALIZABLE", "SERVER", "SERVER_NAME", "SESSION", "SESSION_USER", "SET", "SETOF", "SETS", "SHARE", "SHOW", + "SIMILAR", "SIMPLE", "SIZE", "SKIP", "SMALLINT", "SNAPSHOT", "SOME", "SOURCE", "SPACE", "SPECIFIC", "SPECIFICTYPE", + "SPECIFIC_NAME", "SQL", "SQLCODE", "SQLERROR", "SQLEXCEPTION", "SQLSTATE", "SQLWARNING", "SQRT", "STABLE", "STANDALONE", + "START", "STATE", "STATEMENT", "STATIC", "STATISTICS", "STDDEV_POP", "STDDEV_SAMP", "STDIN", "STDOUT", "STORAGE", "STRICT", + "STRIP", "STRUCTURE", "STYLE", "SUBCLASS_ORIGIN", "SUBMULTISET", "SUBSTRING", "SUBSTRING_REGEX", "SUCCEEDS", "SUM", "SYMMETRIC", + "SYSID", "SYSTEM", "SYSTEM_TIME", "SYSTEM_USER", "T", "TABLE", "TABLES", "TABLESAMPLE", "TABLESPACE", "TABLE_NAME", "TEMP", + "TEMPLATE", "TEMPORARY", "TEXT", "THEN", "TIES", "TIME", "TIMESTAMP", "TIMEZONE_HOUR", "TIMEZONE_MINUTE", "TO", "TOKEN", + "TOP_LEVEL_COUNT", "TRAILING", "TRANSACTION", "TRANSACTIONS_COMMITTED", "TRANSACTIONS_ROLLED_BACK", "TRANSACTION_ACTIVE", + "TRANSFORM", "TRANSFORMS", "TRANSLATE", "TRANSLATE_REGEX", "TRANSLATION", "TREAT", "TRIGGER", "TRIGGER_CATALOG", "TRIGGER_NAME", + "TRIGGER_SCHEMA", "TRIM", "TRIM_ARRAY", "TRUE", "TRUNCATE", "TRUSTED", "TYPE", "TYPES", "UESCAPE", "UNBOUNDED", "UNCOMMITTED", + "UNDER", "UNENCRYPTED", "UNION", "UNIQUE", "UNKNOWN", "UNLINK", "UNLISTEN", "UNLOGGED", "UNNAMED", "UNNEST", "UNTIL", "UNTYPED", + "UPDATE", "UPPER", "URI", "USAGE", "USER", "USER_DEFINED_TYPE_CATALOG", "USER_DEFINED_TYPE_CODE", "USER_DEFINED_TYPE_NAME", + "USER_DEFINED_TYPE_SCHEMA", "USING", "VACUUM", "VALID", "VALIDATE", "VALIDATOR", "VALUE", "VALUES", "VALUE_OF", "VARBINARY", + "VARCHAR", "VARIADIC", "VARYING", "VAR_POP", "VAR_SAMP", "VERBOSE", "VERSION", "VERSIONING", "VIEW", "VIEWS", "VOLATILE", + "WHEN", "WHENEVER", "WHERE", "WHITESPACE", "WIDTH_BUCKET", "WINDOW", "WITH", "WITHIN", "WITHOUT", "WORK", "WRAPPER", "WRITE", + "XML", "XMLAGG", "XMLATTRIBUTES", "XMLBINARY", "XMLCAST", "XMLCOMMENT", "XMLCONCAT", "XMLDECLARATION", "XMLDOCUMENT", + "XMLELEMENT", "XMLEXISTS", "XMLFOREST", "XMLITERATE", "XMLNAMESPACES", "XMLPARSE", "XMLPI", "XMLQUERY", "XMLROOT", "XMLSCHEMA", + "XMLSERIALIZE", "XMLTABLE", "XMLTEXT", "XMLVALIDATE", "YEAR", "YES", "ZONE" + ], + operators: [ + "AND", "BETWEEN", "IN", "LIKE", "NOT", "OR", "IS", "NULL", "INTERSECT", "UNION", "INNER", "JOIN", "LEFT", "OUTER", "RIGHT" + ], + builtinFunctions: [ + "abbrev", "abs", "acos", "acosd", "age", "any", "area", "array_agg", "array_append", "array_cat", "array_dims", "array_fill", + "array_length", "array_lower", "array_ndims", "array_position", "array_positions", "array_prepend", "array_remove", "array_replace", + "array_to_json", "array_to_string", "array_to_tsvector", "array_upper", "ascii", "asin", "asind", "atan", "atan2", "atan2d", "atand", + "avg", "bit", "bit_and", "bit_length", "bit_or", "bool_and", "bool_or", "bound_box", "box", "brin_summarize_new_values", "broadcast", + "btrim", "cardinality", "cbrt", "ceil", "ceiling", "center", "char_length", "character_length", "chr", "circle", "clock_timestamp", + "coalesce", "col_description", "concat", "concat_ws", "convert", "convert_from", "convert_to", "corr", "cos", "cosd", "cot", "cotd", + "count", "covar_pop", "covar_samp", "cume_dist", "current_catalog", "current_database", "current_date", "current_query", "current_role", + "current_schema", "current_schemas", "current_setting", "current_time", "current_timestamp", "current_user", "currval", "cursor_to_xml", + "date_part", "date_trunc", "decode", "degrees", "dense_rank", "diameter", "div", "encode", "enum_first", "enum_last", "enum_range", "every", + "exp", "extract", "family", "first_value", "floor", "format", "format_type", "generate_series", "generate_subscripts", "get_bit", "get_byte", + "get_current_ts_config", "gin_clean_pending_list", "greatest", "grouping", "has_any_column_privilege", "has_column_privilege", + "has_database_privilege", "has_foreign_data_wrapper_privilege", "has_function_privilege", "has_language_privilege", "has_schema_privilege", + "has_sequence_privilege", "has_server_privilege", "has_table_privilege", "has_tablespace_privilege", "has_type_privilege", "height", "host", + "hostmask", "inet_client_addr", "inet_client_port", "inet_merge", "inet_same_family", "inet_server_addr", "inet_server_port", "initcap", + "isclosed", "isempty", "isfinite", "isopen", "json_agg", "json_object", "json_object_agg", "json_populate_record", "json_populate_recordset", + "json_to_record", "json_to_recordset", "jsonb_agg", "jsonb_object_agg", "justify_days", "justify_hours", "justify_interval", "lag", + "last_value", "lastval", "lead", "least", "left", "length", "line", "ln", "localtime", "localtimestamp", "log", "lower", "lower_inc", + "lower_inf", "lpad", "lseg", "ltrim", "make_date", "make_interval", "make_time", "make_timestamp", "make_timestamptz", "masklen", "max", + "md5", "min", "mod", "mode", "netmask", "network", "nextval", "now", "npoints", "nth_value", "ntile", "nullif", "num_nonnulls", "num_nulls", + "numnode", "obj_description", "octet_length", "overlay", "parse_ident", "path", "pclose", "percent_rank", "percentile_cont", "percentile_disc", + "pg_advisory_lock", "pg_advisory_lock_shared", "pg_advisory_unlock", "pg_advisory_unlock_all", "pg_advisory_unlock_shared", "pg_advisory_xact_lock", + "pg_advisory_xact_lock_shared", "pg_backend_pid", "pg_backup_start_time", "pg_blocking_pids", "pg_cancel_backend", "pg_client_encoding", + "pg_collation_is_visible", "pg_column_size", "pg_conf_load_time", "pg_control_checkpoint", "pg_control_init", "pg_control_recovery", + "pg_control_system", "pg_conversion_is_visible", "pg_create_logical_replication_slot", "pg_create_physical_replication_slot", "pg_create_restore_point", + "pg_current_xlog_flush_location", "pg_current_xlog_insert_location", "pg_current_xlog_location", "pg_database_size", "pg_describe_object", + "pg_drop_replication_slot", "pg_export_snapshot", "pg_filenode_relation", "pg_function_is_visible", "pg_get_constraintdef", "pg_get_expr", + "pg_get_function_arguments", "pg_get_function_identity_arguments", "pg_get_function_result", "pg_get_functiondef", "pg_get_indexdef", "pg_get_keywords", + "pg_get_object_address", "pg_get_owned_sequence", "pg_get_ruledef", "pg_get_serial_sequence", "pg_get_triggerdef", "pg_get_userbyid", "pg_get_viewdef", + "pg_has_role", "pg_identify_object", "pg_identify_object_as_address", "pg_index_column_has_property", "pg_index_has_property", "pg_indexam_has_property", + "pg_indexes_size", "pg_is_in_backup", "pg_is_in_recovery", "pg_is_other_temp_schema", "pg_is_xlog_replay_paused", "pg_last_committed_xact", + "pg_last_xact_replay_timestamp", "pg_last_xlog_receive_location", "pg_last_xlog_replay_location", "pg_listening_channels", "pg_logical_emit_message", + "pg_logical_slot_get_binary_changes", "pg_logical_slot_get_changes", "pg_logical_slot_peek_binary_changes", "pg_logical_slot_peek_changes", "pg_ls_dir", + "pg_my_temp_schema", "pg_notification_queue_usage", "pg_opclass_is_visible", "pg_operator_is_visible", "pg_opfamily_is_visible", "pg_options_to_table", + "pg_postmaster_start_time", "pg_read_binary_file", "pg_read_file", "pg_relation_filenode", "pg_relation_filepath", "pg_relation_size", "pg_reload_conf", + "pg_replication_origin_create", "pg_replication_origin_drop", "pg_replication_origin_oid", "pg_replication_origin_progress", "pg_replication_origin_session_is_setup", + "pg_replication_origin_session_progress", "pg_replication_origin_session_reset", "pg_replication_origin_session_setup", "pg_replication_origin_xact_reset", + "pg_replication_origin_xact_setup", "pg_rotate_logfile", "pg_size_bytes", "pg_size_pretty", "pg_sleep", "pg_sleep_for", "pg_sleep_until", "pg_start_backup", + "pg_stat_file", "pg_stop_backup", "pg_switch_xlog", "pg_table_is_visible", "pg_table_size", "pg_tablespace_databases", "pg_tablespace_location", + "pg_tablespace_size", "pg_terminate_backend", "pg_total_relation_size", "pg_trigger_depth", "pg_try_advisory_lock", "pg_try_advisory_lock_shared", + "pg_try_advisory_xact_lock", "pg_try_advisory_xact_lock_shared", "pg_ts_config_is_visible", "pg_ts_dict_is_visible", "pg_ts_parser_is_visible", + "pg_ts_template_is_visible", "pg_type_is_visible", "pg_typeof", "pg_xact_commit_timestamp", "pg_xlog_location_diff", "pg_xlog_replay_pause", + "pg_xlog_replay_resume", "pg_xlogfile_name", "pg_xlogfile_name_offset", "phraseto_tsquery", "pi", "plainto_tsquery", "point", "polygon", "popen", "position", + "power", "pqserverversion", "query_to_xml", "querytree", "quote_ident", "quote_literal", "quote_nullable", "radians", "radius", "random", "range_merge", + "rank", "regexp_matches", "regexp_replace", "regexp_split_to_array", "regexp_split_to_table", "regr_avgx", "regr_avgy", "regr_count", "regr_intercept", + "regr_r2", "regr_slope", "regr_sxx", "regr_sxy", "regr_syy", "repeat", "replace", "reverse", "right", "round", "row_number", "row_security_active", + "row_to_json", "rpad", "rtrim", "scale", "session_user", "set_bit", "set_byte", "set_config", "set_masklen", "setseed", "setval", "setweight", + "shobj_description", "sign", "sin", "sind", "split_part", "sprintf", "sqrt", "statement_timestamp", "stddev", "stddev_pop", "stddev_samp", "string_agg", + "string_to_array", "strip", "strpos", "substr", "substring", "sum", "table_to_xml", "table_to_xml_and_xmlschema", "tan", "tand", "text", "timeofday", + "timezone", "to_ascii", "to_char", "to_date", "to_hex", "to_json", "to_number", "to_regclass", "to_regnamespace", "to_regoper", "to_regoperator", "to_regproc", + "to_regprocedure", "to_regrole", "to_regtype", "to_timestamp", "to_tsquery", "to_tsvector", "transaction_timestamp", "translate", "trim", "trunc", "ts_debug", + "ts_delete", "ts_filter", "ts_headline", "ts_lexize", "ts_parse", "ts_rank", "ts_rank_cd", "ts_rewrite", "ts_stat", "ts_token_type", "tsquery_phrase", + "tsvector_to_array", "tsvector_update_trigger", "tsvector_update_trigger_column", "txid_current", "txid_current_snapshot", "txid_snapshot_xip", "txid_snapshot_xmax", + "txid_snapshot_xmin", "txid_visible_in_snapshot", "unnest", "upper", "upper_inc", "upper_inf", "user", "var_pop", "var_samp", "variance", "version", "width", + "width_bucket", "xml_is_well_formed", "xml_is_well_formed_content", "xml_is_well_formed_document", "xmlagg", "xmlcomment", "xmlconcat", "xmlelement", "xmlexists", + "xmlforest", "xmlparse", "xmlpi", "xmlroot", "xmlserialize", "xpath", "xpath_exists" + ], + builtinVariables: [ + // NOT SUPPORTED + ], + pseudoColumns: [ + // NOT SUPPORTED + ], + tokenizer: { + root: [ + { include: '@comments' }, + { include: '@whitespace' }, + { include: '@pseudoColumns' }, + { include: '@numbers' }, + { include: '@strings' }, + { include: '@complexIdentifiers' }, + { include: '@scopes' }, + [/[;,.]/, 'delimiter'], + [/[()]/, '@brackets'], + [/[\w@#$]+/, { + cases: { + '@keywords': 'keyword', + '@operators': 'operator', + '@builtinVariables': 'predefined', + '@builtinFunctions': 'predefined', + '@default': 'identifier' + } + }], + [/[<>=!%&+\-*/|~^]/, 'operator'], + ], + whitespace: [ + [/\s+/, 'white'] + ], + comments: [ + [/--+.*/, 'comment'], + [/\/\*/, { token: 'comment.quote', next: '@comment' }] + ], + comment: [ + [/[^*/]+/, 'comment'], + // Not supporting nested comments, as nested comments seem to not be standard? + // i.e. http://stackoverflow.com/questions/728172/are-there-multiline-comment-delimiters-in-sql-that-are-vendor-agnostic + // [/\/\*/, { token: 'comment.quote', next: '@push' }], // nested comment not allowed :-( + [/\*\//, { token: 'comment.quote', next: '@pop' }], + [/./, 'comment'] + ], + pseudoColumns: [ + [/[$][A-Za-z_][\w@#$]*/, { + cases: { + '@pseudoColumns': 'predefined', + '@default': 'identifier' + } + }], + ], + numbers: [ + [/0[xX][0-9a-fA-F]*/, 'number'], + [/[$][+-]*\d*(\.\d*)?/, 'number'], + [/((\d+(\.\d*)?)|(\.\d+))([eE][\-+]?\d+)?/, 'number'] + ], + strings: [ + [/'/, { token: 'string', next: '@string' }], + ], + string: [ + [/[^']+/, 'string'], + [/''/, 'string'], + [/'/, { token: 'string', next: '@pop' }] + ], + complexIdentifiers: [ + [/"/, { token: 'identifier.quote', next: '@quotedIdentifier' }] + ], + quotedIdentifier: [ + [/[^"]+/, 'identifier'], + [/""/, 'identifier'], + [/"/, { token: 'identifier.quote', next: '@pop' }] + ], + scopes: [ + // NOT SUPPORTED + ] + } +}; diff --git a/src/redis.ts b/src/redis.ts new file mode 100644 index 00000000..be33b8c8 --- /dev/null +++ b/src/redis.ts @@ -0,0 +1,129 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration; +import ILanguage = monaco.languages.IMonarchLanguage; + +export const conf: IRichLanguageConfiguration = { + brackets: [ + ['{', '}'], + ['[', ']'], + ['(', ')'] + ], + autoClosingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '"', close: '"' }, + { open: '\'', close: '\'' }, + ], + surroundingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '"', close: '"' }, + { open: '\'', close: '\'' }, + ] +}; + +export const language = { + defaultToken: '', + tokenPostfix: '.redis', + ignoreCase: true, + + brackets: [ + { open: '[', close: ']', token: 'delimiter.square' }, + { open: '(', close: ')', token: 'delimiter.parenthesis' } + ], + + keywords: [ + "APPEND", "AUTH", "BGREWRITEAOF", "BGSAVE", "BITCOUNT", "BITFIELD", "BITOP", "BITPOS", "BLPOP", "BRPOP", "BRPOPLPUSH", + "CLIENT", "KILL", "LIST", "GETNAME", "PAUSE", "REPLY", "SETNAME", "CLUSTER", "ADDSLOTS", "COUNT-FAILURE-REPORTS", + "COUNTKEYSINSLOT", "DELSLOTS", "FAILOVER", "FORGET", "GETKEYSINSLOT", "INFO", "KEYSLOT", "MEET", "NODES", "REPLICATE", + "RESET", "SAVECONFIG", "SET-CONFIG-EPOCH", "SETSLOT", "SLAVES", "SLOTS", "COMMAND", "COUNT", "GETKEYS", "CONFIG", "GET", + "REWRITE", "SET", "RESETSTAT", "DBSIZE", "DEBUG", "OBJECT", "SEGFAULT", "DECR", "DECRBY", "DEL", "DISCARD", "DUMP", "ECHO", + "EVAL", "EVALSHA", "EXEC", "EXISTS", "EXPIRE", "EXPIREAT", "FLUSHALL", "FLUSHDB", "GEOADD", "GEOHASH", "GEOPOS", "GEODIST", + "GEORADIUS", "GEORADIUSBYMEMBER", "GETBIT", "GETRANGE", "GETSET", "HDEL", "HEXISTS", "HGET", "HGETALL", "HINCRBY", "HINCRBYFLOAT", + "HKEYS", "HLEN", "HMGET", "HMSET", "HSET", "HSETNX", "HSTRLEN", "HVALS", "INCR", "INCRBY", "INCRBYFLOAT", "KEYS", "LASTSAVE", + "LINDEX", "LINSERT", "LLEN", "LPOP", "LPUSH", "LPUSHX", "LRANGE", "LREM", "LSET", "LTRIM", "MGET", "MIGRATE", "MONITOR", + "MOVE", "MSET", "MSETNX", "MULTI", "PERSIST", "PEXPIRE", "PEXPIREAT", "PFADD", "PFCOUNT", "PFMERGE", "PING", "PSETEX", + "PSUBSCRIBE", "PUBSUB", "PTTL", "PUBLISH", "PUNSUBSCRIBE", "QUIT", "RANDOMKEY", "READONLY", "READWRITE", "RENAME", "RENAMENX", + "RESTORE", "ROLE", "RPOP", "RPOPLPUSH", "RPUSH", "RPUSHX", "SADD", "SAVE", "SCARD", "SCRIPT", "FLUSH", "LOAD", "SDIFF", + "SDIFFSTORE", "SELECT", "SETBIT", "SETEX", "SETNX", "SETRANGE", "SHUTDOWN", "SINTER", "SINTERSTORE", "SISMEMBER", "SLAVEOF", + "SLOWLOG", "SMEMBERS", "SMOVE", "SORT", "SPOP", "SRANDMEMBER", "SREM", "STRLEN", "SUBSCRIBE", "SUNION", "SUNIONSTORE", "SWAPDB", + "SYNC", "TIME", "TOUCH", "TTL", "TYPE", "UNSUBSCRIBE", "UNLINK", "UNWATCH", "WAIT", "WATCH", "ZADD", "ZCARD", "ZCOUNT", "ZINCRBY", + "ZINTERSTORE", "ZLEXCOUNT", "ZRANGE", "ZRANGEBYLEX", "ZREVRANGEBYLEX", "ZRANGEBYSCORE", "ZRANK", "ZREM", "ZREMRANGEBYLEX", + "ZREMRANGEBYRANK", "ZREMRANGEBYSCORE", "ZREVRANGE", "ZREVRANGEBYSCORE", "ZREVRANK", "ZSCORE", "ZUNIONSTORE", "SCAN", "SSCAN", + "HSCAN", "ZSCAN" + ], + operators: [ + // NOT SUPPORTED + ], + builtinFunctions: [ + // NOT SUPPORTED + ], + builtinVariables: [ + // NOT SUPPORTED + ], + pseudoColumns: [ + // NOT SUPPORTED + ], + tokenizer: { + root: [ + { include: '@whitespace' }, + { include: '@pseudoColumns' }, + { include: '@numbers' }, + { include: '@strings' }, + { include: '@scopes' }, + [/[;,.]/, 'delimiter'], + [/[()]/, '@brackets'], + [/[\w@#$]+/, { + cases: { + '@keywords': 'keyword', + '@operators': 'operator', + '@builtinVariables': 'predefined', + '@builtinFunctions': 'predefined', + '@default': 'identifier' + } + }], + [/[<>=!%&+\-*/|~^]/, 'operator'], + ], + whitespace: [ + [/\s+/, 'white'] + ], + pseudoColumns: [ + [/[$][A-Za-z_][\w@#$]*/, { + cases: { + '@pseudoColumns': 'predefined', + '@default': 'identifier' + } + }], + ], + numbers: [ + [/0[xX][0-9a-fA-F]*/, 'number'], + [/[$][+-]*\d*(\.\d*)?/, 'number'], + [/((\d+(\.\d*)?)|(\.\d+))([eE][\-+]?\d+)?/, 'number'] + ], + strings: [ + [/'/, { token: 'string', next: '@string' }], + [/"/, { token: 'string.double', next: '@stringDouble' }] + ], + string: [ + [/[^']+/, 'string'], + [/''/, 'string'], + [/'/, { token: 'string', next: '@pop' }], + ], + stringDouble: [ + [/[^"]+/, 'string.double'], + [/""/, 'string.double'], + [/"/, { token: 'string.double', next: '@pop' }] + ], + scopes: [ + // NOT SUPPORTED + ] + } +}; diff --git a/src/redshift.ts b/src/redshift.ts new file mode 100644 index 00000000..9fb3dc98 --- /dev/null +++ b/src/redshift.ts @@ -0,0 +1,214 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration; +import ILanguage = monaco.languages.IMonarchLanguage; + +export const conf: IRichLanguageConfiguration = { + comments: { + lineComment: '--', + blockComment: ['/*', '*/'], + }, + brackets: [ + ['{', '}'], + ['[', ']'], + ['(', ')'] + ], + autoClosingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '"', close: '"' }, + { open: '\'', close: '\'' }, + ], + surroundingPairs: [ + { open: '{', close: '}' }, + { open: '[', close: ']' }, + { open: '(', close: ')' }, + { open: '"', close: '"' }, + { open: '\'', close: '\'' }, + ] +}; + +export const language = { + defaultToken: '', + tokenPostfix: '.sql', + ignoreCase: true, + + brackets: [ + { open: '[', close: ']', token: 'delimiter.square' }, + { open: '(', close: ')', token: 'delimiter.parenthesis' } + ], + keywords: [ + "AES128", "AES256", "ALL", "ALLOWOVERWRITE", "ANALYSE", "ANALYZE", "AND", "ANY", "ARRAY", "AS", "ASC", "AUTHORIZATION", + "BACKUP", "BETWEEN", "BINARY", "BLANKSASNULL", "BOTH", "BYTEDICT", "BZIP2", "CASE", "CAST", "CHECK", "COLLATE", "COLUMN", + "CONSTRAINT", "CREATE", "CREDENTIALS", "CROSS", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "CURRENT_USER", + "CURRENT_USER_ID", "DEFAULT", "DEFERRABLE", "DEFLATE", "DEFRAG", "DELTA", "DELTA32K", "DESC", "DISABLE", "DISTINCT", "DO", + "ELSE", "EMPTYASNULL", "ENABLE", "ENCODE", "ENCRYPT", "ENCRYPTION", "END", "EXCEPT", "EXPLICIT", "FALSE", "FOR", "FOREIGN", + "FREEZE", "FROM", "FULL", "GLOBALDICT256", "GLOBALDICT64K", "GRANT", "GROUP", "GZIP", "HAVING", "IDENTITY", "IGNORE", "ILIKE", + "IN", "INITIALLY", "INNER", "INTERSECT", "INTO", "IS", "ISNULL", "JOIN", "LEADING", "LEFT", "LIKE", "LIMIT", "LOCALTIME", + "LOCALTIMESTAMP", "LUN", "LUNS", "LZO", "LZOP", "MINUS", "MOSTLY13", "MOSTLY32", "MOSTLY8", "NATURAL", "NEW", "NOT", "NOTNULL", + "NULL", "NULLS", "OFF", "OFFLINE", "OFFSET", "OID", "OLD", "ON", "ONLY", "OPEN", "OR", "ORDER", "OUTER", "OVERLAPS", "PARALLEL", + "PARTITION", "PERCENT", "PERMISSIONS", "PLACING", "PRIMARY", "RAW", "READRATIO", "RECOVER", "REFERENCES", "RESPECT", "REJECTLOG", + "RESORT", "RESTORE", "RIGHT", "SELECT", "SESSION_USER", "SIMILAR", "SNAPSHOT", "SOME", "SYSDATE", "SYSTEM", "TABLE", "TAG", + "TDES", "TEXT255", "TEXT32K", "THEN", "TIMESTAMP", "TO", "TOP", "TRAILING", "TRUE", "TRUNCATECOLUMNS", "UNION", "UNIQUE", "USER", + "USING", "VERBOSE", "WALLET", "WHEN", "WHERE", "WITH", "WITHOUT" + ], + operators: [ + "AND", "BETWEEN", "IN", "LIKE", "NOT", "OR", "IS", "NULL", "INTERSECT", "UNION", "INNER", "JOIN", "LEFT", "OUTER", "RIGHT" + ], + builtinFunctions: [ + "current_schema", "current_schemas", "has_database_privilege", "has_schema_privilege", "has_table_privilege", "age", + "current_time", "current_timestamp", "localtime", "isfinite", "now", "ascii", "get_bit", "get_byte", "set_bit", "set_byte", + "to_ascii", "approximate percentile_disc", "avg", "count", "listagg", "max", "median", "min", "percentile_cont", "stddev_samp", + "stddev_pop", "sum", "var_samp", "var_pop", "bit_and", "bit_or", "bool_and", "bool_or", "cume_dist", "first_value", "lag", + "last_value", "lead", "nth_value", "ratio_to_report", "dense_rank", "ntile", "percent_rank", "rank", "row_number", "case", + "coalesce", "decode", "greatest", "least", "nvl", "nvl2", "nullif", "add_months", "at time zone", "convert_timezone", + "current_date", "date_cmp", "date_cmp_timestamp", "date_cmp_timestamptz", "date_part_year", "dateadd", "datediff", + "date_part", "date_trunc", "extract", "getdate", "interval_cmp", "last_day", "months_between", "next_day", "sysdate", + "timeofday", "timestamp_cmp", "timestamp_cmp_date", "timestamp_cmp_timestamptz", "timestamptz_cmp", "timestamptz_cmp_date", + "timestamptz_cmp_timestamp", "timezone", "to_timestamp", "trunc", "abs", "acos", "asin", "atan", "atan2", "cbrt", "ceil", + "ceiling", "checksum", "cos", "cot", "degrees", "dexp", "dlog1", "dlog10", "exp", "floor", "ln", "log", "mod", "pi", "power", + "radians", "random", "round", "sin", "sign", "sqrt", "tan", "to_hex", "bpcharcmp", "btrim", "bttext_pattern_cmp", "char_length", + "character_length", "charindex", "chr", "concat", "crc32", "func_sha1", "initcap", "left and rights", "len", "length", "lower", + "lpad and rpads", "ltrim", "md5", "octet_length", "position", "quote_ident", "quote_literal", "regexp_count", "regexp_instr", + "regexp_replace", "regexp_substr", "repeat", "replace", "replicate", "reverse", "rtrim", "split_part", "strpos", "strtol", + "substring", "textlen", "translate", "trim", "upper", "cast", "convert", "to_char", "to_date", "to_number", "json_array_length", + "json_extract_array_element_text", "json_extract_path_text", "current_setting", "pg_cancel_backend", "pg_terminate_backend", + "set_config", "current_database", "current_user", "current_user_id", "pg_backend_pid", "pg_last_copy_count", "pg_last_copy_id", + "pg_last_query_id", "pg_last_unload_count", "session_user", "slice_num", "user", "version", "abbrev", "acosd", "any", "area", + "array_agg", "array_append", "array_cat", "array_dims", "array_fill", "array_length", "array_lower", "array_ndims", + "array_position", "array_positions", "array_prepend", "array_remove", "array_replace", "array_to_json", "array_to_string", + "array_to_tsvector", "array_upper", "asind", "atan2d", "atand", "bit", "bit_length", "bound_box", "box", + "brin_summarize_new_values", "broadcast", "cardinality", "center", "circle", "clock_timestamp", "col_description", "concat_ws", + "convert_from", "convert_to", "corr", "cosd", "cotd", "covar_pop", "covar_samp", "current_catalog", "current_query", + "current_role", "currval", "cursor_to_xml", "diameter", "div", "encode", "enum_first", "enum_last", "enum_range", "every", + "family", "format", "format_type", "generate_series", "generate_subscripts", "get_current_ts_config", "gin_clean_pending_list", + "grouping", "has_any_column_privilege", "has_column_privilege", "has_foreign_data_wrapper_privilege", "has_function_privilege", + "has_language_privilege", "has_sequence_privilege", "has_server_privilege", "has_tablespace_privilege", "has_type_privilege", + "height", "host", "hostmask", "inet_client_addr", "inet_client_port", "inet_merge", "inet_same_family", "inet_server_addr", + "inet_server_port", "isclosed", "isempty", "isopen", "json_agg", "json_object", "json_object_agg", "json_populate_record", + "json_populate_recordset", "json_to_record", "json_to_recordset", "jsonb_agg", "jsonb_object_agg", "justify_days", "justify_hours", + "justify_interval", "lastval", "left", "line", "localtimestamp", "lower_inc", "lower_inf", "lpad", "lseg", "make_date", + "make_interval", "make_time", "make_timestamp", "make_timestamptz", "masklen", "mode", "netmask", "network", "nextval", "npoints", + "num_nonnulls", "num_nulls", "numnode", "obj_description", "overlay", "parse_ident", "path", "pclose", "percentile_disc", + "pg_advisory_lock", "pg_advisory_lock_shared", "pg_advisory_unlock", "pg_advisory_unlock_all", "pg_advisory_unlock_shared", + "pg_advisory_xact_lock", "pg_advisory_xact_lock_shared", "pg_backup_start_time", "pg_blocking_pids", "pg_client_encoding", + "pg_collation_is_visible", "pg_column_size", "pg_conf_load_time", "pg_control_checkpoint", "pg_control_init", "pg_control_recovery", + "pg_control_system", "pg_conversion_is_visible", "pg_create_logical_replication_slot", "pg_create_physical_replication_slot", + "pg_create_restore_point", "pg_current_xlog_flush_location", "pg_current_xlog_insert_location", "pg_current_xlog_location", + "pg_database_size", "pg_describe_object", "pg_drop_replication_slot", "pg_export_snapshot", "pg_filenode_relation", + "pg_function_is_visible", "pg_get_constraintdef", "pg_get_expr", "pg_get_function_arguments", "pg_get_function_identity_arguments", + "pg_get_function_result", "pg_get_functiondef", "pg_get_indexdef", "pg_get_keywords", "pg_get_object_address", + "pg_get_owned_sequence", "pg_get_ruledef", "pg_get_serial_sequence", "pg_get_triggerdef", "pg_get_userbyid", "pg_get_viewdef", + "pg_has_role", "pg_identify_object", "pg_identify_object_as_address", "pg_index_column_has_property", "pg_index_has_property", + "pg_indexam_has_property", "pg_indexes_size", "pg_is_in_backup", "pg_is_in_recovery", "pg_is_other_temp_schema", + "pg_is_xlog_replay_paused", "pg_last_committed_xact", "pg_last_xact_replay_timestamp", "pg_last_xlog_receive_location", + "pg_last_xlog_replay_location", "pg_listening_channels", "pg_logical_emit_message", "pg_logical_slot_get_binary_changes", + "pg_logical_slot_get_changes", "pg_logical_slot_peek_binary_changes", "pg_logical_slot_peek_changes", "pg_ls_dir", + "pg_my_temp_schema", "pg_notification_queue_usage", "pg_opclass_is_visible", "pg_operator_is_visible", "pg_opfamily_is_visible", + "pg_options_to_table", "pg_postmaster_start_time", "pg_read_binary_file", "pg_read_file", "pg_relation_filenode", + "pg_relation_filepath", "pg_relation_size", "pg_reload_conf", "pg_replication_origin_create", "pg_replication_origin_drop", + "pg_replication_origin_oid", "pg_replication_origin_progress", "pg_replication_origin_session_is_setup", + "pg_replication_origin_session_progress", "pg_replication_origin_session_reset", "pg_replication_origin_session_setup", + "pg_replication_origin_xact_reset", "pg_replication_origin_xact_setup", "pg_rotate_logfile", "pg_size_bytes", "pg_size_pretty", + "pg_sleep", "pg_sleep_for", "pg_sleep_until", "pg_start_backup", "pg_stat_file", "pg_stop_backup", "pg_switch_xlog", + "pg_table_is_visible", "pg_table_size", "pg_tablespace_databases", "pg_tablespace_location", "pg_tablespace_size", + "pg_total_relation_size", "pg_trigger_depth", "pg_try_advisory_lock", "pg_try_advisory_lock_shared", "pg_try_advisory_xact_lock", + "pg_try_advisory_xact_lock_shared", "pg_ts_config_is_visible", "pg_ts_dict_is_visible", "pg_ts_parser_is_visible", + "pg_ts_template_is_visible", "pg_type_is_visible", "pg_typeof", "pg_xact_commit_timestamp", "pg_xlog_location_diff", + "pg_xlog_replay_pause", "pg_xlog_replay_resume", "pg_xlogfile_name", "pg_xlogfile_name_offset", "phraseto_tsquery", + "plainto_tsquery", "point", "polygon", "popen", "pqserverversion", "query_to_xml", "querytree", "quote_nullable", "radius", + "range_merge", "regexp_matches", "regexp_split_to_array", "regexp_split_to_table", "regr_avgx", "regr_avgy", "regr_count", + "regr_intercept", "regr_r2", "regr_slope", "regr_sxx", "regr_sxy", "regr_syy", "right", "row_security_active", "row_to_json", + "rpad", "scale", "set_masklen", "setseed", "setval", "setweight", "shobj_description", "sind", "sprintf", "statement_timestamp", + "stddev", "string_agg", "string_to_array", "strip", "substr", "table_to_xml", "table_to_xml_and_xmlschema", "tand", "text", + "to_json", "to_regclass", "to_regnamespace", "to_regoper", "to_regoperator", "to_regproc", "to_regprocedure", "to_regrole", + "to_regtype", "to_tsquery", "to_tsvector", "transaction_timestamp", "ts_debug", "ts_delete", "ts_filter", "ts_headline", + "ts_lexize", "ts_parse", "ts_rank", "ts_rank_cd", "ts_rewrite", "ts_stat", "ts_token_type", "tsquery_phrase", "tsvector_to_array", + "tsvector_update_trigger", "tsvector_update_trigger_column", "txid_current", "txid_current_snapshot", "txid_snapshot_xip", + "txid_snapshot_xmax", "txid_snapshot_xmin", "txid_visible_in_snapshot", "unnest", "upper_inc", "upper_inf", "variance", "width", + "width_bucket", "xml_is_well_formed", "xml_is_well_formed_content", "xml_is_well_formed_document", "xmlagg", "xmlcomment", + "xmlconcat", "xmlelement", "xmlexists", "xmlforest", "xmlparse", "xmlpi", "xmlroot", "xmlserialize", "xpath", "xpath_exists" + ], + builtinVariables: [ + // NOT SUPPORTED + ], + pseudoColumns: [ + // NOT SUPPORTED + ], + tokenizer: { + root: [ + { include: '@comments' }, + { include: '@whitespace' }, + { include: '@pseudoColumns' }, + { include: '@numbers' }, + { include: '@strings' }, + { include: '@complexIdentifiers' }, + { include: '@scopes' }, + [/[;,.]/, 'delimiter'], + [/[()]/, '@brackets'], + [/[\w@#$]+/, { + cases: { + '@keywords': 'keyword', + '@operators': 'operator', + '@builtinVariables': 'predefined', + '@builtinFunctions': 'predefined', + '@default': 'identifier' + } + }], + [/[<>=!%&+\-*/|~^]/, 'operator'], + ], + whitespace: [ + [/\s+/, 'white'] + ], + comments: [ + [/--+.*/, 'comment'], + [/\/\*/, { token: 'comment.quote', next: '@comment' }] + ], + comment: [ + [/[^*/]+/, 'comment'], + // Not supporting nested comments, as nested comments seem to not be standard? + // i.e. http://stackoverflow.com/questions/728172/are-there-multiline-comment-delimiters-in-sql-that-are-vendor-agnostic + // [/\/\*/, { token: 'comment.quote', next: '@push' }], // nested comment not allowed :-( + [/\*\//, { token: 'comment.quote', next: '@pop' }], + [/./, 'comment'] + ], + pseudoColumns: [ + [/[$][A-Za-z_][\w@#$]*/, { + cases: { + '@pseudoColumns': 'predefined', + '@default': 'identifier' + } + }], + ], + numbers: [ + [/0[xX][0-9a-fA-F]*/, 'number'], + [/[$][+-]*\d*(\.\d*)?/, 'number'], + [/((\d+(\.\d*)?)|(\.\d+))([eE][\-+]?\d+)?/, 'number'] + ], + strings: [ + [/'/, { token: 'string', next: '@string' }], + ], + string: [ + [/[^']+/, 'string'], + [/''/, 'string'], + [/'/, { token: 'string', next: '@pop' }] + ], + complexIdentifiers: [ + [/"/, { token: 'identifier.quote', next: '@quotedIdentifier' }] + ], + quotedIdentifier: [ + [/[^"]+/, 'identifier'], + [/""/, 'identifier'], + [/"/, { token: 'identifier.quote', next: '@pop' }] + ], + scopes: [ + // NOT SUPPORTED + ] + } +}; diff --git a/test/all.js b/test/all.js index 91cd206b..28d7f2c1 100644 --- a/test/all.js +++ b/test/all.js @@ -58,7 +58,11 @@ requirejs([ 'out/test/xml.test', 'out/test/yaml.test', 'out/test/solidity.test', - 'out/test/sb.test' + 'out/test/sb.test', + 'out/test/mysql.test', + 'out/test/pgsql.test', + 'out/test/redshift.test', + 'out/test/redis.test' ], function() { run(); // We can launch the tests! }); diff --git a/test/mysql.test.ts b/test/mysql.test.ts new file mode 100644 index 00000000..18ec3b9d --- /dev/null +++ b/test/mysql.test.ts @@ -0,0 +1,554 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { testTokenization } from './testRunner'; + +testTokenization('mysql', [ + // Comments + [{ + line: '-- a comment', + tokens: [ + { startIndex: 0, type: 'comment.sql' } + ] + }], + + [{ + line: '---sticky -- comment', + tokens: [ + { startIndex: 0, type: 'comment.sql' } + ] + }], + + [{ + line: '-almost a comment', + tokens: [ + { startIndex: 0, type: 'operator.sql' }, + { startIndex: 1, type: 'identifier.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.sql' }, + { startIndex: 9, type: 'white.sql' }, + { startIndex: 10, type: 'keyword.sql' } + ] + }], + + [{ + line: '/* a full line comment */', + tokens: [ + { startIndex: 0, type: 'comment.quote.sql' }, + { startIndex: 2, type: 'comment.sql' }, + { startIndex: 23, type: 'comment.quote.sql' } + ] + }], + + [{ + line: '/* /// *** /// */', + tokens: [ + { startIndex: 0, type: 'comment.quote.sql' }, + { startIndex: 2, type: 'comment.sql' }, + { startIndex: 15, type: 'comment.quote.sql' } + ] + }], + + [{ + line: '# comment', + tokens: [ + { startIndex: 0, type: 'comment.sql' } + ] + }], + + [{ + line: 'declare @x int = /* a simple comment */ 1;', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.sql' }, + { startIndex: 10, type: 'white.sql' }, + { startIndex: 11, type: 'keyword.sql' }, + { startIndex: 14, type: 'white.sql' }, + { startIndex: 15, type: 'operator.sql' }, + { startIndex: 16, type: 'white.sql' }, + { startIndex: 17, type: 'comment.quote.sql' }, + { startIndex: 19, type: 'comment.sql' }, + { startIndex: 37, type: 'comment.quote.sql' }, + { startIndex: 39, type: 'white.sql' }, + { startIndex: 40, type: 'number.sql' }, + { startIndex: 41, type: 'delimiter.sql' } + ] + }], + + // Not supporting nested comments, as nested comments seem to not be standard? + // i.e. http://stackoverflow.com/questions/728172/are-there-multiline-comment-delimiters-in-sql-that-are-vendor-agnostic + [{ + line: '@x=/* a /* nested comment 1*/;', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 2, type: 'operator.sql' }, + { startIndex: 3, type: 'comment.quote.sql' }, + { startIndex: 5, type: 'comment.sql' }, + { startIndex: 28, type: 'comment.quote.sql' }, + { startIndex: 30, type: 'delimiter.sql' } + ] + }], + + [{ + line: '@x=/* another comment */ 1*/;', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 2, type: 'operator.sql' }, + { startIndex: 3, type: 'comment.quote.sql' }, + { startIndex: 5, type: 'comment.sql' }, + { startIndex: 22, type: 'comment.quote.sql' }, + { startIndex: 24, type: 'white.sql' }, + { startIndex: 25, type: 'number.sql' }, + { startIndex: 26, type: 'operator.sql' }, + { startIndex: 28, type: 'delimiter.sql' } + ] + }], + + [{ + line: '@x=/*/;', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 2, type: 'operator.sql' }, + { startIndex: 3, type: 'comment.quote.sql' }, + { startIndex: 5, type: 'comment.sql' } + ] + }], + + // Numbers + [{ + line: '123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '-123', + tokens: [ + { startIndex: 0, type: 'operator.sql' }, + { startIndex: 1, type: 'number.sql' } + ] + }], + + [{ + line: '0xaBc123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0XaBc123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0x', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0x0', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0xAB_CD', + tokens: [ + { startIndex: 0, type: 'number.sql' }, + { startIndex: 4, type: 'identifier.sql' } + ] + }], + + [{ + line: '$', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$-123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$-+-123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$123.5678', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$0.99', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$.99', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$99.', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$0.', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$.0', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '.', + tokens: [ + { startIndex: 0, type: 'delimiter.sql' } + ] + }], + + [{ + line: '123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '123.5678', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0.99', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '.99', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '99.', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0.', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '.0', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '1E-2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '1E+2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '1E2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0.1E2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '1.E2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '.1E2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + // Identifiers + + [{ + line: 'declare `abc 321`;', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.quote.sql' }, + { startIndex: 9, type: 'identifier.sql' }, + { startIndex: 16, type: 'identifier.quote.sql' }, + { startIndex: 17, type: 'delimiter.sql' } + ] + }], + + [{ + line: '`abc`` 321 `` xyz`', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' }, + { startIndex: 17, type: 'identifier.quote.sql' } + ] + }], + + [{ + line: '`abc', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' } + ] + }], + + [{ + line: 'declare `abc 321`;', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.quote.sql' }, + { startIndex: 9, type: 'identifier.sql' }, + { startIndex: 16, type: 'identifier.quote.sql' }, + { startIndex: 17, type: 'delimiter.sql' } + ] + }], + + [{ + line: '`abc`` 321 `` xyz`', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' }, + { startIndex: 17, type: 'identifier.quote.sql' } + ] + }], + + [{ + line: '`abc', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' } + ] + }], + + [{ + line: 'int', + tokens: [ + { startIndex: 0, type: 'keyword.sql' } + ] + }], + + [{ + line: '`int`', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' }, + { startIndex: 4, type: 'identifier.quote.sql' } + ] + }], + + // Strings + [{ + line: 'declare @x=\'a string\';', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.sql' }, + { startIndex: 10, type: 'operator.sql' }, + { startIndex: 11, type: 'string.sql' }, + { startIndex: 21, type: 'delimiter.sql' } + ] + }], + + [{ + line: 'declare @x="a string";', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.sql' }, + { startIndex: 10, type: 'operator.sql' }, + { startIndex: 11, type: 'string.double.sql' }, + { startIndex: 21, type: 'delimiter.sql' } + ] + }], + + [{ + line: '\'a \'\' string with quotes\'', + tokens: [ + { startIndex: 0, type: 'string.sql' }, + ] + }], + + [{ + line: '"a "" string with quotes"', + tokens: [ + { startIndex: 0, type: 'string.double.sql' }, + ] + }], + + [{ + line: '\'a " string with quotes\'', + tokens: [ + { startIndex: 0, type: 'string.sql' }, + ] + }], + + [{ + line: '"a ` string with quotes"', + tokens: [ + { startIndex: 0, type: 'string.double.sql' }, + ] + }], + + [{ + line: '\'a -- string with comment\'', + tokens: [ + { startIndex: 0, type: 'string.sql' }, + ] + }], + + [{ + line: '"a -- string with comment"', + tokens: [ + { startIndex: 0, type: 'string.double.sql' }, + ] + }], + + [{ + line: '\'a endless string', + tokens: [ + { startIndex: 0, type: 'string.sql' }, + ] + }], + + [{ + line: '"a endless string', + tokens: [ + { startIndex: 0, type: 'string.double.sql' }, + ] + }], + + // Operators + [{ + line: 'SET @x=@x+1', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 3, type: 'white.sql' }, + { startIndex: 4, type: 'identifier.sql' }, + { startIndex: 6, type: 'operator.sql' }, + { startIndex: 7, type: 'identifier.sql' }, + { startIndex: 9, type: 'operator.sql' }, + { startIndex: 10, type: 'number.sql' } + ] + }], + + [{ + line: '@x^=@x', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 2, type: 'operator.sql' }, + { startIndex: 4, type: 'identifier.sql' } + ] + }], + + [{ + line: 'WHERE myfield IS NOT NULL', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 5, type: 'white.sql' }, + { startIndex: 6, type: 'identifier.sql' }, + { startIndex: 13, type: 'white.sql' }, + { startIndex: 14, type: 'operator.sql' }, + { startIndex: 16, type: 'white.sql' }, + { startIndex: 17, type: 'operator.sql' }, + { startIndex: 20, type: 'white.sql' }, + { startIndex: 21, type: 'operator.sql' } + ] + }], + + [{ + line: 'SELECT * FROM tbl WHERE MyColumn IN (1,2)', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 6, type: 'white.sql' }, + { startIndex: 7, type: 'operator.sql' }, + { startIndex: 8, type: 'white.sql' }, + { startIndex: 9, type: 'keyword.sql' }, + { startIndex: 13, type: 'white.sql' }, + { startIndex: 14, type: 'identifier.sql' }, + { startIndex: 17, type: 'white.sql' }, + { startIndex: 18, type: 'keyword.sql' }, + { startIndex: 23, type: 'white.sql' }, + { startIndex: 24, type: 'identifier.sql' }, + { startIndex: 32, type: 'white.sql' }, + { startIndex: 33, type: 'operator.sql' }, + { startIndex: 35, type: 'white.sql' }, + { startIndex: 36, type: 'delimiter.parenthesis.sql' }, + { startIndex: 37, type: 'number.sql' }, + { startIndex: 38, type: 'delimiter.sql' }, + { startIndex: 39, type: 'number.sql' }, + { startIndex: 40, type: 'delimiter.parenthesis.sql' } + ] + }] +]); diff --git a/test/pgsql.test.ts b/test/pgsql.test.ts new file mode 100644 index 00000000..d8958603 --- /dev/null +++ b/test/pgsql.test.ts @@ -0,0 +1,555 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { testTokenization } from './testRunner'; + +testTokenization('sql', [ + // Comments + [{ + line: '-- a comment', + tokens: [ + { startIndex: 0, type: 'comment.sql' } + ] + }], + + [{ + line: '---sticky -- comment', + tokens: [ + { startIndex: 0, type: 'comment.sql' } + ] + }], + + [{ + line: '-almost a comment', + tokens: [ + { startIndex: 0, type: 'operator.sql' }, + { startIndex: 1, type: 'identifier.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.sql' }, + { startIndex: 9, type: 'white.sql' }, + { startIndex: 10, type: 'identifier.sql' } + ] + }], + + [{ + line: '/* a full line comment */', + tokens: [ + { startIndex: 0, type: 'comment.quote.sql' }, + { startIndex: 2, type: 'comment.sql' }, + { startIndex: 23, type: 'comment.quote.sql' } + ] + }], + + [{ + line: '/* /// *** /// */', + tokens: [ + { startIndex: 0, type: 'comment.quote.sql' }, + { startIndex: 2, type: 'comment.sql' }, + { startIndex: 15, type: 'comment.quote.sql' } + ] + }], + + [{ + line: 'declare _x int = /* a simple comment */ 1;', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.sql' }, + { startIndex: 10, type: 'white.sql' }, + { startIndex: 11, type: 'keyword.sql' }, + { startIndex: 14, type: 'white.sql' }, + { startIndex: 15, type: 'operator.sql' }, + { startIndex: 16, type: 'white.sql' }, + { startIndex: 17, type: 'comment.quote.sql' }, + { startIndex: 19, type: 'comment.sql' }, + { startIndex: 37, type: 'comment.quote.sql' }, + { startIndex: 39, type: 'white.sql' }, + { startIndex: 40, type: 'number.sql' }, + { startIndex: 41, type: 'delimiter.sql' } + ] + }], + + // Not supporting nested comments, as nested comments seem to not be standard? + // i.e. http://stackoverflow.com/questions/728172/are-there-multiline-comment-delimiters-in-sql-that-are-vendor-agnostic + [{ + line: '_x=/* a /* nested comment 1*/;', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 2, type: 'operator.sql' }, + { startIndex: 3, type: 'comment.quote.sql' }, + { startIndex: 5, type: 'comment.sql' }, + { startIndex: 28, type: 'comment.quote.sql' }, + { startIndex: 30, type: 'delimiter.sql' } + ] + }], + + [{ + line: '_x=/* another comment */ 1*/;', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 2, type: 'operator.sql' }, + { startIndex: 3, type: 'comment.quote.sql' }, + { startIndex: 5, type: 'comment.sql' }, + { startIndex: 22, type: 'comment.quote.sql' }, + { startIndex: 24, type: 'white.sql' }, + { startIndex: 25, type: 'number.sql' }, + { startIndex: 26, type: 'operator.sql' }, + { startIndex: 28, type: 'delimiter.sql' } + ] + }], + + [{ + line: '_x=/*/;', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 2, type: 'operator.sql' }, + { startIndex: 3, type: 'comment.quote.sql' }, + { startIndex: 5, type: 'comment.sql' } + ] + }], + + // Numbers + [{ + line: '123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '-123', + tokens: [ + { startIndex: 0, type: 'operator.sql' }, + { startIndex: 1, type: 'number.sql' } + ] + }], + + [{ + line: '0xaBc123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0XaBc123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0x', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0x0', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0xAB_CD', + tokens: [ + { startIndex: 0, type: 'number.sql' }, + { startIndex: 4, type: 'identifier.sql' } + ] + }], + + [{ + line: '$', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$-123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$-+-123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$123.5678', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$0.99', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$.99', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$99.', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$0.', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$.0', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '.', + tokens: [ + { startIndex: 0, type: 'delimiter.sql' } + ] + }], + + [{ + line: '123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '123.5678', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0.99', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '.99', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '99.', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0.', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '.0', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '1E-2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '1E+2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '1E2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0.1E2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '1.E2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '.1E2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + // Identifiers + [{ + line: '_abc$01', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '#abc$01', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '##abc$01', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '@abc$01', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '@@abc$01', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '$abc', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '$nonexistent', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '@@nonexistent', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: 'declare "abc 321";', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.quote.sql' }, + { startIndex: 9, type: 'identifier.sql' }, + { startIndex: 16, type: 'identifier.quote.sql' }, + { startIndex: 17, type: 'delimiter.sql' } + ] + }], + + [{ + line: '"abc"" 321 "" xyz"', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' }, + { startIndex: 17, type: 'identifier.quote.sql' } + ] + }], + + [{ + line: '"abc', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' } + ] + }], + + [{ + line: 'declare "abc 321";', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.quote.sql' }, + { startIndex: 9, type: 'identifier.sql' }, + { startIndex: 16, type: 'identifier.quote.sql' }, + { startIndex: 17, type: 'delimiter.sql' } + ] + }], + + [{ + line: '"abc"" 321 "" xyz"', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' }, + { startIndex: 17, type: 'identifier.quote.sql' } + ] + }], + + [{ + line: '"abc', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' } + ] + }], + + [{ + line: 'int', + tokens: [ + { startIndex: 0, type: 'keyword.sql' } + ] + }], + + [{ + line: '"int"', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' }, + { startIndex: 4, type: 'identifier.quote.sql' } + ] + }], + + // Strings + [{ + line: 'declare _x=\'a string\';', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.sql' }, + { startIndex: 10, type: 'operator.sql' }, + { startIndex: 11, type: 'string.sql' }, + { startIndex: 21, type: 'delimiter.sql' } + ] + }], + + [{ + line: '\'a \'\' string with quotes\'', + tokens: [ + { startIndex: 0, type: 'string.sql' }, + ] + }], + + [{ + line: '\'a -- string with comment\'', + tokens: [ + { startIndex: 0, type: 'string.sql' }, + ] + }], + + [{ + line: '\'a endless string', + tokens: [ + { startIndex: 0, type: 'string.sql' }, + ] + }], + + // Operators + [{ + line: 'x=x+1', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 1, type: 'operator.sql' }, + { startIndex: 2, type: 'identifier.sql' }, + { startIndex: 3, type: 'operator.sql' }, + { startIndex: 4, type: 'number.sql' } + ] + }], + + [{ + line: '_x^=_x', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 2, type: 'operator.sql' }, + { startIndex: 4, type: 'identifier.sql' } + ] + }], + + [{ + line: 'WHERE x IS NOT NULL', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 5, type: 'white.sql' }, + { startIndex: 6, type: 'identifier.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'operator.sql' }, + { startIndex: 10, type: 'white.sql' }, + { startIndex: 11, type: 'operator.sql' }, + { startIndex: 14, type: 'white.sql' }, + { startIndex: 15, type: 'operator.sql' } + ] + }], + + [{ + line: 'SELECT * FROM sch.MyTable WHERE MyColumn IN (1,2)', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 6, type: 'white.sql' }, + { startIndex: 7, type: 'operator.sql' }, + { startIndex: 8, type: 'white.sql' }, + { startIndex: 9, type: 'keyword.sql' }, + { startIndex: 13, type: 'white.sql' }, + { startIndex: 14, type: 'identifier.sql' }, + { startIndex: 17, type: 'delimiter.sql' }, + { startIndex: 18, type: 'identifier.sql' }, + { startIndex: 25, type: 'white.sql' }, + { startIndex: 26, type: 'keyword.sql' }, + { startIndex: 31, type: 'white.sql' }, + { startIndex: 32, type: 'identifier.sql' }, + { startIndex: 40, type: 'white.sql' }, + { startIndex: 41, type: 'operator.sql' }, + { startIndex: 43, type: 'white.sql' }, + { startIndex: 44, type: 'delimiter.parenthesis.sql' }, + { startIndex: 45, type: 'number.sql' }, + { startIndex: 46, type: 'delimiter.sql' }, + { startIndex: 47, type: 'number.sql' }, + { startIndex: 48, type: 'delimiter.parenthesis.sql' } + ] + }] +]); diff --git a/test/redis.test.ts b/test/redis.test.ts new file mode 100644 index 00000000..83a96b83 --- /dev/null +++ b/test/redis.test.ts @@ -0,0 +1,295 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { testTokenization } from './testRunner'; + +testTokenization('redis', [ + + // Numbers + [{ + line: '123', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '-123', + tokens: [ + { startIndex: 0, type: 'operator.redis' }, + { startIndex: 1, type: 'number.redis' } + ] + }], + + [{ + line: '0xaBc123', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '0XaBc123', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '0x', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '0x0', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '0xAB_CD', + tokens: [ + { startIndex: 0, type: 'number.redis' }, + { startIndex: 4, type: 'identifier.redis' } + ] + }], + + [{ + line: '$', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '$-123', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '$-+-123', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '$123.5678', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '$0.99', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '$.99', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '$99.', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '$0.', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '$.0', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '.', + tokens: [ + { startIndex: 0, type: 'delimiter.redis' } + ] + }], + + [{ + line: '123', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '123.5678', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '0.99', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '.99', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '99.', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '0.', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '.0', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '1E-2', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '1E+2', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '1E2', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '0.1E2', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '1.E2', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + [{ + line: '.1E2', + tokens: [ + { startIndex: 0, type: 'number.redis' } + ] + }], + + // Strings + + [{ + line: 'SET key1 "Hello"', + tokens: [ + { startIndex: 0, type: 'keyword.redis' }, + { startIndex: 3, type: 'white.redis' }, + { startIndex: 4, type: 'identifier.redis' }, + { startIndex: 8, type: 'white.redis' }, + { startIndex: 9, type: 'string.double.redis' }, + ] + }], + + [{ + line: 'SET key1 \'Hello\'', + tokens: [ + { startIndex: 0, type: 'keyword.redis' }, + { startIndex: 3, type: 'white.redis' }, + { startIndex: 4, type: 'identifier.redis' }, + { startIndex: 8, type: 'white.redis' }, + { startIndex: 9, type: 'string.redis' }, + ] + }], + + // Commands + + [{ + line: 'DEL key1 key2 key3', + tokens: [ + { startIndex: 0, type: 'keyword.redis' }, + { startIndex: 3, type: 'white.redis' }, + { startIndex: 4, type: 'identifier.redis' }, + { startIndex: 8, type: 'white.redis' }, + { startIndex: 9, type: 'identifier.redis' }, + { startIndex: 13, type: 'white.redis' }, + { startIndex: 14, type: 'identifier.redis' }, + ] + }], + + [{ + line: 'GEOADD Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"', + tokens: [ + { startIndex: 0, type: 'keyword.redis' }, + { startIndex: 6, type: 'white.redis' }, + { startIndex: 7, type: 'identifier.redis' }, + { startIndex: 13, type: 'white.redis' }, + { startIndex: 14, type: 'number.redis' }, + { startIndex: 23, type: 'white.redis' }, + { startIndex: 24, type: 'number.redis' }, + { startIndex: 33, type: 'white.redis' }, + { startIndex: 34, type: 'string.double.redis' }, + { startIndex: 43, type: 'white.redis' }, + { startIndex: 44, type: 'number.redis' }, + { startIndex: 53, type: 'white.redis' }, + { startIndex: 54, type: 'number.redis' }, + { startIndex: 63, type: 'white.redis' }, + { startIndex: 64, type: 'string.double.redis' }, + ] + }], + + [{ + line: 'HGET myhash field1', + tokens: [ + { startIndex: 0, type: 'keyword.redis' }, + { startIndex: 4, type: 'white.redis' }, + { startIndex: 5, type: 'identifier.redis' }, + { startIndex: 11, type: 'white.redis' }, + { startIndex: 12, type: 'identifier.redis' } + ] + }], +]); diff --git a/test/redshift.test.ts b/test/redshift.test.ts new file mode 100644 index 00000000..d8958603 --- /dev/null +++ b/test/redshift.test.ts @@ -0,0 +1,555 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { testTokenization } from './testRunner'; + +testTokenization('sql', [ + // Comments + [{ + line: '-- a comment', + tokens: [ + { startIndex: 0, type: 'comment.sql' } + ] + }], + + [{ + line: '---sticky -- comment', + tokens: [ + { startIndex: 0, type: 'comment.sql' } + ] + }], + + [{ + line: '-almost a comment', + tokens: [ + { startIndex: 0, type: 'operator.sql' }, + { startIndex: 1, type: 'identifier.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.sql' }, + { startIndex: 9, type: 'white.sql' }, + { startIndex: 10, type: 'identifier.sql' } + ] + }], + + [{ + line: '/* a full line comment */', + tokens: [ + { startIndex: 0, type: 'comment.quote.sql' }, + { startIndex: 2, type: 'comment.sql' }, + { startIndex: 23, type: 'comment.quote.sql' } + ] + }], + + [{ + line: '/* /// *** /// */', + tokens: [ + { startIndex: 0, type: 'comment.quote.sql' }, + { startIndex: 2, type: 'comment.sql' }, + { startIndex: 15, type: 'comment.quote.sql' } + ] + }], + + [{ + line: 'declare _x int = /* a simple comment */ 1;', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.sql' }, + { startIndex: 10, type: 'white.sql' }, + { startIndex: 11, type: 'keyword.sql' }, + { startIndex: 14, type: 'white.sql' }, + { startIndex: 15, type: 'operator.sql' }, + { startIndex: 16, type: 'white.sql' }, + { startIndex: 17, type: 'comment.quote.sql' }, + { startIndex: 19, type: 'comment.sql' }, + { startIndex: 37, type: 'comment.quote.sql' }, + { startIndex: 39, type: 'white.sql' }, + { startIndex: 40, type: 'number.sql' }, + { startIndex: 41, type: 'delimiter.sql' } + ] + }], + + // Not supporting nested comments, as nested comments seem to not be standard? + // i.e. http://stackoverflow.com/questions/728172/are-there-multiline-comment-delimiters-in-sql-that-are-vendor-agnostic + [{ + line: '_x=/* a /* nested comment 1*/;', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 2, type: 'operator.sql' }, + { startIndex: 3, type: 'comment.quote.sql' }, + { startIndex: 5, type: 'comment.sql' }, + { startIndex: 28, type: 'comment.quote.sql' }, + { startIndex: 30, type: 'delimiter.sql' } + ] + }], + + [{ + line: '_x=/* another comment */ 1*/;', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 2, type: 'operator.sql' }, + { startIndex: 3, type: 'comment.quote.sql' }, + { startIndex: 5, type: 'comment.sql' }, + { startIndex: 22, type: 'comment.quote.sql' }, + { startIndex: 24, type: 'white.sql' }, + { startIndex: 25, type: 'number.sql' }, + { startIndex: 26, type: 'operator.sql' }, + { startIndex: 28, type: 'delimiter.sql' } + ] + }], + + [{ + line: '_x=/*/;', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 2, type: 'operator.sql' }, + { startIndex: 3, type: 'comment.quote.sql' }, + { startIndex: 5, type: 'comment.sql' } + ] + }], + + // Numbers + [{ + line: '123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '-123', + tokens: [ + { startIndex: 0, type: 'operator.sql' }, + { startIndex: 1, type: 'number.sql' } + ] + }], + + [{ + line: '0xaBc123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0XaBc123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0x', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0x0', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0xAB_CD', + tokens: [ + { startIndex: 0, type: 'number.sql' }, + { startIndex: 4, type: 'identifier.sql' } + ] + }], + + [{ + line: '$', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$-123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$-+-123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$123.5678', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$0.99', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$.99', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$99.', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$0.', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '$.0', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '.', + tokens: [ + { startIndex: 0, type: 'delimiter.sql' } + ] + }], + + [{ + line: '123', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '123.5678', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0.99', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '.99', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '99.', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0.', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '.0', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '1E-2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '1E+2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '1E2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '0.1E2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '1.E2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + [{ + line: '.1E2', + tokens: [ + { startIndex: 0, type: 'number.sql' } + ] + }], + + // Identifiers + [{ + line: '_abc$01', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '#abc$01', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '##abc$01', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '@abc$01', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '@@abc$01', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '$abc', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '$nonexistent', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: '@@nonexistent', + tokens: [ + { startIndex: 0, type: 'identifier.sql' } + ] + }], + + [{ + line: 'declare "abc 321";', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.quote.sql' }, + { startIndex: 9, type: 'identifier.sql' }, + { startIndex: 16, type: 'identifier.quote.sql' }, + { startIndex: 17, type: 'delimiter.sql' } + ] + }], + + [{ + line: '"abc"" 321 "" xyz"', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' }, + { startIndex: 17, type: 'identifier.quote.sql' } + ] + }], + + [{ + line: '"abc', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' } + ] + }], + + [{ + line: 'declare "abc 321";', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.quote.sql' }, + { startIndex: 9, type: 'identifier.sql' }, + { startIndex: 16, type: 'identifier.quote.sql' }, + { startIndex: 17, type: 'delimiter.sql' } + ] + }], + + [{ + line: '"abc"" 321 "" xyz"', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' }, + { startIndex: 17, type: 'identifier.quote.sql' } + ] + }], + + [{ + line: '"abc', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' } + ] + }], + + [{ + line: 'int', + tokens: [ + { startIndex: 0, type: 'keyword.sql' } + ] + }], + + [{ + line: '"int"', + tokens: [ + { startIndex: 0, type: 'identifier.quote.sql' }, + { startIndex: 1, type: 'identifier.sql' }, + { startIndex: 4, type: 'identifier.quote.sql' } + ] + }], + + // Strings + [{ + line: 'declare _x=\'a string\';', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'identifier.sql' }, + { startIndex: 10, type: 'operator.sql' }, + { startIndex: 11, type: 'string.sql' }, + { startIndex: 21, type: 'delimiter.sql' } + ] + }], + + [{ + line: '\'a \'\' string with quotes\'', + tokens: [ + { startIndex: 0, type: 'string.sql' }, + ] + }], + + [{ + line: '\'a -- string with comment\'', + tokens: [ + { startIndex: 0, type: 'string.sql' }, + ] + }], + + [{ + line: '\'a endless string', + tokens: [ + { startIndex: 0, type: 'string.sql' }, + ] + }], + + // Operators + [{ + line: 'x=x+1', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 1, type: 'operator.sql' }, + { startIndex: 2, type: 'identifier.sql' }, + { startIndex: 3, type: 'operator.sql' }, + { startIndex: 4, type: 'number.sql' } + ] + }], + + [{ + line: '_x^=_x', + tokens: [ + { startIndex: 0, type: 'identifier.sql' }, + { startIndex: 2, type: 'operator.sql' }, + { startIndex: 4, type: 'identifier.sql' } + ] + }], + + [{ + line: 'WHERE x IS NOT NULL', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 5, type: 'white.sql' }, + { startIndex: 6, type: 'identifier.sql' }, + { startIndex: 7, type: 'white.sql' }, + { startIndex: 8, type: 'operator.sql' }, + { startIndex: 10, type: 'white.sql' }, + { startIndex: 11, type: 'operator.sql' }, + { startIndex: 14, type: 'white.sql' }, + { startIndex: 15, type: 'operator.sql' } + ] + }], + + [{ + line: 'SELECT * FROM sch.MyTable WHERE MyColumn IN (1,2)', + tokens: [ + { startIndex: 0, type: 'keyword.sql' }, + { startIndex: 6, type: 'white.sql' }, + { startIndex: 7, type: 'operator.sql' }, + { startIndex: 8, type: 'white.sql' }, + { startIndex: 9, type: 'keyword.sql' }, + { startIndex: 13, type: 'white.sql' }, + { startIndex: 14, type: 'identifier.sql' }, + { startIndex: 17, type: 'delimiter.sql' }, + { startIndex: 18, type: 'identifier.sql' }, + { startIndex: 25, type: 'white.sql' }, + { startIndex: 26, type: 'keyword.sql' }, + { startIndex: 31, type: 'white.sql' }, + { startIndex: 32, type: 'identifier.sql' }, + { startIndex: 40, type: 'white.sql' }, + { startIndex: 41, type: 'operator.sql' }, + { startIndex: 43, type: 'white.sql' }, + { startIndex: 44, type: 'delimiter.parenthesis.sql' }, + { startIndex: 45, type: 'number.sql' }, + { startIndex: 46, type: 'delimiter.sql' }, + { startIndex: 47, type: 'number.sql' }, + { startIndex: 48, type: 'delimiter.parenthesis.sql' } + ] + }] +]);