X-Git-Url: http://git.phpeclipse.com
diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.jj b/net.sourceforge.phpeclipse/src/test/PHPParser.jj
index e3b05cf..bb3d533 100644
--- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj
+++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj
@@ -30,6 +30,7 @@ import org.eclipse.jface.preference.IPreferenceStore;
import java.util.Hashtable;
import java.io.StringReader;
+import java.io.*;
import java.text.MessageFormat;
import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
@@ -50,6 +51,7 @@ import net.sourceforge.phpdt.internal.compiler.parser.PHPReqIncDeclaration;
*/
public final class PHPParser extends PHPParserSuperclass {
+ /** The file that is parsed. */
private static IFile fileToParse;
/** The current segment */
@@ -58,24 +60,30 @@ public final class PHPParser extends PHPParserSuperclass {
private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
PHPOutlineInfo outlineInfo;
+
+ /** The error level of the current ParseException. */
private static int errorLevel = ERROR;
+ /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
private static String errorMessage;
+ private static int errorStart = -1;
+ private static int errorEnd = -1;
+
public PHPParser() {
}
- public final void setFileToParse(IFile fileToParse) {
+ public final void setFileToParse(final IFile fileToParse) {
this.fileToParse = fileToParse;
}
- public PHPParser(IFile fileToParse) {
+ public PHPParser(final IFile fileToParse) {
this(new StringReader(""));
this.fileToParse = fileToParse;
}
- public static final void phpParserTester(String strEval) throws CoreException, ParseException {
+ public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
- StringReader stream = new StringReader(strEval);
+ final StringReader stream = new StringReader(strEval);
if (jj_input_stream == null) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
}
@@ -83,8 +91,23 @@ public final class PHPParser extends PHPParserSuperclass {
phpTest();
}
- public static final void htmlParserTester(String strEval) throws CoreException, ParseException {
- StringReader stream = new StringReader(strEval);
+ public static final void htmlParserTester(final File fileName) throws CoreException, ParseException {
+ try {
+ final Reader stream = new FileReader(fileName);
+ if (jj_input_stream == null) {
+ jj_input_stream = new SimpleCharStream(stream, 1, 1);
+ }
+ ReInit(stream);
+ phpFile();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace(); //To change body of catch statement use Options | File Templates.
+ } catch (ParseException e) {
+ e.printStackTrace(); //To change body of catch statement use Options | File Templates.
+ }
+ }
+
+ public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
+ final StringReader stream = new StringReader(strEval);
if (jj_input_stream == null) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
}
@@ -92,10 +115,10 @@ public final class PHPParser extends PHPParserSuperclass {
phpFile();
}
- public final PHPOutlineInfo parseInfo(Object parent, String s) {
+ public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
outlineInfo = new PHPOutlineInfo(parent);
currentSegment = outlineInfo.getDeclarations();
- StringReader stream = new StringReader(s);
+ final StringReader stream = new StringReader(s);
if (jj_input_stream == null) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
}
@@ -117,6 +140,8 @@ public final class PHPParser extends PHPParserSuperclass {
if (errorMessage == null) {
PHPeclipsePlugin.log(e);
errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
+ errorStart = jj_input_stream.getPosition();
+ errorEnd = errorStart + 1;
}
setMarker(e);
errorMessage = null;
@@ -124,15 +149,27 @@ public final class PHPParser extends PHPParserSuperclass {
/**
* Create marker for the parse error
+ * @param e the ParseException
*/
- private static void setMarker(ParseException e) {
+ private static void setMarker(final ParseException e) {
try {
- setMarker(fileToParse,
- errorMessage,
- jj_input_stream.tokenBegin,
- jj_input_stream.tokenBegin + e.currentToken.image.length(),
- errorLevel,
- "Line " + e.currentToken.beginLine);
+ if (errorStart == -1) {
+ setMarker(fileToParse,
+ errorMessage,
+ jj_input_stream.tokenBegin,
+ jj_input_stream.tokenBegin + e.currentToken.image.length(),
+ errorLevel,
+ "Line " + e.currentToken.beginLine);
+ } else {
+ setMarker(fileToParse,
+ errorMessage,
+ errorStart,
+ errorEnd,
+ errorLevel,
+ "Line " + e.currentToken.beginLine);
+ errorStart = -1;
+ errorEnd = -1;
+ }
} catch (CoreException e2) {
PHPeclipsePlugin.log(e2);
}
@@ -141,12 +178,12 @@ public final class PHPParser extends PHPParserSuperclass {
/**
* Create markers according to the external parser output
*/
- private static void createMarkers(String output, IFile file) throws CoreException {
+ private static void createMarkers(final String output, final IFile file) throws CoreException {
// delete all markers
file.deleteMarkers(IMarker.PROBLEM, false, 0);
int indx = 0;
- int brIndx = 0;
+ int brIndx;
boolean flag = true;
while ((brIndx = output.indexOf("
", indx)) != -1) {
// newer php error output (tested with 4.2.3)
@@ -163,7 +200,10 @@ public final class PHPParser extends PHPParserSuperclass {
}
}
- private static void scanLine(String output, IFile file, int indx, int brIndx) throws CoreException {
+ private static void scanLine(final String output,
+ final IFile file,
+ final int indx,
+ final int brIndx) throws CoreException {
String current;
StringBuffer lineNumberBuffer = new StringBuffer(10);
char ch;
@@ -201,8 +241,8 @@ public final class PHPParser extends PHPParserSuperclass {
}
}
- public final void parse(String s) throws CoreException {
- StringReader stream = new StringReader(s);
+ public final void parse(final String s) throws CoreException {
+ final StringReader stream = new StringReader(s);
if (jj_input_stream == null) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
}
@@ -218,15 +258,15 @@ public final class PHPParser extends PHPParserSuperclass {
* Call the php parse command ( php -l -f <filename> )
* and create markers according to the external parser output
*/
- public static void phpExternalParse(IFile file) {
- IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
- String filename = file.getLocation().toString();
+ public static void phpExternalParse(final IFile file) {
+ final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+ final String filename = file.getLocation().toString();
- String[] arguments = { filename };
- MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
- String command = form.format(arguments);
+ final String[] arguments = { filename };
+ final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
+ final String command = form.format(arguments);
- String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
+ final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
try {
// parse the buffer to find the errors and warnings
@@ -245,7 +285,9 @@ PARSER_END(PHPParser)
TOKEN :
{
- : PHPPARSING
+ : PHPPARSING
+| : PHPPARSING
+| : PHPPARSING
}
TOKEN :
@@ -272,10 +314,12 @@ PARSER_END(PHPParser)
/* COMMENTS */
- MORE :
+ SPECIAL_TOKEN :
{
"//" : IN_SINGLE_LINE_COMMENT
|
+ "#" : IN_SINGLE_LINE_COMMENT
+|
<"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
|
"/*" : IN_MULTI_LINE_COMMENT
@@ -286,7 +330,7 @@ PARSER_END(PHPParser)
: PHPPARSING
}
- TOKEN :
+ SPECIAL_TOKEN :
{
" > : DEFAULT
}
@@ -319,72 +363,76 @@ MORE :
|
|
|
+|
}
/* LANGUAGE CONSTRUCT */
TOKEN :
{
-
-|
-|
-|
-|
-|
-|
-|
-| ">
-|
-| ">
+
+|
+|
+|
+|
+|
+|
+|
+| ">
+|
+| ">
}
+ TOKEN :
+{
+
+}
/* RESERVED WORDS AND LITERALS */
TOKEN :
{
- < BREAK: "break" >
-| < CASE: "case" >
-| < CONST: "const" >
-| < CONTINUE: "continue" >
-| < _DEFAULT: "default" >
-| < DO: "do" >
-| < EXTENDS: "extends" >
-| < FALSE: "false" >
-| < FOR: "for" >
-| < GOTO: "goto" >
-| < NEW: "new" >
-| < NULL: "null" >
-| < RETURN: "return" >
-| < SUPER: "super" >
-| < SWITCH: "switch" >
-| < THIS: "this" >
-| < TRUE: "true" >
-| < WHILE: "while" >
-| < ENDWHILE : "endwhile" >
-|
-|
-|
-|
+
+|
+|
+| <_DEFAULT : "default">
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
}
/* TYPES */
TOKEN :
{
-
-|