* Created on 05.03.2003
*
* @author Stefan Langer (musk)
- * @version $Revision: 1.21 $
+ * @version $Revision: 1.24 $
*/
package net.sourceforge.phpeclipse.phpeditor.php;
import java.util.HashMap;
import java.util.Map;
+import net.sourceforge.phpdt.internal.ui.text.*;
+
import org.eclipse.jface.text.Assert;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
private boolean fInDoubString = false;
private IDocument fDocument = null;
private int fOffset = -1;
- private String fContentType = IPHPPartitionScannerConstants.HTML;
- private String fPrevContentType = IPHPPartitionScannerConstants.HTML;
+ private String fContentType = IPHPPartitions.HTML;
+ private String fPrevContentType = IPHPPartitions.HTML;
private boolean partitionBorder = false;
private int fTokenOffset;
private int fEnd = -1;
private int fFileType;
private Map tokens = new HashMap();
+ public PHPPartitionScanner() {
+ this(IPHPPartitions.PHP_FILE);
+ }
+
public PHPPartitionScanner(int fileType) {
- this.tokens.put(IPHPPartitionScannerConstants.PHP, new Token(IPHPPartitionScannerConstants.PHP));
+ this.tokens.put(IPHPPartitions.PHP_PARTITIONING, new Token(IPHPPartitions.PHP_PARTITIONING));
+ this.tokens.put(IPHPPartitions.PHP_STRING_DQ, new Token(IPHPPartitions.PHP_STRING_DQ));
this.tokens.put(
- IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
- new Token(IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT));
- this.tokens.put(IPHPPartitionScannerConstants.HTML, new Token(IPHPPartitionScannerConstants.HTML));
+ IPHPPartitions.PHP_PHPDOC_COMMENT,
+ new Token(IPHPPartitions.PHP_PHPDOC_COMMENT));
+ this.tokens.put(IPHPPartitions.HTML, new Token(IPHPPartitions.HTML));
this.tokens.put(
- IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
- new Token(IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT));
+ IPHPPartitions.HTML_MULTILINE_COMMENT,
+ new Token(IPHPPartitions.HTML_MULTILINE_COMMENT));
- this.tokens.put(IPHPPartitionScannerConstants.SMARTY, new Token(IPHPPartitionScannerConstants.SMARTY));
+ this.tokens.put(IPHPPartitions.SMARTY, new Token(IPHPPartitions.SMARTY));
this.tokens.put(
- IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT,
- new Token(IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT));
+ IPHPPartitions.SMARTY_MULTILINE_COMMENT,
+ new Token(IPHPPartitions.SMARTY_MULTILINE_COMMENT));
this.tokens.put(IDocument.DEFAULT_CONTENT_TYPE, new Token(IDocument.DEFAULT_CONTENT_TYPE));
fFileType = fileType;
while ((c = read()) != ICharacterScanner.EOF) {
switch (c) {
case '<' :
- if (!isInString(IPHPPartitionScannerConstants.PHP)
- && fContentType != IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT
+ if (!isInString(IPHPPartitions.PHP_PARTITIONING)
+ && fContentType != IPHPPartitions.PHP_PHPDOC_COMMENT
&& checkPattern(new char[] { '?', 'p', 'h', 'p' }, true)) {
- if (fContentType != IPHPPartitionScannerConstants.PHP && fCurrentLength > 5) {
+ if (fContentType != IPHPPartitions.PHP_PARTITIONING && fCurrentLength > 5) {
unread(5);
IToken token = getToken(fContentType);
// save previouse contenttype
//TODO build stack for previouse contenttype
fPrevContentType = fContentType;
- fContentType = IPHPPartitionScannerConstants.PHP;
+ fContentType = IPHPPartitions.PHP_PARTITIONING;
return token;
} else
- fContentType = IPHPPartitionScannerConstants.PHP;
+ fContentType = IPHPPartitions.PHP_PARTITIONING;
// remember offset of this partition
fTokenOffset = fOffset - 5;
fCurrentLength = 5;
} else if (
- !isInString(IPHPPartitionScannerConstants.PHP)
- && fContentType != IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT
+ !isInString(IPHPPartitions.PHP_PARTITIONING)
+ && fContentType != IPHPPartitions.PHP_PHPDOC_COMMENT
&& checkPattern(new char[] { '?' }, false)) {
- if (fContentType != IPHPPartitionScannerConstants.PHP && fCurrentLength > 2) {
+ if (fContentType != IPHPPartitions.PHP_PARTITIONING && fCurrentLength > 2) {
unread(2);
IToken token = getToken(fContentType);
// save previouse contenttype
fPrevContentType = fContentType;
- fContentType = IPHPPartitionScannerConstants.PHP;
+ fContentType = IPHPPartitions.PHP_PARTITIONING;
return token;
} else
- fContentType = IPHPPartitionScannerConstants.PHP;
+ fContentType = IPHPPartitions.PHP_PARTITIONING;
// remember offset of this partition
fTokenOffset = fOffset - 2;
fCurrentLength = 2;
} else if (
- !isInString(IPHPPartitionScannerConstants.PHP)
- && (fContentType != IPHPPartitionScannerConstants.PHP) // BUG #769044
- && (fContentType != IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT) // BUG #769044
+ !isInString(IPHPPartitions.PHP_PARTITIONING)
+ && (fContentType != IPHPPartitions.PHP_PARTITIONING) // BUG #769044
+ && (fContentType != IPHPPartitions.PHP_PHPDOC_COMMENT) // BUG #769044
&& checkPattern(new char[] { '!', '-', '-' })) { // return previouse partition
- if (fContentType != IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT && fCurrentLength > 4) {
+ if (fContentType != IPHPPartitions.HTML_MULTILINE_COMMENT && fCurrentLength > 4) {
unread(4);
IToken token = getToken(fContentType);
- fContentType = IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT;
+ fContentType = IPHPPartitions.HTML_MULTILINE_COMMENT;
return token;
} else
- fContentType = IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT;
+ fContentType = IPHPPartitions.HTML_MULTILINE_COMMENT;
fTokenOffset = fOffset - 4;
fCurrentLength = 4;
}
break;
case '?' :
- if (!isInString(IPHPPartitionScannerConstants.PHP) && fContentType == IPHPPartitionScannerConstants.PHP) {
+ if (!isInString(IPHPPartitions.PHP_PARTITIONING) && fContentType == IPHPPartitions.PHP_PARTITIONING) {
if ((c = read()) == '>') {
if (fPrevContentType != null)
fContentType = fPrevContentType;
else
- fContentType = IPHPPartitionScannerConstants.HTML;
+ fContentType = IPHPPartitions.HTML;
partitionBorder = true;
- return getToken(IPHPPartitionScannerConstants.PHP);
+ return getToken(IPHPPartitions.PHP_PARTITIONING);
} else if (c != ICharacterScanner.EOF)
unread();
}
break;
case '-' :
- if (!isInString(IPHPPartitionScannerConstants.PHP)
- && fContentType == IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT
+ if (!isInString(IPHPPartitions.PHP_PARTITIONING)
+ && fContentType == IPHPPartitions.HTML_MULTILINE_COMMENT
&& checkPattern(new char[] { '-', '>' })) {
- fContentType = IPHPPartitionScannerConstants.HTML;
+ fContentType = IPHPPartitions.HTML;
partitionBorder = true;
- return getToken(IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT);
+ return getToken(IPHPPartitions.HTML_MULTILINE_COMMENT);
}
break;
case '{' : // SMARTY code starts here ?
- if (fFileType == IPHPPartitionScannerConstants.SMARTY_FILE) {
+ if (fFileType == IPHPPartitions.SMARTY_FILE) {
if ((c = read()) == '*') {
if (DEBUG) {
System.out.println(
+ " fCurrentLength="
+ fCurrentLength);
}
- if (fContentType != IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT && fCurrentLength > 2) {
+ if (fContentType != IPHPPartitions.SMARTY_MULTILINE_COMMENT && fCurrentLength > 2) {
// SMARTY doc code starts here
unread(2);
IToken token = getToken(fContentType);
- fContentType = IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT;
+ fContentType = IPHPPartitions.SMARTY_MULTILINE_COMMENT;
return token;
// } else if (fContentType == IPHPPartitionScannerConstants.HTML && fOffset == 2) {
// fContentType = IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT;
} else { // if (fContentType == IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT) {
- fContentType = IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT;
+ fContentType = IPHPPartitions.SMARTY_MULTILINE_COMMENT;
fTokenOffset = fOffset - 2;
fCurrentLength = 2;
}
if (c != ICharacterScanner.EOF) {
unread();
}
- if (fContentType != IPHPPartitionScannerConstants.SMARTY && fCurrentLength > 1) {
+ if (fContentType != IPHPPartitions.SMARTY && fCurrentLength > 1) {
unread(1);
IToken token = getToken(fContentType);
- fContentType = IPHPPartitionScannerConstants.SMARTY;
+ fContentType = IPHPPartitions.SMARTY;
return token;
// } else if (fContentType == IPHPPartitionScannerConstants.HTML && fOffset==1) {
// fContentType = IPHPPartitionScannerConstants.SMARTY;
} else {
- fContentType = IPHPPartitionScannerConstants.SMARTY;
+ fContentType = IPHPPartitions.SMARTY;
fTokenOffset = fOffset - 1;
fCurrentLength = 1;
}
}
break;
case '}' : // SMARTY code ends here ?
- if (fFileType == IPHPPartitionScannerConstants.SMARTY_FILE && fContentType == IPHPPartitionScannerConstants.SMARTY) {
+ if (fFileType == IPHPPartitions.SMARTY_FILE && fContentType == IPHPPartitions.SMARTY) {
if (DEBUG) {
System.out.println(
"SMARTY_TOKEN end "
+ " fOffset="
+ fOffset);
}
- fContentType = IPHPPartitionScannerConstants.HTML;
+ fContentType = IPHPPartitions.HTML;
partitionBorder = true;
- return getToken(IPHPPartitionScannerConstants.SMARTY);
+ return getToken(IPHPPartitions.SMARTY);
}
break;
case '/' :
- if (!isInString(IPHPPartitionScannerConstants.PHP) && (c = read()) == '*') { // MULTINE COMMENT JAVASCRIPT, CSS, PHP
- if (fContentType == IPHPPartitionScannerConstants.PHP && fCurrentLength > 2) {
+ if (!isInString(IPHPPartitions.PHP_PARTITIONING) && (c = read()) == '*') { // MULTINE COMMENT JAVASCRIPT, CSS, PHP
+ if (fContentType == IPHPPartitions.PHP_PARTITIONING && fCurrentLength > 2) {
unread(2);
IToken token = getToken(fContentType);
- fContentType = IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT;
+ fContentType = IPHPPartitions.PHP_PHPDOC_COMMENT;
return token;
- } else if (fContentType == IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT) {
+ } else if (fContentType == IPHPPartitions.PHP_PHPDOC_COMMENT) {
fTokenOffset = fOffset - 2;
fCurrentLength = 2;
}
- } else if (!isInString(IPHPPartitionScannerConstants.PHP) && c != ICharacterScanner.EOF)
+ } else if (!isInString(IPHPPartitions.PHP_PARTITIONING) && c != ICharacterScanner.EOF)
unread();
break;
case '*' :
- if (!isInString(IPHPPartitionScannerConstants.PHP) && (c = read()) == '/') {
- if (fContentType == IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT) {
- fContentType = IPHPPartitionScannerConstants.PHP;
+ if (!isInString(IPHPPartitions.PHP_PARTITIONING) && (c = read()) == '/') {
+ if (fContentType == IPHPPartitions.PHP_PHPDOC_COMMENT) {
+ fContentType = IPHPPartitions.PHP_PARTITIONING;
partitionBorder = true;
- return getToken(IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT);
- } else if (fContentType == IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT) {
- } else if (fContentType == IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT) {
+ return getToken(IPHPPartitions.PHP_PHPDOC_COMMENT);
+ } else if (fContentType == IPHPPartitions.CSS_MULTILINE_COMMENT) {
+ } else if (fContentType == IPHPPartitions.JS_MULTILINE_COMMENT) {
}
- } else if (fFileType == IPHPPartitionScannerConstants.SMARTY_FILE && (c = read()) == '}') {
+ } else if (fFileType == IPHPPartitions.SMARTY_FILE && (c = read()) == '}') {
if (DEBUG) {
System.out.println(
"SMARTYDOC_TOKEN end "
+ " fOffset="
+ fOffset);
}
- if (fContentType == IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT) {
- fContentType = IPHPPartitionScannerConstants.HTML;
+ if (fContentType == IPHPPartitions.SMARTY_MULTILINE_COMMENT) {
+ fContentType = IPHPPartitions.HTML;
partitionBorder = true;
- return getToken(IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT);
+ return getToken(IPHPPartitions.SMARTY_MULTILINE_COMMENT);
}
- } else if (!isInString(IPHPPartitionScannerConstants.PHP) && c != ICharacterScanner.EOF) {
+ } else if (!isInString(IPHPPartitions.PHP_PARTITIONING) && c != ICharacterScanner.EOF) {
unread();
}
break;
fEnd = fOffset + length;
fInString = false;
fInDoubString = false;
- fContentType = IPHPPartitionScannerConstants.HTML;
+ fContentType = IPHPPartitions.HTML;
// String[] prev = getPartitionStack(offset);
}