提交 b2a94dc7 authored 作者: Thomas Mueller's avatar Thomas Mueller

H2 Console: auto-complete did not work with multi-line statements.

上级 573c2c5d
...@@ -138,6 +138,16 @@ public class Bnf { ...@@ -138,6 +138,16 @@ public class Bnf {
rule.accept(visitor); rule.accept(visitor);
} }
/**
* Check whether the statement starts with a whitespace.
*
* @param s the statement
* @return if the statement is not empty and starts with a whitespace
*/
public static boolean startWithSpace(String s) {
return s.length() > 0 && Character.isWhitespace(s.charAt(0));
}
/** /**
* Convert convert ruleLink to rule_link. * Convert convert ruleLink to rule_link.
* *
......
...@@ -61,7 +61,7 @@ public class RuleElement implements Rule { ...@@ -61,7 +61,7 @@ public class RuleElement implements Rule {
String up = sentence.getQueryUpper().trim(); String up = sentence.getQueryUpper().trim();
if (up.startsWith(name)) { if (up.startsWith(name)) {
query = query.substring(name.length()); query = query.substring(name.length());
while (!"_".equals(name) && query.length() > 0 && Character.isSpaceChar(query.charAt(0))) { while (!"_".equals(name) && Bnf.startWithSpace(query)) {
query = query.substring(1); query = query.substring(1);
} }
sentence.setQuery(query); sentence.setQuery(query);
......
...@@ -111,7 +111,7 @@ public class RuleFixed implements Rule { ...@@ -111,7 +111,7 @@ public class RuleFixed implements Rule {
} }
break; break;
case ANY_WORD: case ANY_WORD:
while (s.length() > 0 && !Character.isSpaceChar(s.charAt(0))) { while (s.length() > 0 && !Bnf.startWithSpace(s)) {
s = s.substring(1); s = s.substring(1);
} }
if (s.length() == 0) { if (s.length() == 0) {
...@@ -185,7 +185,7 @@ public class RuleFixed implements Rule { ...@@ -185,7 +185,7 @@ public class RuleFixed implements Rule {
throw new AssertionError("type="+type); throw new AssertionError("type="+type);
} }
if (!s.equals(query)) { if (!s.equals(query)) {
while (s.length() > 0 && Character.isSpaceChar(s.charAt(0))) { while (Bnf.startWithSpace(s)) {
s = s.substring(1); s = s.substring(1);
} }
sentence.setQuery(s); sentence.setQuery(s);
......
...@@ -8,6 +8,8 @@ package org.h2.bnf.context; ...@@ -8,6 +8,8 @@ package org.h2.bnf.context;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import org.h2.bnf.Bnf;
import org.h2.bnf.BnfVisitor; import org.h2.bnf.BnfVisitor;
import org.h2.bnf.Rule; import org.h2.bnf.Rule;
import org.h2.bnf.RuleElement; import org.h2.bnf.RuleElement;
...@@ -218,7 +220,7 @@ public class DbContextRule implements Rule { ...@@ -218,7 +220,7 @@ public class DbContextRule implements Rule {
throw DbException.throwInternalError("type=" + type); throw DbException.throwInternalError("type=" + type);
} }
if (!s.equals(query)) { if (!s.equals(query)) {
while (s.length() > 0 && Character.isSpaceChar(s.charAt(0))) { while (Bnf.startWithSpace(s)) {
s = s.substring(1); s = s.substring(1);
} }
sentence.setQuery(s); sentence.setQuery(s);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论