|
1 | 1 | # CodeEditor |
2 | 2 | A professional code editor on Android device with highlight and auto completion. |
3 | | -***Work In Progress*** This project is still developing slowly because of school. |
4 | | -***Note:*** This project is moving fast. |
5 | | -Source code in branch `master` will be a much stable version which can run smoothly (but will be overwrite as long as code in `dev` branch is tested) while branch `dev` can be unstable. |
6 | | -Any method or field can be changed and moved or even deleted. |
7 | | -And it also have to do more tests on different devices. |
| 3 | +***Work In Progress*** This project is still developing slowly because of school.Bugs may be inside. |
| 4 | +***Note:*** |
| 5 | +Code in branch `master` will be a stabler version which can run without a lot problems (but sometimes there might be some important problems that has been solved in `dev`). |
| 6 | +Branch `dev` has newest features in editor and is developing. |
| 7 | +Any non-public method or field can be changed and moved or even deleted. |
8 | 8 | If you find any exception please send it to me. |
| 9 | + |
9 | 10 | See Projects/CodeEditor to get more information about what I am working on. |
10 | 11 | Issues and pull requests are welcome. |
11 | 12 | If you are unable to compile this project or crash while using sample app, try to rollback to any previous version. |
@@ -36,147 +37,5 @@ To include this project into your project: |
36 | 37 | * Copy `editor` module into your project and add it to your module's dependency. |
37 | 38 | * Copy `language-base` if you want to use languages we have created. Otherwise, you have done the process. |
38 | 39 | * Copy `language-java` , `language-s5d` , `language-universal` into your project if required. |
39 | | -## How to customize your language for editor |
40 | | -### A Simple Method |
41 | | -You just have to implement a `LanguageDescription`! |
42 | | -See the interface in `/language-universal/src/main/java/io/github/rosemoe/editor/langs/universal/LanguageDescription` to get more information about it. |
43 | | -There is also some implementations in `/language-universal/src/main/java/io/github/rosemoe/editor/langs/desc/`. You can view them and learn how to implement one by yourself. |
44 | | -This way supports: Highlight(Keywords,Comments,Operators,Literals), Code block lines |
45 | | -This method is quite simple for everyone, but it will have some limits that are annoying. |
46 | | -If you want to get advanced features of CodeEditor, you'd better use the followig method. |
47 | | -### Advanced Method - For experts |
48 | | -* Make a lexer for the language (Use JFlex or ANTLR to analyze code and highlight. JFlex is recommended) |
49 | | -[ANTLR Website](https://www.antlr.org/) |
50 | | -[ANTLR4 Repository](https://github.com/antlr/antlr4) |
51 | | -[Grammars for ANTLR4](https://github.com/antlr/grammars-v4) |
52 | | -[JFLex Website](https://jflex.de/) |
53 | | -[JFLex Repository](https://github.com/jflex-de/jflex) |
54 | | -You may obtain a example flex for Java in ThisRepo/jflex/ |
55 | | -* Implement a CodeAnalyzer: |
56 | | -```Java |
57 | | -public class XxxCodeAnalyzer { |
58 | | - |
59 | | - public void analyze(CharSequence content, TextAnalyzer.TextColors colors, TextAnalyzer.AnalyzeThread.Delegate delegate) { |
60 | | - //Analyze code here(Use your Lexer) |
61 | | - //Use colors.addIfNeeded() to add a new span if required |
62 | | - //Use colors.add() to add a new span forcely |
63 | | - //Use colors.addBlockLine() to add a new code block line |
64 | | - //Use colors.setNavigation() to specify navigation list |
65 | | - //Assign colors.mExtra to pass your information to AutoCompleteProvider module |
66 | | - |
67 | | - //Note that you should stop when delegate.shouldAnalyze() returns false. |
68 | | - //... |
69 | | - } |
70 | | - |
71 | | -} |
72 | | -``` |
73 | | -* Create an AutoCompleteProvider: |
74 | | -You have two choices: |
75 | | -A.Implement a AutoCompleteProvider by your self |
76 | | -```Java |
77 | | -public class XxxAutoComplete { |
78 | | - |
79 | | - public List<ResultItem> getAutoCompleteItems(String prefix, boolean isInCodeBlock, TextColorProvider.TextColors colors, int line) { |
80 | | - //Match items here |
81 | | - //How to match is up to you (contains/startsWith/toLowerCase...) |
82 | | - //You can get information from last analysis by colors.mExtra |
83 | | - //This value can be null |
84 | | - //... |
85 | | - |
86 | | - //You are unexpected to return null(May cause crash) |
87 | | - return ...; |
88 | | - } |
89 | | - |
90 | | -} |
91 | | -``` |
92 | | -B.Use a simple AutoCompleteProvider implementation -- IdentifierAutoComplete |
93 | | -This can only match your given word case insensitively by using startsWith(). |
94 | | -And you should use IdentifierAutoComplete.Identifiers as extra data from CodeAnalyzer or there will not be any effect. |
95 | | -Sample: |
96 | | -```Java |
97 | | -IdentifierAutoComplete autoComplete = new IdentifierAutoComplete(); |
98 | | -String[] keywords = new String[]{"public","private","protected"}; |
99 | | -//True if your all of keywords are in small case |
100 | | -autoComplete.setKeywords(keywords,true); |
101 | | -``` |
102 | | -And in your CodeAnalyzer: |
103 | | -```Java |
104 | | -public class XxxCodeAnalyzer { |
105 | | - |
106 | | - public void analyze(CharSequence content, TextAnalyzer.TextColors colors, TextAnalyzer.AnalyzeThread.Delegate delegate) { |
107 | | - XxxTokenizer tokenizer = ...; |
108 | | - ... |
109 | | - IdentifierAutoComplete.Identifiers identifiers = new IdentifierAutoComplete.Identifiers(); |
110 | | - identifiers.begin(); |
111 | | - while(...) { |
112 | | - switch(...) { |
113 | | - ... |
114 | | - case IDENTIFIER: |
115 | | - identifiers.addIdentifier(tokenizer.getTokenText()); |
116 | | - ... |
117 | | - break; |
118 | | - ... |
119 | | - } |
120 | | - } |
121 | | - identifiers.finish(); |
122 | | - colors.mExtra = identifiers; |
123 | | - ... |
124 | | - } |
125 | | - |
126 | | -} |
127 | | -``` |
128 | | -Note that repeat identifier will not be added. |
129 | | -And you must call begin() before you call addIdentifier(). |
130 | | -Remember to call finish() after all addIdentifier() actions done.(This will free some space) |
131 | | -* Implement your formatter (Optional) |
132 | | -Use lexer/tokenizer to create a formatter for your language. |
133 | | -* Implement EditorLanguage: |
134 | | -```Java |
135 | | -public class MyLanguage implements EditorLanguage { |
136 | | - |
137 | | - public CodeAnalyzer getAnalyzer() { |
138 | | - //NonNull or crash |
139 | | - return new XxxCodeAnalyzer(); |
140 | | - } |
141 | | - |
142 | | - public AutoCompleteProvider getAutoCompleteProvider() { |
143 | | - //NonNull or crash |
144 | | - return new XxxAutoComplete(); |
145 | | - //Or |
146 | | - IdentifierAutoComplete autoComplete = new IdentifierAutoComplete(); |
147 | | - String[] keywords = new String[]{"public","private","protected"}; |
148 | | - //True if your all of keywords are in small case |
149 | | - autoComplete.setKeywords(keywords,true); |
150 | | - return autoComplete; |
151 | | - } |
152 | | - |
153 | | - public boolean isAutoCompleteChar(char ch) { |
154 | | - //This is up to your. |
155 | | - //We will search character from the tail of insert position |
156 | | - //The default implementation is Character#isJavaIdentifierPart(char) |
157 | | - } |
158 | | - |
159 | | - public int getIndentAdvance(String content) { |
160 | | - //This is will be called when a newline is at start of input |
161 | | - //And you will receive text on current line before cursor |
162 | | - //The return value is counted as space |
163 | | - } |
164 | | - |
165 | | - public boolean useTab() { |
166 | | - //Whether we use tab to indent |
167 | | - //And how many spaces can tab replace is related to editor's settings |
168 | | - } |
169 | | - |
170 | | - public CharSequence format(CharSequence text) { |
171 | | - //Format code |
172 | | - //You should return formatted code |
173 | | - //If you can not,just return the given text |
174 | | - } |
175 | | -} |
176 | | -``` |
177 | | -* Apply your language |
178 | | -It's very simple: |
179 | | -```Java |
180 | | -editor.setEditorLanguage(yourLanguage); |
181 | | -``` |
182 | | -All things after will be done in a minute by editor |
| 40 | +## More information |
| 41 | +Turn to wiki page. |
0 commit comments