From f61119e07b7b883be43d3451f2fc152848e5dc50 Mon Sep 17 00:00:00 2001 From: Serge Rider Date: Sat, 28 Dec 2019 15:29:04 +0300 Subject: [PATCH] #7494 Text parser base model. SQL dialect registry Former-commit-id: a7d096ee67889a09aa7fcc5824bec6144ae966ac --- .../META-INF/MANIFEST.MF | 3 +- .../org.jkiss.dbeaver.model.sql/plugin.xml | 14 ++ .../schema/org.jkiss.dbeaver.sqlDialect.exsd | 144 ++++++++++++++++++ .../sql/registry/SQLDialectDescriptor.java | 68 +++++++++ .../sql/registry/SQLDialectRegistry.java | 74 +++++++++ .../model/text/parser/TPCharacterScanner.java | 56 +++++++ .../model/text/parser/TPPredicateRule.java | 27 ++++ .../dbeaver/model/text/parser/TPRule.java | 35 +++++ .../dbeaver/model/text/parser/TPToken.java | 60 ++++++++ .../model/text/parser/TPTokenAbstract.java | 76 +++++++++ .../model/text/parser/TPTokenDefault.java | 31 ++++ .../model/text/parser/TPTokenPartition.java | 31 ++++ .../model/text/parser/TPTokenType.java | 35 +++++ .../model/impl/sql/BasicSQLDialect.java | 2 +- .../sql/syntax/SQLPartitionScanner.java | 3 +- .../ui/editors/sql/syntax/SQLRuleManager.java | 61 ++++---- .../sql/syntax/tokens/SQLTokenType.java | 56 +++++++ 17 files changed, 739 insertions(+), 37 deletions(-) create mode 100644 plugins/org.jkiss.dbeaver.model.sql/schema/org.jkiss.dbeaver.sqlDialect.exsd create mode 100644 plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/registry/SQLDialectDescriptor.java create mode 100644 plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/registry/SQLDialectRegistry.java create mode 100644 plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPCharacterScanner.java create mode 100644 plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPPredicateRule.java create mode 100644 plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPRule.java create mode 100644 plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPToken.java create mode 100644 plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenAbstract.java create mode 100644 plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenDefault.java create mode 100644 plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenPartition.java create mode 100644 plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenType.java create mode 100644 plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/syntax/tokens/SQLTokenType.java diff --git a/plugins/org.jkiss.dbeaver.model.sql/META-INF/MANIFEST.MF b/plugins/org.jkiss.dbeaver.model.sql/META-INF/MANIFEST.MF index 89d8b9ade6..e03f589d82 100644 --- a/plugins/org.jkiss.dbeaver.model.sql/META-INF/MANIFEST.MF +++ b/plugins/org.jkiss.dbeaver.model.sql/META-INF/MANIFEST.MF @@ -18,7 +18,8 @@ Export-Package: org.jkiss.dbeaver.model.sql, org.jkiss.dbeaver.model.sql.format.tokenized, org.jkiss.dbeaver.model.sql.parser, org.jkiss.dbeaver.model.sql.registry, - org.jkiss.dbeaver.model.text + org.jkiss.dbeaver.model.text, + org.jkiss.dbeaver.model.text.parser Bundle-ClassPath: . Require-Bundle: org.eclipse.equinox.security, org.eclipse.core.runtime, diff --git a/plugins/org.jkiss.dbeaver.model.sql/plugin.xml b/plugins/org.jkiss.dbeaver.model.sql/plugin.xml index 2732a049ca..c1e10a955c 100644 --- a/plugins/org.jkiss.dbeaver.model.sql/plugin.xml +++ b/plugins/org.jkiss.dbeaver.model.sql/plugin.xml @@ -4,6 +4,7 @@ + @@ -23,4 +24,17 @@ + + + + + + + + + + + + + diff --git a/plugins/org.jkiss.dbeaver.model.sql/schema/org.jkiss.dbeaver.sqlDialect.exsd b/plugins/org.jkiss.dbeaver.model.sql/schema/org.jkiss.dbeaver.sqlDialect.exsd new file mode 100644 index 0000000000..033461bd3e --- /dev/null +++ b/plugins/org.jkiss.dbeaver.model.sql/schema/org.jkiss.dbeaver.sqlDialect.exsd @@ -0,0 +1,144 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/registry/SQLDialectDescriptor.java b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/registry/SQLDialectDescriptor.java new file mode 100644 index 0000000000..6b78a4eb44 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/registry/SQLDialectDescriptor.java @@ -0,0 +1,68 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jkiss.dbeaver.model.sql.registry; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.jkiss.dbeaver.DBException; +import org.jkiss.dbeaver.model.DBPImage; +import org.jkiss.dbeaver.model.impl.AbstractContextDescriptor; +import org.jkiss.dbeaver.model.sql.SQLDialect; + +/** + * SQLDialectDescriptor + */ +public class SQLDialectDescriptor extends AbstractContextDescriptor { + + public static final String EXTENSION_ID = "org.jkiss.dbeaver.sqlDialect"; //$NON-NLS-1$ + + private final String id; + private final String label; + private final String description; + private final ObjectType implClass; + private final DBPImage icon; + + SQLDialectDescriptor(IConfigurationElement config) { + super(config); + this.id = config.getAttribute("id"); + this.label = config.getAttribute("label"); + this.description = config.getAttribute("description"); + this.implClass = new ObjectType(config.getAttribute("class")); + this.icon = iconToImage(config.getAttribute("icon")); + } + + public String getId() { + return id; + } + + public String getLabel() { + return label; + } + + public String getDescription() { + return description; + } + + public DBPImage getIcon() { + return icon; + } + + public SQLDialect createInstance() throws DBException { + return implClass.createInstance(SQLDialect.class); + } + +} diff --git a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/registry/SQLDialectRegistry.java b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/registry/SQLDialectRegistry.java new file mode 100644 index 0000000000..f39a762b1c --- /dev/null +++ b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/sql/registry/SQLDialectRegistry.java @@ -0,0 +1,74 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jkiss.dbeaver.model.sql.registry; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class SQLDialectRegistry +{ + static final String TAG_DIALECT = "dialect"; //$NON-NLS-1$ + + private static SQLDialectRegistry instance = null; + + public synchronized static SQLDialectRegistry getInstance() + { + if (instance == null) { + instance = new SQLDialectRegistry(); + instance.loadExtensions(Platform.getExtensionRegistry()); + } + return instance; + } + + private final Map dialects = new LinkedHashMap<>(); + + private SQLDialectRegistry() + { + } + + private void loadExtensions(IExtensionRegistry registry) + { + IConfigurationElement[] extConfigs = registry.getConfigurationElementsFor(SQLCommandHandlerDescriptor.EXTENSION_ID); + for (IConfigurationElement ext : extConfigs) { + // Load functions + if (TAG_DIALECT.equals(ext.getName())) { + SQLDialectDescriptor commandDescriptor = new SQLDialectDescriptor(ext); + this.dialects.put(commandDescriptor.getId(), commandDescriptor); + } + } + } + + public void dispose() + { + dialects.clear(); + } + + public List getDialects() { + return new ArrayList<>(dialects.values()); + } + + public SQLDialectDescriptor getDialect(String id) { + return dialects.get(id); + } + +} diff --git a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPCharacterScanner.java b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPCharacterScanner.java new file mode 100644 index 0000000000..3387fec140 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPCharacterScanner.java @@ -0,0 +1,56 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jkiss.dbeaver.model.text.parser; + + +/** + * Replica of ICharacterScanner but without jface/swt + */ +public interface TPCharacterScanner { + + /** + * The value returned when this scanner has read EOF. + */ + int EOF= -1; + + /** + * Provides rules access to the legal line delimiters. The returned + * object may not be modified by clients. + * + * @return the legal line delimiters + */ + char[][] getLegalLineDelimiters(); + + /** + * Returns the column of the character scanner. + * + * @return the column of the character scanner + */ + int getColumn(); + + /** + * Returns the next character or EOF if end of file has been reached + * + * @return the next character or EOF + */ + int read(); + + /** + * Rewinds the scanner before the last read character. + */ + void unread(); +} diff --git a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPPredicateRule.java b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPPredicateRule.java new file mode 100644 index 0000000000..e53e1f1cc5 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPPredicateRule.java @@ -0,0 +1,27 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jkiss.dbeaver.model.text.parser; + +/** + * Replicate of IPredicateRule + */ +public interface TPPredicateRule extends TPRule { + + TPToken getSuccessToken(); + + TPToken evaluate(TPCharacterScanner scanner, boolean resume); +} diff --git a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPRule.java b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPRule.java new file mode 100644 index 0000000000..a878951079 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPRule.java @@ -0,0 +1,35 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jkiss.dbeaver.model.text.parser; + + +/** + * Simple rule + */ +public interface TPRule { + + /** + * Evaluates the rule by examining the characters available from the provided character scanner. + * The token returned by this rule returns true when calling + * isUndefined, if the text that the rule investigated does not match the rule's + * requirements + * + * @param scanner the character scanner to be used by this rule + * @return the token computed by the rule + */ + TPToken evaluate(TPCharacterScanner scanner); +} diff --git a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPToken.java b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPToken.java new file mode 100644 index 0000000000..21d0fad9bc --- /dev/null +++ b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPToken.java @@ -0,0 +1,60 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jkiss.dbeaver.model.text.parser; + + +/** + * A token to be returned by a rule. + */ +public interface TPToken { + + /** + * Return whether this token is undefined. + * + * @return trueif this token is undefined + */ + boolean isUndefined(); + + /** + * Return whether this token represents a whitespace. + * + * @return trueif this token represents a whitespace + */ + boolean isWhitespace(); + + /** + * Return whether this token represents End Of File. + * + * @return trueif this token represents EOF + */ + boolean isEOF(); + + /** + * Return whether this token is neither undefined, nor whitespace, nor EOF. + * + * @return trueif this token is not undefined, not a whitespace, and not EOF + */ + boolean isOther(); + + /** + * Return a data attached to this token. The semantics of this data kept undefined by this interface. + * + * @return the data attached to this token. + */ + Object getData(); + +} diff --git a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenAbstract.java b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenAbstract.java new file mode 100644 index 0000000000..f5e7e075d5 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenAbstract.java @@ -0,0 +1,76 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jkiss.dbeaver.model.text.parser; + +/** + * Standard implementation of TPToken. + */ +public class TPTokenAbstract implements TPToken { + + private static final int T_UNDEFINED = 0; + private static final int T_EOF = 1; + private static final int T_WHITESPACE = 2; + private static final int T_OTHER = 3; + + public static final TPToken UNDEFINED = new TPTokenAbstract(T_UNDEFINED); + public static final TPToken EOF = new TPTokenAbstract(T_EOF); + public static final TPToken WHITESPACE = new TPTokenAbstract(T_WHITESPACE); + + /** + * The type of this token + */ + private int type; + private DATA data; + + private TPTokenAbstract(int type) { + this.type = type; + } + + /** + * Creates a new token according to the given specification which does not + * have any data attached to it. + */ + protected TPTokenAbstract(int type, DATA data) { + this.type = type; + } + + @Override + public DATA getData() { + return data; + } + + @Override + public boolean isOther() { + return (type == T_OTHER); + } + + @Override + public boolean isEOF() { + return (type == T_EOF); + } + + @Override + public boolean isWhitespace() { + return (type == T_WHITESPACE); + } + + @Override + public boolean isUndefined() { + return (type == T_UNDEFINED); + } + +} diff --git a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenDefault.java b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenDefault.java new file mode 100644 index 0000000000..4d8e0fc5f5 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenDefault.java @@ -0,0 +1,31 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jkiss.dbeaver.model.text.parser; + +/** + * Token for main scanner + */ +public class TPTokenDefault extends TPTokenAbstract { + + /** + * Token for main parser. Data is token type, depends on parser but usually refers to some colored type. + */ + protected TPTokenDefault(TPTokenType type) { + super(type.getTokenType(), type); + } + +} diff --git a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenPartition.java b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenPartition.java new file mode 100644 index 0000000000..38b10fb50b --- /dev/null +++ b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenPartition.java @@ -0,0 +1,31 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jkiss.dbeaver.model.text.parser; + +/** + * Token for partition scanner + */ +public class TPTokenPartition extends TPTokenAbstract { + + /** + * Token for partition parser. Data is content type. + */ + protected TPTokenPartition(int type, String contentType) { + super(type, contentType); + } + +} diff --git a/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenType.java b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenType.java new file mode 100644 index 0000000000..f0d7d2da79 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.model.sql/src/org/jkiss/dbeaver/model/text/parser/TPTokenType.java @@ -0,0 +1,35 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jkiss.dbeaver.model.text.parser; + + +/** + * A token type + */ +public interface TPTokenType { + + /** + * See TPTokenAbstract.T_ constants + */ + int getTokenType(); + + /** + * Usually some color ID associated with this type + */ + String getTypeId(); + +} diff --git a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/sql/BasicSQLDialect.java b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/sql/BasicSQLDialect.java index fd307ce32e..4d61fab6f8 100644 --- a/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/sql/BasicSQLDialect.java +++ b/plugins/org.jkiss.dbeaver.model/src/org/jkiss/dbeaver/model/impl/sql/BasicSQLDialect.java @@ -235,7 +235,7 @@ public class BasicSQLDialect implements SQLDialect { @NotNull @Override public String getSearchStringEscape() { - return null; + return ""; } @Override diff --git a/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLPartitionScanner.java b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLPartitionScanner.java index 48cc0abd36..74377f4c4e 100644 --- a/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLPartitionScanner.java +++ b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLPartitionScanner.java @@ -25,6 +25,7 @@ import org.jkiss.dbeaver.model.DBPDataSource; import org.jkiss.dbeaver.model.sql.SQLConstants; import org.jkiss.dbeaver.model.sql.SQLDialect; import org.jkiss.dbeaver.model.sql.parser.SQLParserPartitions; +import org.jkiss.dbeaver.model.text.parser.TPCharacterScanner; import org.jkiss.dbeaver.runtime.sql.SQLRuleProvider; import org.jkiss.dbeaver.utils.GeneralUtils; import org.jkiss.utils.ArrayUtils; @@ -40,7 +41,7 @@ import java.util.List; * changed. The document partitions are based on tokens that represent comments * and SQL code sections. */ -public class SQLPartitionScanner extends RuleBasedPartitionScanner { +public class SQLPartitionScanner extends RuleBasedPartitionScanner implements TPCharacterScanner { private final DBPDataSource dataSource; // Syntax highlight diff --git a/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLRuleManager.java b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLRuleManager.java index 1dfad3a36e..cf822a7cbf 100644 --- a/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLRuleManager.java +++ b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/syntax/SQLRuleManager.java @@ -36,6 +36,7 @@ import org.jkiss.dbeaver.model.sql.SQLSyntaxManager; import org.jkiss.dbeaver.model.sql.parser.SQLWordDetector; import org.jkiss.dbeaver.model.sql.registry.SQLCommandHandlerDescriptor; import org.jkiss.dbeaver.model.sql.registry.SQLCommandsRegistry; +import org.jkiss.dbeaver.model.text.parser.TPCharacterScanner; import org.jkiss.dbeaver.runtime.DBWorkbench; import org.jkiss.dbeaver.runtime.sql.SQLRuleProvider; import org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase; @@ -52,11 +53,11 @@ import java.util.*; /** * SQLSyntaxManager. - *

+ * * Contains information about some concrete datasource underlying database syntax. * Support runtime change of datasource (reloads syntax information) */ -public class SQLRuleManager extends RuleBasedScanner { +public class SQLRuleManager extends RuleBasedScanner implements TPCharacterScanner { @NotNull private final IThemeManager themeManager; @@ -69,8 +70,7 @@ public class SQLRuleManager extends RuleBasedScanner { private boolean evalMode; - public SQLRuleManager(@NotNull SQLSyntaxManager syntaxManager) - { + public SQLRuleManager(@NotNull SQLSyntaxManager syntaxManager) { this.syntaxManager = syntaxManager; this.themeManager = PlatformUI.getWorkbench().getThemeManager(); } @@ -94,19 +94,16 @@ public class SQLRuleManager extends RuleBasedScanner { } } - public void dispose() - { + public void dispose() { } @NotNull - public Collection getPositions(int offset, int length) - { + public Collection getPositions(int offset, int length) { return positions.subMap(offset, offset + length).values(); } @NotNull - public synchronized Set getRemovedPositions(boolean clear) - { + public synchronized Set getRemovedPositions(boolean clear) { Set posList = removedPositions; if (clear) { removedPositions = new HashSet<>(); @@ -115,8 +112,7 @@ public class SQLRuleManager extends RuleBasedScanner { } @NotNull - public synchronized Set getAddedPositions(boolean clear) - { + public synchronized Set getAddedPositions(boolean clear) { Set posList = addedPositions; if (clear) { addedPositions = new HashSet<>(); @@ -124,8 +120,7 @@ public class SQLRuleManager extends RuleBasedScanner { return posList; } - public void refreshRules(@Nullable DBPDataSource dataSource, @Nullable IEditorInput editorInput) - { + public void refreshRules(@Nullable DBPDataSource dataSource, @Nullable IEditorInput editorInput) { SQLDialect dialect = syntaxManager.getDialect(); SQLRuleProvider ruleProvider = GeneralUtils.adapt(dialect, SQLRuleProvider.class); DBPDataSourceContainer dataSourceContainer = dataSource == null ? null : dataSource.getContainer(); @@ -133,39 +128,39 @@ public class SQLRuleManager extends RuleBasedScanner { boolean minimalRules = SQLEditorBase.isBigScript(editorInput); boolean boldKeywords = dataSource == null ? - DBWorkbench.getPlatform().getPreferenceStore().getBoolean(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS) : - dataSource.getContainer().getPreferenceStore().getBoolean(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS); + DBWorkbench.getPlatform().getPreferenceStore().getBoolean(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS) : + dataSource.getContainer().getPreferenceStore().getBoolean(SQLPreferenceConstants.SQL_FORMAT_BOLD_KEYWORDS); int keywordStyle = boldKeywords ? SWT.BOLD : SWT.NORMAL; /*final Color backgroundColor = null;unassigned || dataSource != null ? getColor(SQLConstants.CONFIG_COLOR_BACKGROUND, SWT.COLOR_WHITE) : getColor(SQLConstants.CONFIG_COLOR_DISABLED, SWT.COLOR_WIDGET_LIGHT_SHADOW);*/ final IToken keywordToken = new Token( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle)); final IToken typeToken = new Token( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_DATATYPE), null, keywordStyle)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_DATATYPE), null, keywordStyle)); final IToken stringToken = new Token( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_STRING), null, SWT.NORMAL)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_STRING), null, SWT.NORMAL)); final IToken quotedToken = new Token( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_DATATYPE), null, SWT.NORMAL)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_DATATYPE), null, SWT.NORMAL)); final IToken numberToken = new Token( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_NUMBER), null, SWT.NORMAL)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_NUMBER), null, SWT.NORMAL)); final IToken commentToken = new SQLCommentToken( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_COMMENT), null, SWT.NORMAL)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_COMMENT), null, SWT.NORMAL)); final SQLDelimiterToken delimiterToken = new SQLDelimiterToken( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_DELIMITER, SWT.COLOR_RED), null, SWT.NORMAL)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_DELIMITER, SWT.COLOR_RED), null, SWT.NORMAL)); final SQLParameterToken parameterToken = new SQLParameterToken( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_PARAMETER, SWT.COLOR_DARK_BLUE), null, keywordStyle)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_PARAMETER, SWT.COLOR_DARK_BLUE), null, keywordStyle)); final SQLVariableToken variableToken = new SQLVariableToken( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_PARAMETER, SWT.COLOR_DARK_BLUE), null, keywordStyle)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_PARAMETER, SWT.COLOR_DARK_BLUE), null, keywordStyle)); final IToken otherToken = new Token( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_TEXT), null, SWT.NORMAL)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_TEXT), null, SWT.NORMAL)); final SQLBlockHeaderToken blockHeaderToken = new SQLBlockHeaderToken( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle)); final SQLBlockBeginToken blockBeginToken = new SQLBlockBeginToken( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle)); final SQLBlockEndToken blockEndToken = new SQLBlockEndToken( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_KEYWORD), null, keywordStyle)); setDefaultReturnToken(otherToken); List rules = new ArrayList<>(); @@ -255,7 +250,7 @@ public class SQLRuleManager extends RuleBasedScanner { String delimRedefine = dialect.getScriptDelimiterRedefiner(); if (!CommonUtils.isEmpty(delimRedefine)) { final SQLSetDelimiterToken setDelimiterToken = new SQLSetDelimiterToken( - new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_COMMAND), null, keywordStyle)); + new TextAttribute(getColor(SQLConstants.CONFIG_COLOR_COMMAND), null, keywordStyle)); rules.add(new SQLDelimiterSetRule(delimRedefine, setDelimiterToken, delimRule)); } @@ -309,13 +304,11 @@ public class SQLRuleManager extends RuleBasedScanner { setRules(result); } - public Color getColor(String colorKey) - { + public Color getColor(String colorKey) { return getColor(colorKey, SWT.COLOR_BLACK); } - public Color getColor(String colorKey, int colorDefault) - { + public Color getColor(String colorKey, int colorDefault) { ITheme currentTheme = themeManager.getCurrentTheme(); Color color = currentTheme.getColorRegistry().get(colorKey); if (color == null) { diff --git a/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/syntax/tokens/SQLTokenType.java b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/syntax/tokens/SQLTokenType.java new file mode 100644 index 0000000000..481f156ddb --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/syntax/tokens/SQLTokenType.java @@ -0,0 +1,56 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org) + * + * Licensed under the Apache License, Version 2.0 (the "License")), + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jkiss.dbeaver.ui.editors.sql.syntax.tokens; + +import org.jkiss.dbeaver.model.text.parser.TPTokenType; + +/** + * SQL token type + */ +public enum SQLTokenType implements TPTokenType { + + T_UNKNOWN(1000), + T_BLOCK_BEGIN(1001), + T_BLOCK_END(1002), + T_BLOCK_TOGGLE(1003), + T_BLOCK_HEADER(1004), + + T_COMMENT(1005), + T_CONTROL(1006), + T_DELIMITER(1007), + T_SET_DELIMITER(1008), + T_PARAMETER(1009), + T_VARIABLE(1010); + + private final int type; + + SQLTokenType(int type) { + this.type = type; + } + + @Override + public int getTokenType() { + return type; + } + + @Override + public String getTypeId() { + return null; + } + +} -- GitLab