diff options
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java new file mode 100644 index 0000000..223a25d --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java | |||
@@ -0,0 +1,94 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright (c) 2009 Ken Gilmer | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Ken Gilmer - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.bc.ui.editors.bitbake; | ||
12 | |||
13 | import org.eclipse.jface.text.rules.ICharacterScanner; | ||
14 | import org.eclipse.jface.text.rules.IRule; | ||
15 | import org.eclipse.jface.text.rules.IToken; | ||
16 | import org.eclipse.jface.text.rules.Token; | ||
17 | |||
18 | /** | ||
19 | * Rule for def_ BB Recipe functions | ||
20 | * @author kgilmer | ||
21 | * | ||
22 | */ | ||
23 | final class CustomFunctionRule implements IRule { | ||
24 | |||
25 | /** Token to return for this rule */ | ||
26 | private final IToken fToken; | ||
27 | |||
28 | /** | ||
29 | * Creates a new operator rule. | ||
30 | * | ||
31 | * @param token | ||
32 | * Token to use for this rule | ||
33 | */ | ||
34 | public CustomFunctionRule(IToken token) { | ||
35 | fToken = token; | ||
36 | } | ||
37 | |||
38 | public IToken evaluate(ICharacterScanner scanner) { | ||
39 | if (scanner.getColumn() > 0) { | ||
40 | return Token.UNDEFINED; | ||
41 | } | ||
42 | |||
43 | int i = scanner.read(); | ||
44 | int c = 1; | ||
45 | |||
46 | if (!Character.isLetter(i) && i != 10) { | ||
47 | scanner.unread(); | ||
48 | return Token.UNDEFINED; | ||
49 | } | ||
50 | |||
51 | if (i == 'd' && scanAhead(scanner, "o_".toCharArray())) { | ||
52 | scanner.unread(); | ||
53 | return Token.UNDEFINED; | ||
54 | } | ||
55 | |||
56 | while (i != ICharacterScanner.EOF && i != 10) { | ||
57 | i = scanner.read(); | ||
58 | c++; | ||
59 | |||
60 | if (i == '(') { | ||
61 | readUntil(scanner, ')'); | ||
62 | |||
63 | return fToken; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | for (int t = 0; t < c; t++) { | ||
68 | scanner.unread(); | ||
69 | } | ||
70 | |||
71 | return Token.UNDEFINED; | ||
72 | } | ||
73 | |||
74 | private void readUntil(ICharacterScanner scanner, int c) { | ||
75 | int i; | ||
76 | do { | ||
77 | i = scanner.read(); | ||
78 | } while (! (i == ICharacterScanner.EOF) && ! (i == c)); | ||
79 | } | ||
80 | |||
81 | private boolean scanAhead(ICharacterScanner scanner, char [] chars) { | ||
82 | boolean v = true; | ||
83 | for (int i = 0; i < chars.length; ++i) { | ||
84 | if (! (scanner.read() == chars[i])) { | ||
85 | v = false; | ||
86 | for (int j = 0; j < i; ++j) { | ||
87 | scanner.unread(); | ||
88 | } | ||
89 | break; | ||
90 | } | ||
91 | } | ||
92 | return v; | ||
93 | } | ||
94 | } \ No newline at end of file | ||