1 5 package org.exoplatform.services.grammar.wiki.impl; 6 7 12 public class Token { 13 final static public String DEFAULT_TOKEN = "default" ; 14 final static public String BOLD_TOKEN = "**" ; 15 final static public String ITALIC_TOKEN = "~~" ; 16 final static public String STRIKE_TOKEN = "--" ; 17 final static public String UNDERLINE_TOKEN = "__" ; 18 final static public String HORIZONTAL_LINE_TOKEN = "---" ; 19 final static public String SINGLE_NEW_LINE_TOKEN = "\n" ; 20 final static public String MULTIPLE_NEW_LINE_TOKEN = "\n+" ; 21 final static public String SMILEY_TOKEN = "smiley" ; 22 23 final static public String TITLE_1_TOKEN = "\n 1 " ; 24 final static public String TITLE_1_1_TOKEN = "\n 1.1" ; 25 26 final static public String LINK_TOKEN = "[.+]" ; 27 28 final static public String LIST_LEVEL_1_TOKEN = "\n *" ; 29 final static public String LIST_LEVEL_2_TOKEN = "\n **" ; 30 final static public String LIST_LEVEL_3_TOKEN = "\n ***" ; 31 32 final static public String ENUMERATED_TOKEN = "\n 1." ; 33 final static public String ALPHABETICAL_ENUMERATED_TOKEN = "\n a." ; 34 final static public String ROMAN_ENUMERATED_TOKEN = "\n i." ; 35 36 final static public String CURLY_BRACES_TOKEN = "{.+}" ; 37 38 final static public String SINGLE_TOKEN_GROUP = "single" ; 39 final static public String INLINE_TOKEN_GROUP = "inline" ; 40 final static public String BLOCK_TOKEN_GROUP = "block" ; 41 42 int start ; 43 int end ; 44 String type ; 45 String group ; 46 Token parent ; 47 48 Token(int start, int end) { 49 this.start = start ; 50 this.end = end ; 51 } 52 53 Token(int start, int end, String type) { 54 this.start = start ; 55 this.end = end ; 56 this.type = type ; 57 } 58 59 Token(Token token) { 60 this.start = token.start ; 61 this.end = token.end ; 62 this.type = token.type ; 63 this.group = token.group ; 64 parent = token.parent ; 65 } 66 67 public void clone(Token token) { 68 this.start = token.start ; 69 this.end = token.end ; 70 this.type = token.type ; 71 this.group = token.group ; 72 this.parent = token.parent ; 73 } 74 75 final public String getTokenImage(ParsingContext context) { 76 return context.getSubstring(start, end) ; 77 } 78 79 public String getTokenType() { return type ; } 80 81 public String getTokenGroup() { return group ; } 82 83 public boolean hasAncestor(String type) { 84 Token p = parent ; 85 while(p != null) { 86 if(p.type == type) return true ; 87 p = p.parent ; 88 } 89 return false ; 90 } 91 } | Popular Tags |