From c7da892cb23d50d4d85746c9a0b6b14bf570989d Mon Sep 17 00:00:00 2001 From: Adrian Dudau Date: Thu, 26 Jun 2014 13:23:09 +0200 Subject: initial commit for Enea Linux 4.0 Migrated from the internal git server on the daisy-enea branch Signed-off-by: Adrian Dudau --- .../bc/ui/editors/bitbake/CustomFunctionRule.java | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/editors/bitbake/CustomFunctionRule.java') 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 @@ +/***************************************************************************** + * Copyright (c) 2009 Ken Gilmer + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ken Gilmer - initial API and implementation + *******************************************************************************/ +package org.yocto.bc.ui.editors.bitbake; + +import org.eclipse.jface.text.rules.ICharacterScanner; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.Token; + +/** + * Rule for def_ BB Recipe functions + * @author kgilmer + * + */ +final class CustomFunctionRule implements IRule { + + /** Token to return for this rule */ + private final IToken fToken; + + /** + * Creates a new operator rule. + * + * @param token + * Token to use for this rule + */ + public CustomFunctionRule(IToken token) { + fToken = token; + } + + public IToken evaluate(ICharacterScanner scanner) { + if (scanner.getColumn() > 0) { + return Token.UNDEFINED; + } + + int i = scanner.read(); + int c = 1; + + if (!Character.isLetter(i) && i != 10) { + scanner.unread(); + return Token.UNDEFINED; + } + + if (i == 'd' && scanAhead(scanner, "o_".toCharArray())) { + scanner.unread(); + return Token.UNDEFINED; + } + + while (i != ICharacterScanner.EOF && i != 10) { + i = scanner.read(); + c++; + + if (i == '(') { + readUntil(scanner, ')'); + + return fToken; + } + } + + for (int t = 0; t < c; t++) { + scanner.unread(); + } + + return Token.UNDEFINED; + } + + private void readUntil(ICharacterScanner scanner, int c) { + int i; + do { + i = scanner.read(); + } while (! (i == ICharacterScanner.EOF) && ! (i == c)); + } + + private boolean scanAhead(ICharacterScanner scanner, char [] chars) { + boolean v = true; + for (int i = 0; i < chars.length; ++i) { + if (! (scanner.read() == chars[i])) { + v = false; + for (int j = 0; j < i; ++j) { + scanner.unread(); + } + break; + } + } + return v; + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf