Search in sources :

Example 1 with RuleFixed

use of org.h2.bnf.RuleFixed in project jackrabbit-oak by apache.

the class BnfSyntax method getLink.

/**
 * Get the HTML link to the given token.
 *
 * @param bnf the BNF
 * @param token the token
 * @return the HTML link
 */
String getLink(Bnf bnf, String token) {
    RuleHead found = null;
    String key = Bnf.getRuleMapKey(token);
    for (int i = 0; i < token.length(); i++) {
        String test = StringUtils.toLowerEnglish(key.substring(i));
        RuleHead r = bnf.getRuleHead(test);
        if (r != null) {
            found = r;
            break;
        }
    }
    if (found == null) {
        return token;
    }
    if (found.getRule() instanceof RuleFixed) {
        found.getRule().accept(this);
        return html;
    }
    String link = found.getTopic().toLowerCase().replace(' ', '_');
    link = "#" + StringUtils.urlEncode(link);
    return "<a href=\"" + link + "\">" + token + "</a>";
}
Also used : RuleFixed(org.h2.bnf.RuleFixed) RuleHead(org.h2.bnf.RuleHead)

Example 2 with RuleFixed

use of org.h2.bnf.RuleFixed in project h2database by h2database.

the class Bnf method addFixedRule.

private void addFixedRule(String name, int fixedType) {
    Rule rule = new RuleFixed(fixedType);
    addRule(name, "Fixed", rule);
}
Also used : DbContextRule(org.h2.bnf.context.DbContextRule)

Example 3 with RuleFixed

use of org.h2.bnf.RuleFixed in project h2database by h2database.

the class BnfSyntax method getLink.

/**
 * Get the HTML link to the given token.
 *
 * @param bnf the BNF
 * @param token the token
 * @return the HTML link
 */
String getLink(Bnf bnf, String token) {
    RuleHead found = null;
    String key = Bnf.getRuleMapKey(token);
    for (int i = 0; i < token.length(); i++) {
        String test = StringUtils.toLowerEnglish(key.substring(i));
        RuleHead r = bnf.getRuleHead(test);
        if (r != null) {
            found = r;
            break;
        }
    }
    if (found == null) {
        return token;
    }
    String page = "grammar.html";
    if (found.getSection().startsWith("Data Types")) {
        page = "datatypes.html";
    } else if (found.getSection().startsWith("Functions")) {
        page = "functions.html";
    } else if (token.equals("@func@")) {
        return "<a href=\"functions.html\">Function</a>";
    } else if (found.getRule() instanceof RuleFixed) {
        found.getRule().accept(this);
        return html;
    }
    String link = found.getTopic().toLowerCase().replace(' ', '_');
    link = page + "#" + StringUtils.urlEncode(link);
    return "<a href=\"" + link + "\">" + token + "</a>";
}
Also used : RuleFixed(org.h2.bnf.RuleFixed) RuleHead(org.h2.bnf.RuleHead)

Aggregations

RuleFixed (org.h2.bnf.RuleFixed)2 RuleHead (org.h2.bnf.RuleHead)2 DbContextRule (org.h2.bnf.context.DbContextRule)1