X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java index bebcc1f..85aa0d2 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java @@ -33,15 +33,16 @@ public class PHPPartitionScanner extends RuleBasedPartitionScanner { public final static String HTML_MULTILINE_COMMENT = "__html_multiline_comment"; //$NON-NLS-1$ // public final static String JAVA_DOC= "__java_javadoc"; //$NON-NLS-1$ public final static String PHP = "__php"; -// public final static String HTML = "__html"; + // public final static String HTML = "__html"; public final static IToken php = new Token(PHP); -// public final static IToken html = new Token(HTML); + // public final static IToken html = new Token(HTML); public final static IToken comment = new Token(HTML_MULTILINE_COMMENT); protected final static char[] php0EndSequence = { '<', '?' }; protected final static char[] php1EndSequence = { '<', '?', 'p', 'h', 'p' }; protected final static char[] php2EndSequence = { '<', '?', 'P', 'H', 'P' }; + private StringBuffer test; public class PHPMultiLineRule extends MultiLineRule { @@ -64,48 +65,65 @@ public class PHPPartitionScanner extends RuleBasedPartitionScanner { char[][] delimiters = scanner.getLegalLineDelimiters(); while ((c = scanner.read()) != ICharacterScanner.EOF) { - if (lineCommentMode && (c == '\n')) { - lineCommentMode = false; - // read until end of line - } else if ((!stringMode) && (c == '#')) { + if (c == '#') { // read until end of line - lineCommentMode = true; - continue; - } else if ((!stringMode) && (!multiLineCommentMode) && (c == '/')) { - c2 = scanner.read(); - if (c2 == '/') { - lineCommentMode = true; - continue; - } else if (c2 == '*') { - multiLineCommentMode = true; - continue; - } else { - scanner.unread(); + while ((c = scanner.read()) != ICharacterScanner.EOF) { + if (fEndSequence.length > 0 && c == fEndSequence[0]) { + // Check if the specified end sequence has been found. + if (sequenceDetected(scanner, fEndSequence, true)) + return true; + } else if (c == '\n') { + break; + } } - } else if (c == '*' && multiLineCommentMode) { - c2 = scanner.read(); - if (c2 == '/') { - multiLineCommentMode = false; + continue; + } else if (c == '/' && (c = scanner.read()) != ICharacterScanner.EOF) { + if (c == '/') { + // read until end of line + while ((c = scanner.read()) != ICharacterScanner.EOF) { + if (fEndSequence.length > 0 && c == fEndSequence[0]) { + // Check if the specified end sequence has been found. + if (sequenceDetected(scanner, fEndSequence, true)) + return true; + } else if (c == '\n') { + break; + } + } continue; - } else { - scanner.unread(); - } - } else if (c == '\\' && stringMode) { - c2 = scanner.read(); - if (c2 == '"') { + } else if (c == '*') { + // multi-line comment + while ((c = scanner.read()) != ICharacterScanner.EOF) { + if (c == '*' && (c = scanner.read()) != ICharacterScanner.EOF) { + if (c == '/') { + break; + } + scanner.unread(); + } + } + continue; } else { scanner.unread(); } - } else if ((!lineCommentMode) && (!multiLineCommentMode) && (c == '"')) { - if (stringMode) { - stringMode = false; - } else { - stringMode = true; + } else if (c == '"') { + // string mode + while ((c = scanner.read()) != ICharacterScanner.EOF) { + if (c == '\\') { + c = scanner.read(); + } else if (c == '"') { + break; + } } continue; - } - if (lineCommentMode || multiLineCommentMode || stringMode) { + } else if (c == '\'') { + // string mode + while ((c = scanner.read()) != ICharacterScanner.EOF) { + if (c == '\\') { + c = scanner.read(); + } else if (c == '\'') { + break; + } + } continue; } @@ -123,95 +141,99 @@ public class PHPPartitionScanner extends RuleBasedPartitionScanner { return true; } } + } + boolean phpMode = false; + if (c == ICharacterScanner.EOF) { + phpMode = true; } scanner.unread(); - return false; + return phpMode; } } -// public class HTMLMultiLineRule extends MultiLineRule { -// -// public HTMLMultiLineRule(String startSequence, String endSequence, IToken token) { -// super(startSequence, endSequence, token); -// } -// -// public HTMLMultiLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter) { -// super(startSequence, endSequence, token, escapeCharacter); -// } -// -// protected boolean endSequenceDetected(ICharacterScanner scanner) { -// int c; -// -// char[][] delimiters = scanner.getLegalLineDelimiters(); -// while ((c = scanner.read()) != ICharacterScanner.EOF) { -// if (c == '<') { -// // scanner.unread(); -// if (sequenceDetected(scanner, php2EndSequence, true)) { -// // ", php)); rules.add(new PHPMultiLineRule("", php)); -// rules.add(new HTMLPatternRule(html)); // "<", "