Search in sources :

Example 1 with KeyRule

use of org.dadacoalition.yedit.editor.scanner.KeyRule in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonScanner method init.

protected void init() {
    TextAttribute keyAttr = tokenAttribute(PreferenceConstants.COLOR_KEY, PreferenceConstants.BOLD_KEY, PreferenceConstants.ITALIC_KEY, PreferenceConstants.UNDERLINE_KEY);
    IToken keyToken = new YAMLToken(keyAttr, YAMLToken.KEY);
    TextAttribute scalarAttr = tokenAttribute(PreferenceConstants.COLOR_SCALAR, PreferenceConstants.BOLD_SCALAR, PreferenceConstants.ITALIC_SCALAR, PreferenceConstants.UNDERLINE_SCALAR);
    IToken scalarToken = new YAMLToken(scalarAttr, YAMLToken.SCALAR);
    TextAttribute commentAttr = tokenAttribute(PreferenceConstants.COLOR_COMMENT, PreferenceConstants.BOLD_COMMENT, PreferenceConstants.ITALIC_COMMENT, PreferenceConstants.UNDERLINE_COMMENT);
    IToken commentToken = new YAMLToken(commentAttr, YAMLToken.COMMENT);
    TextAttribute documentAttr = tokenAttribute(PreferenceConstants.COLOR_DOCUMENT, PreferenceConstants.BOLD_DOCUMENT, PreferenceConstants.ITALIC_DOCUMENT, PreferenceConstants.UNDERLINE_DOCUMENT);
    IToken documentStartToken = new YAMLToken(documentAttr, YAMLToken.DOCUMENT_START);
    IToken documentEndToken = new YAMLToken(documentAttr, YAMLToken.DOCUMENT_END);
    TextAttribute anchorAttr = tokenAttribute(PreferenceConstants.COLOR_ANCHOR, PreferenceConstants.BOLD_ANCHOR, PreferenceConstants.ITALIC_ANCHOR, PreferenceConstants.UNDERLINE_ANCHOR);
    IToken anchorToken = new YAMLToken(anchorAttr, YAMLToken.ANCHOR);
    TextAttribute aliasAttr = tokenAttribute(PreferenceConstants.COLOR_ALIAS, PreferenceConstants.BOLD_ALIAS, PreferenceConstants.ITALIC_ALIAS, PreferenceConstants.UNDERLINE_ALIAS);
    IToken aliasToken = new YAMLToken(aliasAttr, YAMLToken.ALIAS);
    IToken indicatorCharToken = new YAMLToken(new TextAttribute(null), YAMLToken.INDICATOR_CHARACTER);
    TextAttribute tagAttr = tokenAttribute(PreferenceConstants.COLOR_TAG_PROPERTY, PreferenceConstants.BOLD_TAG_PROPERTY, PreferenceConstants.ITALIC_TAG_PROPERTY, PreferenceConstants.UNDERLINE_TAG_PROPERTY);
    IToken tagPropToken = new YAMLToken(tagAttr, YAMLToken.TAG_PROPERTY);
    TextAttribute constantAttr = tokenAttribute(PreferenceConstants.COLOR_CONSTANT, PreferenceConstants.BOLD_CONSTANT, PreferenceConstants.ITALIC_CONSTANT, PreferenceConstants.UNDERLINE_CONSTANT);
    IToken predefinedValToken = new YAMLToken(constantAttr, YAMLToken.CONSTANT);
    IToken whitespaceToken = new YAMLToken(new TextAttribute(null), YAMLToken.WHITESPACE);
    IToken directiveToken = new YAMLToken(new TextAttribute(null), YAMLToken.DIRECTIVE);
    ArrayList<IRule> rules = new ArrayList<IRule>();
    rules.add(new KeyRule(keyToken));
    rules.add(new SingleQuotedKeyRule(keyToken));
    rules.add(new DoubleQuotedKeyRule(keyToken));
    rules.add(new MultiLineRule("\"", "\"", scalarToken, '\\'));
    rules.add(new MultiLineRule("'", "'", scalarToken));
    rules.add(new EndOfLineRule("#", commentToken));
    rules.add(new EndOfLineRule("%TAG", directiveToken));
    rules.add(new EndOfLineRule("%YAML", directiveToken));
    rules.add(new DocumentStartAndEndRule("---", documentStartToken));
    rules.add(new DocumentStartAndEndRule("...", documentEndToken));
    rules.add(new IndicatorCharacterRule(indicatorCharToken));
    rules.add(new WhitespaceRule(whitespaceToken));
    rules.add(new WordPatternRule(new AnchorWordDetector(), "&", "", anchorToken));
    rules.add(new WordPatternRule(new AnchorWordDetector(), "*", "", aliasToken));
    rules.add(new WordPatternRule(new TagWordDetector(), "!", "", tagPropToken));
    rules.add(new PredefinedValueRule(predefinedValToken));
    rules.add(new ScalarRule(scalarToken));
    IRule[] rulesArray = new IRule[rules.size()];
    rules.toArray(rulesArray);
    setRules(rulesArray);
    setDefaultReturnToken(scalarToken);
}
Also used : WordPatternRule(org.eclipse.jface.text.rules.WordPatternRule) AnchorWordDetector(org.dadacoalition.yedit.editor.scanner.AnchorWordDetector) ScalarRule(org.dadacoalition.yedit.editor.scanner.ScalarRule) TextAttribute(org.eclipse.jface.text.TextAttribute) KeyRule(org.dadacoalition.yedit.editor.scanner.KeyRule) DoubleQuotedKeyRule(org.dadacoalition.yedit.editor.scanner.DoubleQuotedKeyRule) SingleQuotedKeyRule(org.dadacoalition.yedit.editor.scanner.SingleQuotedKeyRule) TagWordDetector(org.dadacoalition.yedit.editor.scanner.TagWordDetector) YAMLToken(org.dadacoalition.yedit.editor.scanner.YAMLToken) ArrayList(java.util.ArrayList) MultiLineRule(org.eclipse.jface.text.rules.MultiLineRule) PredefinedValueRule(org.dadacoalition.yedit.editor.scanner.PredefinedValueRule) WhitespaceRule(org.dadacoalition.yedit.editor.scanner.WhitespaceRule) IRule(org.eclipse.jface.text.rules.IRule) DocumentStartAndEndRule(org.dadacoalition.yedit.editor.scanner.DocumentStartAndEndRule) SingleQuotedKeyRule(org.dadacoalition.yedit.editor.scanner.SingleQuotedKeyRule) DoubleQuotedKeyRule(org.dadacoalition.yedit.editor.scanner.DoubleQuotedKeyRule) IToken(org.eclipse.jface.text.rules.IToken) IndicatorCharacterRule(org.dadacoalition.yedit.editor.scanner.IndicatorCharacterRule) EndOfLineRule(org.eclipse.jface.text.rules.EndOfLineRule)

Aggregations

ArrayList (java.util.ArrayList)1 AnchorWordDetector (org.dadacoalition.yedit.editor.scanner.AnchorWordDetector)1 DocumentStartAndEndRule (org.dadacoalition.yedit.editor.scanner.DocumentStartAndEndRule)1 DoubleQuotedKeyRule (org.dadacoalition.yedit.editor.scanner.DoubleQuotedKeyRule)1 IndicatorCharacterRule (org.dadacoalition.yedit.editor.scanner.IndicatorCharacterRule)1 KeyRule (org.dadacoalition.yedit.editor.scanner.KeyRule)1 PredefinedValueRule (org.dadacoalition.yedit.editor.scanner.PredefinedValueRule)1 ScalarRule (org.dadacoalition.yedit.editor.scanner.ScalarRule)1 SingleQuotedKeyRule (org.dadacoalition.yedit.editor.scanner.SingleQuotedKeyRule)1 TagWordDetector (org.dadacoalition.yedit.editor.scanner.TagWordDetector)1 WhitespaceRule (org.dadacoalition.yedit.editor.scanner.WhitespaceRule)1 YAMLToken (org.dadacoalition.yedit.editor.scanner.YAMLToken)1 TextAttribute (org.eclipse.jface.text.TextAttribute)1 EndOfLineRule (org.eclipse.jface.text.rules.EndOfLineRule)1 IRule (org.eclipse.jface.text.rules.IRule)1 IToken (org.eclipse.jface.text.rules.IToken)1 MultiLineRule (org.eclipse.jface.text.rules.MultiLineRule)1 WordPatternRule (org.eclipse.jface.text.rules.WordPatternRule)1