From: khartlage Date: Fri, 17 Jan 2003 20:47:33 +0000 (+0000) Subject: first scanner /parser copied from the jdt java version X-Git-Url: http://git.phpeclipse.com first scanner /parser copied from the jdt java version --- diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/IProblem.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/IProblem.java new file mode 100644 index 0000000..df5d8e5 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/IProblem.java @@ -0,0 +1,480 @@ +/********************************************************************** +Copyright (c) 2002 IBM Corp. and others. +All rights reserved.   This program and the accompanying materials +are made available under the terms of the Common Public License v0.5 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v05.html +  +Contributors: + IBM Corporation - initial API and implementation +**********************************************************************/ + +package net.sourceforge.phpdt.core.compiler; + +import net.sourceforge.phpdt.internal.compiler.lookup.ProblemReasons; + +/** + * Description of a Java problem, as detected by the compiler or some of the underlying + * technology reusing the compiler. + * A problem provides access to: + * + * + * Note: the compiler produces IProblems internally, which are turned into markers by the JavaBuilder + * so as to persist problem descriptions. This explains why there is no API allowing to reach IProblem detected + * when compiling. However, the Java problem markers carry equivalent information to IProblem, in particular + * their ID (attribute "id") is set to one of the IDs defined on this interface. + * + * @since 2.0 + */ +public interface IProblem { + + /** + * Answer back the original arguments recorded into the problem. + * @return the original arguments recorded into the problem + */ + String[] getArguments(); + + /** + * Returns the problem id + * + * @return the problem id + */ + int getID(); + + /** + * Answer a localized, human-readable message string which describes the problem. + * + * @return a localized, human-readable message string which describes the problem + */ + String getMessage(); + + /** + * Answer the file name in which the problem was found. + * + * @return the file name in which the problem was found + */ + char[] getOriginatingFileName(); + + /** + * Answer the end position of the problem (inclusive), or -1 if unknown. + * + * @return the end position of the problem (inclusive), or -1 if unknown + */ + int getSourceEnd(); + + /** + * Answer the line number in source where the problem begins. + * + * @return the line number in source where the problem begins + */ + int getSourceLineNumber(); + + /** + * Answer the start position of the problem (inclusive), or -1 if unknown. + * + * @return the start position of the problem (inclusive), or -1 if unknown + */ + int getSourceStart(); + + /** + * Checks the severity to see if the Error bit is set. + * + * @return true if the Error bit is set for the severity, false otherwise + */ + boolean isError(); + + /** + * Checks the severity to see if the Error bit is not set. + * + * @return true if the Error bit is not set for the severity, false otherwise + */ + boolean isWarning(); + + /** + * Set the end position of the problem (inclusive), or -1 if unknown. + * Used for shifting problem positions. + * + * @param sourceEnd the given end position + */ + void setSourceEnd(int sourceEnd); + + /** + * Set the line number in source where the problem begins. + * + * @param lineNumber the given line number + */ + void setSourceLineNumber(int lineNumber); + + /** + * Set the start position of the problem (inclusive), or -1 if unknown. + * Used for shifting problem positions. + * + * @param the given start position + */ + void setSourceStart(int sourceStart); + + /** + * Problem Categories + * The high bits of a problem ID contains information about the category of a problem. + * e.g. (problemID & TypeRelated) != 0, indicates that this problem is type related. + * + * A problem category can help to implement custom problem filters. Indeed, when numerous problems + * are listed, focusing on import related problems first might be relevant. + * + * When a problem is tagged as Internal, it means that no change other than a local source code change + * can fix the corresponding problem. + */ + int TypeRelated = 0x01000000; + int FieldRelated = 0x02000000; + int MethodRelated = 0x04000000; + int ConstructorRelated = 0x08000000; + int ImportRelated = 0x10000000; + int Internal = 0x20000000; + int Syntax = 0x40000000; + + /** + * Mask to use in order to filter out the category portion of the problem ID. + */ + int IgnoreCategoriesMask = 0xFFFFFF; + + /** + * Below are listed all available problem IDs. Note that this list could be augmented in the future, + * as new features are added to the Java core implementation. + */ + + /** + * ID reserved for referencing an internal error inside the JavaCore implementation which + * may be surfaced as a problem associated with the compilation unit which caused it to occur. + */ + int Unclassified = 0; + + /** + * Generic type related problems + */ + int ObjectHasNoSuperclass = TypeRelated + 1; + int UndefinedType = TypeRelated + 2; + int NotVisibleType = TypeRelated + 3; + int AmbiguousType = TypeRelated + 4; + int UsingDeprecatedType = TypeRelated + 5; + int InternalTypeNameProvided = TypeRelated + 6; + + int IncompatibleTypesInEqualityOperator = TypeRelated + 15; + int IncompatibleTypesInConditionalOperator = TypeRelated + 16; + int TypeMismatch = TypeRelated + 17; + + /** + * Inner types related problems + */ + int MissingEnclosingInstanceForConstructorCall = TypeRelated + 20; + int MissingEnclosingInstance = TypeRelated + 21; + int IncorrectEnclosingInstanceReference = TypeRelated + 22; + int IllegalEnclosingInstanceSpecification = TypeRelated + 23; + int CannotDefineStaticInitializerInLocalType = Internal + 24; + int OuterLocalMustBeFinal = Internal + 25; + int CannotDefineInterfaceInLocalType = Internal + 26; + int IllegalPrimitiveOrArrayTypeForEnclosingInstance = TypeRelated + 27; + int AnonymousClassCannotExtendFinalClass = TypeRelated + 29; + + // variables + int UndefinedName = 50; + int UninitializedLocalVariable = Internal + 51; + int VariableTypeCannotBeVoid = Internal + 52; + int VariableTypeCannotBeVoidArray = Internal + 53; + int CannotAllocateVoidArray = Internal + 54; + // local variables + int RedefinedLocal = Internal + 55; + int RedefinedArgument = Internal + 56; + int DuplicateFinalLocalInitialization = Internal + 57; + // final local variables + int FinalOuterLocalAssignment = Internal + 60; + int LocalVariableIsNeverUsed = Internal + 61; + int ArgumentIsNeverUsed = Internal + 62; + int BytecodeExceeds64KLimit = Internal + 63; + int BytecodeExceeds64KLimitForClinit = Internal + 64; + int TooManyArgumentSlots = Internal + 65; + int TooManyLocalVariableSlots = Internal + 66; + + // fields + int UndefinedField = FieldRelated + 70; + int NotVisibleField = FieldRelated + 71; + int AmbiguousField = FieldRelated + 72; + int UsingDeprecatedField = FieldRelated + 73; + int NonStaticFieldFromStaticInvocation = FieldRelated + 74; + int ReferenceToForwardField = FieldRelated + Internal + 75; + + // blank final fields + int FinalFieldAssignment = FieldRelated + 80; + int UninitializedBlankFinalField = FieldRelated + 81; + int DuplicateBlankFinalFieldInitialization = FieldRelated + 82; + + // methods + int UndefinedMethod = MethodRelated + 100; + int NotVisibleMethod = MethodRelated + 101; + int AmbiguousMethod = MethodRelated + 102; + int UsingDeprecatedMethod = MethodRelated + 103; + int DirectInvocationOfAbstractMethod = MethodRelated + 104; + int VoidMethodReturnsValue = MethodRelated + 105; + int MethodReturnsVoid = MethodRelated + 106; + int MethodRequiresBody = Internal + MethodRelated + 107; + int ShouldReturnValue = Internal + MethodRelated + 108; + int MethodButWithConstructorName = MethodRelated + 110; + int MissingReturnType = TypeRelated + 111; + int BodyForNativeMethod = Internal + MethodRelated + 112; + int BodyForAbstractMethod = Internal + MethodRelated + 113; + int NoMessageSendOnBaseType = MethodRelated + 114; + int ParameterMismatch = MethodRelated + 115; + int NoMessageSendOnArrayType = MethodRelated + 116; + + // constructors + int UndefinedConstructor = ConstructorRelated + 130; + int NotVisibleConstructor = ConstructorRelated + 131; + int AmbiguousConstructor = ConstructorRelated + 132; + int UsingDeprecatedConstructor = ConstructorRelated + 133; + // explicit constructor calls + int InstanceFieldDuringConstructorInvocation = ConstructorRelated + 135; + int InstanceMethodDuringConstructorInvocation = ConstructorRelated + 136; + int RecursiveConstructorInvocation = ConstructorRelated + 137; + int ThisSuperDuringConstructorInvocation = ConstructorRelated + 138; + // implicit constructor calls + int UndefinedConstructorInDefaultConstructor = ConstructorRelated + 140; + int NotVisibleConstructorInDefaultConstructor = ConstructorRelated + 141; + int AmbiguousConstructorInDefaultConstructor = ConstructorRelated + 142; + int UndefinedConstructorInImplicitConstructorCall = ConstructorRelated + 143; + int NotVisibleConstructorInImplicitConstructorCall = ConstructorRelated + 144; + int AmbiguousConstructorInImplicitConstructorCall = ConstructorRelated + 145; + int UnhandledExceptionInDefaultConstructor = TypeRelated + 146; + int UnhandledExceptionInImplicitConstructorCall = TypeRelated + 147; + + // expressions + int ArrayReferenceRequired = Internal + 150; + int NoImplicitStringConversionForCharArrayExpression = Internal + 151; + // constant expressions + int StringConstantIsExceedingUtf8Limit = Internal + 152; + int NonConstantExpression = 153; + int NumericValueOutOfRange = Internal + 154; + // cast expressions + int IllegalCast = TypeRelated + 156; + // allocations + int InvalidClassInstantiation = TypeRelated + 157; + int CannotDefineDimensionExpressionsWithInit = Internal + 158; + int MustDefineEitherDimensionExpressionsOrInitializer = Internal + 159; + // operators + int InvalidOperator = Internal + 160; + // statements + int CodeCannotBeReached = Internal + 161; + int CannotReturnInInitializer = Internal + 162; + int InitializerMustCompleteNormally = Internal + 163; + + // assert + int InvalidVoidExpression = Internal + 164; + // try + int MaskedCatch = TypeRelated + 165; + int DuplicateDefaultCase = 166; + int UnreachableCatch = TypeRelated + MethodRelated + 167; + int UnhandledException = TypeRelated + 168; + // switch + int IncorrectSwitchType = TypeRelated + 169; + int DuplicateCase = FieldRelated + 170; + // labelled + int DuplicateLabel = Internal + 171; + int InvalidBreak = Internal + 172; + int InvalidContinue = Internal + 173; + int UndefinedLabel = Internal + 174; + //synchronized + int InvalidTypeToSynchronized = Internal + 175; + int InvalidNullToSynchronized = Internal + 176; + // throw + int CannotThrowNull = Internal + 177; + + // inner emulation + int NeedToEmulateFieldReadAccess = FieldRelated + 190; + int NeedToEmulateFieldWriteAccess = FieldRelated + 191; + int NeedToEmulateMethodAccess = MethodRelated + 192; + int NeedToEmulateConstructorAccess = MethodRelated + 193; + + //inherited name hides enclosing name (sort of ambiguous) + int InheritedMethodHidesEnclosingName = MethodRelated + 195; + int InheritedFieldHidesEnclosingName = FieldRelated + 196; + int InheritedTypeHidesEnclosingName = TypeRelated + 197; + + // miscellaneous + int ThisInStaticContext = Internal + 200; + int StaticMethodRequested = Internal + MethodRelated + 201; + int IllegalDimension = Internal + 202; + int InvalidTypeExpression = Internal + 203; + int ParsingError = Syntax + Internal + 204; + int ParsingErrorNoSuggestion = Syntax + Internal + 205; + int InvalidUnaryExpression = Syntax + Internal + 206; + + // syntax errors + int InterfaceCannotHaveConstructors = Syntax + Internal + 207; + int ArrayConstantsOnlyInArrayInitializers = Syntax + Internal + 208; + int ParsingErrorOnKeyword = Syntax + Internal + 209; + int ParsingErrorOnKeywordNoSuggestion = Syntax + Internal + 210; + + int UnmatchedBracket = Syntax + Internal + 220; + int NoFieldOnBaseType = FieldRelated + 221; + int InvalidExpressionAsStatement = Syntax + Internal + 222; + + // scanner errors + int EndOfSource = Syntax + Internal + 250; + int InvalidHexa = Syntax + Internal + 251; + int InvalidOctal = Syntax + Internal + 252; + int InvalidCharacterConstant = Syntax + Internal + 253; + int InvalidEscape = Syntax + Internal + 254; + int InvalidInput = Syntax + Internal + 255; + int InvalidUnicodeEscape = Syntax + Internal + 256; + int InvalidFloat = Syntax + Internal + 257; + int NullSourceString = Syntax + Internal + 258; + int UnterminatedString = Syntax + Internal + 259; + int UnterminatedComment = Syntax + Internal + 260; + + // type related problems + int InterfaceCannotHaveInitializers = TypeRelated + 300; + int DuplicateModifierForType = TypeRelated + 301; + int IllegalModifierForClass = TypeRelated + 302; + int IllegalModifierForInterface = TypeRelated + 303; + int IllegalModifierForMemberClass = TypeRelated + 304; + int IllegalModifierForMemberInterface = TypeRelated + 305; + int IllegalModifierForLocalClass = TypeRelated + 306; + + int IllegalModifierCombinationFinalAbstractForClass = TypeRelated + 308; + int IllegalVisibilityModifierForInterfaceMemberType = TypeRelated + 309; + int IllegalVisibilityModifierCombinationForMemberType = TypeRelated + 310; + int IllegalStaticModifierForMemberType = TypeRelated + 311; + int SuperclassMustBeAClass = TypeRelated + 312; + int ClassExtendFinalClass = TypeRelated + 313; + int DuplicateSuperInterface = TypeRelated + 314; + int SuperInterfaceMustBeAnInterface = TypeRelated + 315; + int HierarchyCircularitySelfReference = TypeRelated + 316; + int HierarchyCircularity = TypeRelated + 317; + int HidingEnclosingType = TypeRelated + 318; + int DuplicateNestedType = TypeRelated + 319; + int CannotThrowType = TypeRelated + 320; + int PackageCollidesWithType = TypeRelated + 321; + int TypeCollidesWithPackage = TypeRelated + 322; + int DuplicateTypes = TypeRelated + 323; + int IsClassPathCorrect = TypeRelated + 324; + int PublicClassMustMatchFileName = TypeRelated + 325; + int MustSpecifyPackage = 326; + int HierarchyHasProblems = TypeRelated + 327; + int PackageIsNotExpectedPackage = 328; + + // int InvalidSuperclassBase = TypeRelated + 329; // reserved to 334 included + int SuperclassNotFound = TypeRelated + 329 + ProblemReasons.NotFound; // TypeRelated + 330 + int SuperclassNotVisible = TypeRelated + 329 + ProblemReasons.NotVisible; // TypeRelated + 331 + int SuperclassAmbiguous = TypeRelated + 329 + ProblemReasons.Ambiguous; // TypeRelated + 332 + int SuperclassInternalNameProvided = TypeRelated + 329 + ProblemReasons.InternalNameProvided; // TypeRelated + 333 + int SuperclassInheritedNameHidesEnclosingName = TypeRelated + 329 + ProblemReasons.InheritedNameHidesEnclosingName; // TypeRelated + 334 + + // int InvalidInterfaceBase = TypeRelated + 334; // reserved to 339 included + int InterfaceNotFound = TypeRelated + 334 + ProblemReasons.NotFound; // TypeRelated + 335 + int InterfaceNotVisible = TypeRelated + 334 + ProblemReasons.NotVisible; // TypeRelated + 336 + int InterfaceAmbiguous = TypeRelated + 334 + ProblemReasons.Ambiguous; // TypeRelated + 337 + int InterfaceInternalNameProvided = TypeRelated + 334 + ProblemReasons.InternalNameProvided; // TypeRelated + 338 + int InterfaceInheritedNameHidesEnclosingName = TypeRelated + 334 + ProblemReasons.InheritedNameHidesEnclosingName; // TypeRelated + 339 + + // field related problems + int DuplicateField = FieldRelated + 340; + int DuplicateModifierForField = FieldRelated + 341; + int IllegalModifierForField = FieldRelated + 342; + int IllegalModifierForInterfaceField = FieldRelated + 343; + int IllegalVisibilityModifierCombinationForField = FieldRelated + 344; + int IllegalModifierCombinationFinalVolatileForField = FieldRelated + 345; + int UnexpectedStaticModifierForField = FieldRelated + 346; + + // int FieldTypeProblemBase = FieldRelated + 349; //reserved to 354 + int FieldTypeNotFound = FieldRelated + 349 + ProblemReasons.NotFound; // FieldRelated + 350 + int FieldTypeNotVisible = FieldRelated + 349 + ProblemReasons.NotVisible; // FieldRelated + 351 + int FieldTypeAmbiguous = FieldRelated + 349 + ProblemReasons.Ambiguous; // FieldRelated + 352 + int FieldTypeInternalNameProvided = FieldRelated + 349 + ProblemReasons.InternalNameProvided; // FieldRelated + 353 + int FieldTypeInheritedNameHidesEnclosingName = FieldRelated + 349 + ProblemReasons.InheritedNameHidesEnclosingName; // FieldRelated + 354 + + // method related problems + int DuplicateMethod = MethodRelated + 355; + int IllegalModifierForArgument = MethodRelated + 356; + int DuplicateModifierForMethod = MethodRelated + 357; + int IllegalModifierForMethod = MethodRelated + 358; + int IllegalModifierForInterfaceMethod = MethodRelated + 359; + int IllegalVisibilityModifierCombinationForMethod = MethodRelated + 360; + int UnexpectedStaticModifierForMethod = MethodRelated + 361; + int IllegalAbstractModifierCombinationForMethod = MethodRelated + 362; + int AbstractMethodInAbstractClass = MethodRelated + 363; + int ArgumentTypeCannotBeVoid = MethodRelated + 364; + int ArgumentTypeCannotBeVoidArray = MethodRelated + 365; + int ReturnTypeCannotBeVoidArray = MethodRelated + 366; + int NativeMethodsCannotBeStrictfp = MethodRelated + 367; + int DuplicateModifierForArgument = MethodRelated + 368; + + // int ArgumentProblemBase = MethodRelated + 369; // reserved to 374 included. + int ArgumentTypeNotFound = MethodRelated + 369 + ProblemReasons.NotFound; // MethodRelated + 370 + int ArgumentTypeNotVisible = MethodRelated + 369 + ProblemReasons.NotVisible; // MethodRelated + 371 + int ArgumentTypeAmbiguous = MethodRelated + 369 + ProblemReasons.Ambiguous; // MethodRelated + 372 + int ArgumentTypeInternalNameProvided = MethodRelated + 369 + ProblemReasons.InternalNameProvided; // MethodRelated + 373 + int ArgumentTypeInheritedNameHidesEnclosingName = MethodRelated + 369 + ProblemReasons.InheritedNameHidesEnclosingName; // MethodRelated + 374 + + // int ExceptionTypeProblemBase = MethodRelated + 374; // reserved to 379 included. + int ExceptionTypeNotFound = MethodRelated + 374 + ProblemReasons.NotFound; // MethodRelated + 375 + int ExceptionTypeNotVisible = MethodRelated + 374 + ProblemReasons.NotVisible; // MethodRelated + 376 + int ExceptionTypeAmbiguous = MethodRelated + 374 + ProblemReasons.Ambiguous; // MethodRelated + 377 + int ExceptionTypeInternalNameProvided = MethodRelated + 374 + ProblemReasons.InternalNameProvided; // MethodRelated + 378 + int ExceptionTypeInheritedNameHidesEnclosingName = MethodRelated + 374 + ProblemReasons.InheritedNameHidesEnclosingName; // MethodRelated + 379 + + // int ReturnTypeProblemBase = MethodRelated + 379; + int ReturnTypeNotFound = MethodRelated + 379 + ProblemReasons.NotFound; // MethodRelated + 380 + int ReturnTypeNotVisible = MethodRelated + 379 + ProblemReasons.NotVisible; // MethodRelated + 381 + int ReturnTypeAmbiguous = MethodRelated + 379 + ProblemReasons.Ambiguous; // MethodRelated + 382 + int ReturnTypeInternalNameProvided = MethodRelated + 379 + ProblemReasons.InternalNameProvided; // MethodRelated + 383 + int ReturnTypeInheritedNameHidesEnclosingName = MethodRelated + 379 + ProblemReasons.InheritedNameHidesEnclosingName; // MethodRelated + 384 + + // import related problems + int ConflictingImport = ImportRelated + 385; + int DuplicateImport = ImportRelated + 386; + int CannotImportPackage = ImportRelated + 387; + int UnusedImport = ImportRelated + 388; + + // int ImportProblemBase = ImportRelated + 389; + int ImportNotFound = ImportRelated + 389 + ProblemReasons.NotFound; // ImportRelated + 390 + int ImportNotVisible = ImportRelated + 389 + ProblemReasons.NotVisible; // ImportRelated + 391 + int ImportAmbiguous = ImportRelated + 389 + ProblemReasons.Ambiguous; // ImportRelated + 392 + int ImportInternalNameProvided = ImportRelated + 389 + ProblemReasons.InternalNameProvided; // ImportRelated + 393 + int ImportInheritedNameHidesEnclosingName = ImportRelated + 389 + ProblemReasons.InheritedNameHidesEnclosingName; // ImportRelated + 394 + + + // local variable related problems + int DuplicateModifierForVariable = MethodRelated + 395; + int IllegalModifierForVariable = MethodRelated + 396; + + // method verifier problems + int AbstractMethodMustBeImplemented = MethodRelated + 400; + int FinalMethodCannotBeOverridden = MethodRelated + 401; + int IncompatibleExceptionInThrowsClause = MethodRelated + 402; + int IncompatibleExceptionInInheritedMethodThrowsClause = MethodRelated + 403; + int IncompatibleReturnType = MethodRelated + 404; + int InheritedMethodReducesVisibility = MethodRelated + 405; + int CannotOverrideAStaticMethodWithAnInstanceMethod = MethodRelated + 406; + int CannotHideAnInstanceMethodWithAStaticMethod = MethodRelated + 407; + int StaticInheritedMethodConflicts = MethodRelated + 408; + int MethodReducesVisibility = MethodRelated + 409; + int OverridingNonVisibleMethod = MethodRelated + 410; + int AbstractMethodCannotBeOverridden = MethodRelated + 411; + int OverridingDeprecatedMethod = MethodRelated + 412; + + // code snippet support + int CodeSnippetMissingClass = Internal + 420; + int CodeSnippetMissingMethod = Internal + 421; + int NonExternalizedStringLiteral = Internal + 261; + int CannotUseSuperInCodeSnippet = Internal + 422; + + //constant pool + int TooManyConstantsInConstantPool = Internal + 430; + + // 1.4 features + // assertion warning + int UseAssertAsAnIdentifier = Internal + 440; +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/IScanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/IScanner.java new file mode 100644 index 0000000..eab27dd --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/IScanner.java @@ -0,0 +1,133 @@ +/********************************************************************** +Copyright (c) 2002 IBM Corp. and others. +All rights reserved.   This program and the accompanying materials +are made available under the terms of the Common Public License v0.5 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v05.html +  +Contributors: + IBM Corporation - initial API and implementation +**********************************************************************/ + +package net.sourceforge.phpdt.core.compiler; + + /** + * Definition of a Java scanner, as returned by the ToolFactory. + * The scanner is responsible for tokenizing a given source, providing information about + * the nature of the token read, its positions and source equivalent. + * + * When the scanner has finished tokenizing, it answers an EOF token ( + * ITerminalSymbols#TokenNameEOF. + * + * When encountering lexical errors, an InvalidInputException is thrown. + * + * @see org.eclipse.jdt.core.ToolFactory + * @see ITerminalSymbols + * @since 2.0 + */ +public interface IScanner { + + /** + * Answers the current identifier source, after unicode escape sequences have + * been translated into unicode characters. + * e.g. if original source was \\u0061bc then it will answer abc. + * + * @return the current identifier source, after unicode escape sequences have + * been translated into unicode characters + */ + char[] getCurrentTokenSource(); + + /** + * Answers the starting position of the current token inside the original source. + * This position is zero-based and inclusive. It corresponds to the position of the first character + * which is part of this token. If this character was a unicode escape sequence, it points at the first + * character of this sequence. + * + * @return the starting position of the current token inside the original source + */ + int getCurrentTokenStartPosition(); + + /** + * Answers the ending position of the current token inside the original source. + * This position is zero-based and inclusive. It corresponds to the position of the last character + * which is part of this token. If this character was a unicode escape sequence, it points at the last + * character of this sequence. + * + * @return the ending position of the current token inside the original source + */ + int getCurrentTokenEndPosition(); + + /** + * Answers the starting position of a given line number. This line has to have been encountered + * already in the tokenization process (i.e. it cannot be used to compute positions of lines beyond + * current token). Once the entire source has been processed, it can be used without any limit. + * Line starting positions are zero-based, and start immediately after the previous line separator (if any). + * + * @param lineNumber the given line number + * @return the starting position of a given line number + */ + int getLineStart(int lineNumber); + + /** + * Answers the ending position of a given line number. This line has to have been encountered + * already in the tokenization process (i.e. it cannot be used to compute positions of lines beyond + * current token). Once the entire source has been processed, it can be used without any limit. + * Line ending positions are zero-based, and correspond to the last character of the line separator + * (in case multi-character line separators). + * + * @param lineNumber the given line number + * @return the ending position of a given line number + **/ + int getLineEnd(int lineNumber); + + /** + * Answers an array of the ending positions of the lines encountered so far. Line ending positions + * are zero-based, and correspond to the last character of the line separator (in case multi-character + * line separators). + * + * @return an array of the ending positions of the lines encountered so far + */ + int[] getLineEnds(); + + /** + * Answers a 1-based line number using the lines which have been encountered so far. If the position + * is located beyond the current scanned line, then the last line number will be answered. + * + * @param charPosition the given character position + * @return a 1-based line number using the lines which have been encountered so far + */ + int getLineNumber(int charPosition); + + /** + * Read the next token in the source, and answers its ID as specified by ITerminalSymbols. + * Note that the actual token ID values are subject to change if new keywords were added to the language + * (i.e. 'assert' keyword in 1.4). + * + * @throws InvalidInputException - in case a lexical error was detected while reading the current token + */ + int getNextToken() throws InvalidInputException; + + /** + * Answers the original source being processed (not a copy of it). + * + * @return the original source being processed + */ + char[] getSource(); + + /** + * Reposition the scanner on some portion of the original source. Once reaching the given endPosition + * it will answer EOF tokens (ITerminalSymbols.TokenNameEOF). + * + * @param startPosition the given start position + * @param endPosition the given end position + */ + void resetTo(int startPosition, int endPosition); + + /** + * Set the scanner source to process. By default, the scanner will consider starting at the beginning of the + * source until it reaches its end. + * + * @param source the given source + */ + void setSource(char[] source); +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java new file mode 100644 index 0000000..71706f7 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java @@ -0,0 +1,186 @@ +/********************************************************************** +Copyright (c) 2002 IBM Corp. and others. +All rights reserved.   This program and the accompanying materials +are made available under the terms of the Common Public License v0.5 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v05.html +  +Contributors: + IBM Corporation - initial API and implementation +**********************************************************************/ + +package net.sourceforge.phpdt.core.compiler; + +/** + * Maps each terminal symbol in the java-grammar into a unique integer. + * This integer is used to represent the terminal when computing a parsing action. + * + * Disclaimer : These constant values are generated automatically using a Java + * grammar, therefore their actual values are subject to change if new keywords + * were added to the language (i.e. 'assert' keyword in 1.4). + * + * @see IScanner + * @since 2.0 + */ +public interface ITerminalSymbols { + + // special tokens not part of grammar - not autogenerated + public final static int TokenNameWHITESPACE = 900, + TokenNameCOMMENT_LINE = 901, + TokenNameCOMMENT_BLOCK = 902, + TokenNameCOMMENT_JAVADOC = 903; + + public final static int TokenNameIdentifier = 5, +// TokenNameabstract = 98, +// TokenNameassert = 118, +// TokenNameboolean = 18, +// // TokenNamebreak = 119, +// TokenNamebyte = 19, +// // TokenNamecase = 211, +// TokenNamecatch = 225, +// TokenNamechar = 20, +// // TokenNameclass = 165, +// // TokenNamecontinue = 120, +// // TokenNamedefault = 212, +// // TokenNamedo = 121, +// TokenNamedouble = 21, +// // TokenNameelse = 213, +// // TokenNameextends = 243, +// // TokenNamefalse = 37, +// TokenNamefinal = 99, +// TokenNamefinally = 226, +// TokenNamefloat = 22, +// // TokenNamefor = 122, +// // TokenNameif = 123, +// TokenNameimplements = 267, +// TokenNameimport = 191, +// TokenNameinstanceof = 65, +// TokenNameint = 23, +// TokenNameinterface = 180, +// TokenNamelong = 24, +// TokenNamenative = 100, +// // TokenNamenew = 32, +// // TokenNamenull = 38, +// TokenNamepackage = 214, +// TokenNameprivate = 101, +// TokenNameprotected = 102, +// TokenNamepublic = 103, +// // TokenNamereturn = 124, +// TokenNameshort = 25, +// // TokenNamestatic = 94, +// TokenNamestrictfp = 104, +// TokenNamesuper = 34, +// // TokenNameswitch = 125, +// TokenNamesynchronized = 85, +// TokenNamethis = 35, +// TokenNamethrow = 126, +// TokenNamethrows = 227, +// TokenNametransient = 105, +// // TokenNametrue = 39, +// TokenNametry = 127, +// TokenNamevoid = 26, +// TokenNamevolatile = 106, +// // TokenNamewhile = 117, + TokenNameIntegerLiteral = 40, + TokenNameLongLiteral = 41, + TokenNameFloatingPointLiteral = 42, + TokenNameDoubleLiteral = 43, + TokenNameCharacterLiteral = 44, + TokenNameStringLiteral = 45, + TokenNamePLUS_PLUS = 1, + TokenNameMINUS_MINUS = 2, + TokenNameEQUAL_EQUAL = 33, + TokenNameLESS_EQUAL = 66, + TokenNameGREATER_EQUAL = 67, + TokenNameNOT_EQUAL = 36, + TokenNameLEFT_SHIFT = 14, + TokenNameRIGHT_SHIFT = 11, + TokenNameUNSIGNED_RIGHT_SHIFT = 12, + TokenNamePLUS_EQUAL = 168, + TokenNameMINUS_EQUAL = 169, + TokenNameMULTIPLY_EQUAL = 170, + TokenNameDIVIDE_EQUAL = 171, + TokenNameAND_EQUAL = 172, + TokenNameOR_EQUAL = 173, + TokenNameXOR_EQUAL = 174, + TokenNameREMAINDER_EQUAL = 175, + TokenNameLEFT_SHIFT_EQUAL = 176, + TokenNameRIGHT_SHIFT_EQUAL = 177, + TokenNameUNSIGNED_RIGHT_SHIFT_EQUAL = 178, + TokenNameOR_OR = 80, + TokenNameAND_AND = 79, + TokenNamePLUS = 3, + TokenNameMINUS = 4, + TokenNameNOT = 71, + TokenNameREMAINDER = 9, + TokenNameXOR = 63, + TokenNameAND = 62, + TokenNameMULTIPLY = 8, + TokenNameOR = 70, + TokenNameTWIDDLE = 72, + TokenNameDIVIDE = 10, + TokenNameGREATER = 68, + TokenNameLESS = 69, + TokenNameLPAREN = 7, + TokenNameRPAREN = 86, + TokenNameLBRACE = 110, + TokenNameRBRACE = 95, + TokenNameLBRACKET = 15, + TokenNameRBRACKET = 166, + TokenNameSEMICOLON = 64, + TokenNameQUESTION = 81, + TokenNameCOLON = 154, + TokenNameCOMMA = 90, + TokenNameDOT = 6, + TokenNameEQUAL = 167, + TokenNameEOF = 158, + TokenNameERROR = 307; + +// public final static int TokenNameKEYWORD = 1000; + public final static int TokenNameif = 1001; + public final static int TokenNameelseif = 1002; + public final static int TokenNameelse = 1003; + public final static int TokenNameendif = 1004; + public final static int TokenNamefor = 1005; + public final static int TokenNameendfor = 1006; + public final static int TokenNamewhile = 1007; + public final static int TokenNameendwhile = 1008; + public final static int TokenNameswitch = 1009; + public final static int TokenNamecase = 10010; + public final static int TokenNameendswitch = 1011; + public final static int TokenNamebreak = 1012; + public final static int TokenNamecontinue = 1013; + public final static int TokenNamereturn = 1014; + public final static int TokenNamedefine = 1015; + public final static int TokenNameinclude = 1016; + public final static int TokenNameinclude_once = 1017; + public final static int TokenNamerequire = 1018; + public final static int TokenNamerequire_once = 1019; + public final static int TokenNamefunction = 1020; + public final static int TokenNameclass = 1021; + public final static int TokenNamenew = 1022; + public final static int TokenNamedo = 1023; + public final static int TokenNameold_function = 1024; + public final static int TokenNamedefault = 1025; + public final static int TokenNameglobal = 1026; + public final static int TokenNamestatic = 1027; + public final static int TokenNameforeach = 1028; + public final static int TokenNameendforeach = 1029; + public final static int TokenNameextends = 1030; + // public final static int TokenNameempty = 1031; + // public final static int TokenNamearray = 1032; + public final static int TokenNameecho = 1033; + public final static int TokenNamevar = 1034; + public final static int TokenNameas = 1035; + public final static int TokenNameprint = 1036; + // public final static int TokenNameunset = 1037; + // public final static int TokenNameexit = 1038; + // public final static int TokenNamedie = 1039; + public final static int TokenNameand = 1040; + public final static int TokenNameor = 1041; + public final static int TokenNamexor = 1042; + public final static int TokenNamelist = 1043; + public final static int TokenNamenull = 1044; + public final static int TokenNamefalse = 1045; + public final static int TokenNametrue = 1046; +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/InvalidInputException.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/InvalidInputException.java new file mode 100644 index 0000000..a4367a7 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/InvalidInputException.java @@ -0,0 +1,32 @@ +/********************************************************************** +Copyright (c) 2002 IBM Corp. and others. +All rights reserved.   This program and the accompanying materials +are made available under the terms of the Common Public License v0.5 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v05.html +  +Contributors: + IBM Corporation - initial API and implementation +**********************************************************************/ + +package net.sourceforge.phpdt.core.compiler; + +/** + * Exception thrown by a scanner when encountering lexical errors. + */ +public class InvalidInputException extends Exception { + + /** + * InvalidInputException constructor comment. + */ + public InvalidInputException() { + super(); + } + /** + * InvalidInputException constructor comment. + * @param s java.lang.String + */ + public InvalidInputException(String s) { + super(s); + } +}