integrated antlr 2.7.6.2 sources
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -86,10 +86,6 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="antlr.runtime, Version=2.7.6.2, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\Net\2.0\antlr.runtime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Common.Logging, Version=1.1.0.0, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\Net\2.0\Common.Logging.dll</HintPath>
|
||||
|
||||
8
src/Spring/Spring.Core/README_ANTLR.txt
Normal file
8
src/Spring/Spring.Core/README_ANTLR.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
Notes on code merge into Spring.Core:
|
||||
|
||||
|
||||
28-07-2009
|
||||
----------
|
||||
|
||||
*) Added codebase version 2.7.6 of antlr
|
||||
*) had to move <global>::SupportClass to namespace "antlr"
|
||||
@@ -51,7 +51,7 @@
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
<NoWarn>219, 162, 618</NoWarn>
|
||||
<NoWarn>219, 162, 618, 1591</NoWarn>
|
||||
<Optimize>false</Optimize>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||
@@ -86,10 +86,6 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="antlr.runtime, Version=2.7.6.2, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\Net\2.0\antlr.runtime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Common.Logging, Version=1.1.0.0, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\Net\2.0\Common.Logging.dll</HintPath>
|
||||
@@ -106,6 +102,107 @@
|
||||
<Link>CommonAssemblyInfo.cs</Link>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="antlr\ANTLRException.cs" />
|
||||
<Compile Include="antlr\ANTLRPanicException.cs" />
|
||||
<Compile Include="antlr\ASTFactory.cs" />
|
||||
<Compile Include="antlr\ASTNodeCreator.cs" />
|
||||
<Compile Include="antlr\ASTNULLType.cs" />
|
||||
<Compile Include="antlr\ASTPair.cs" />
|
||||
<Compile Include="antlr\ASTVisitor.cs" />
|
||||
<Compile Include="antlr\BaseAST.cs" />
|
||||
<Compile Include="antlr\ByteBuffer.cs" />
|
||||
<Compile Include="antlr\CharBuffer.cs" />
|
||||
<Compile Include="antlr\CharQueue.cs" />
|
||||
<Compile Include="antlr\CharScanner.cs" />
|
||||
<Compile Include="antlr\CharStreamException.cs" />
|
||||
<Compile Include="antlr\CharStreamIOException.cs" />
|
||||
<Compile Include="antlr\collections\AST.cs" />
|
||||
<Compile Include="antlr\collections\impl\ASTArray.cs" />
|
||||
<Compile Include="antlr\collections\impl\BitSet.cs" />
|
||||
<Compile Include="antlr\CommonAST.cs" />
|
||||
<Compile Include="antlr\CommonASTWithHiddenTokens.cs" />
|
||||
<Compile Include="antlr\CommonHiddenStreamToken.cs" />
|
||||
<Compile Include="antlr\CommonToken.cs" />
|
||||
<Compile Include="antlr\debug\ANTLREventArgs.cs" />
|
||||
<Compile Include="antlr\debug\DebuggingCharScanner.cs" />
|
||||
<Compile Include="antlr\debug\DebuggingInputBuffer.cs" />
|
||||
<Compile Include="antlr\debug\DebuggingParser.cs" />
|
||||
<Compile Include="antlr\debug\GuessingEventArgs.cs" />
|
||||
<Compile Include="antlr\debug\ICharScannerDebugSubject.cs" />
|
||||
<Compile Include="antlr\debug\IDebugSubject.cs" />
|
||||
<Compile Include="antlr\debug\InputBufferEventArgs.cs" />
|
||||
<Compile Include="antlr\debug\InputBufferEventSupport.cs" />
|
||||
<Compile Include="antlr\debug\InputBufferListener.cs" />
|
||||
<Compile Include="antlr\debug\InputBufferListenerBase.cs" />
|
||||
<Compile Include="antlr\debug\InputBufferReporter.cs" />
|
||||
<Compile Include="antlr\debug\IParserDebugSubject.cs" />
|
||||
<Compile Include="antlr\debug\Listener.cs" />
|
||||
<Compile Include="antlr\debug\LLkDebuggingParser.cs" />
|
||||
<Compile Include="antlr\debug\MessageEventArgs.cs" />
|
||||
<Compile Include="antlr\debug\MessageListener.cs" />
|
||||
<Compile Include="antlr\debug\MessageListenerBase.cs" />
|
||||
<Compile Include="antlr\debug\NewLineEventArgs.cs" />
|
||||
<Compile Include="antlr\debug\NewLineListener.cs" />
|
||||
<Compile Include="antlr\debug\ParserController.cs" />
|
||||
<Compile Include="antlr\debug\ParserEventSupport.cs" />
|
||||
<Compile Include="antlr\debug\ParserListener.cs" />
|
||||
<Compile Include="antlr\debug\ParserListenerBase.cs" />
|
||||
<Compile Include="antlr\debug\ParserMatchEventArgs.cs" />
|
||||
<Compile Include="antlr\debug\ParserMatchListener.cs" />
|
||||
<Compile Include="antlr\debug\ParserMatchListenerBase.cs" />
|
||||
<Compile Include="antlr\debug\ParserReporter.cs" />
|
||||
<Compile Include="antlr\debug\ParserTokenEventArgs.cs" />
|
||||
<Compile Include="antlr\debug\ParserTokenListener.cs" />
|
||||
<Compile Include="antlr\debug\ParserTokenListenerBase.cs" />
|
||||
<Compile Include="antlr\debug\ParseTreeDebugParser.cs" />
|
||||
<Compile Include="antlr\debug\ScannerEventSupport.cs" />
|
||||
<Compile Include="antlr\debug\SemanticPredicateEventArgs.cs" />
|
||||
<Compile Include="antlr\debug\SemanticPredicateListener.cs" />
|
||||
<Compile Include="antlr\debug\SemanticPredicateListenerBase.cs" />
|
||||
<Compile Include="antlr\debug\SyntacticPredicateEventArgs.cs" />
|
||||
<Compile Include="antlr\debug\SyntacticPredicateListener.cs" />
|
||||
<Compile Include="antlr\debug\SyntacticPredicateListenerBase.cs" />
|
||||
<Compile Include="antlr\debug\TraceEventArgs.cs" />
|
||||
<Compile Include="antlr\debug\TraceListener.cs" />
|
||||
<Compile Include="antlr\debug\TraceListenerBase.cs" />
|
||||
<Compile Include="antlr\debug\Tracer.cs" />
|
||||
<Compile Include="antlr\DefaultFileLineFormatter.cs" />
|
||||
<Compile Include="antlr\DumpASTVisitor.cs" />
|
||||
<Compile Include="antlr\FileLineFormatter.cs" />
|
||||
<Compile Include="antlr\IHiddenStreamToken.cs" />
|
||||
<Compile Include="antlr\InputBuffer.cs" />
|
||||
<Compile Include="antlr\IToken.cs" />
|
||||
<Compile Include="antlr\LexerSharedInputState.cs" />
|
||||
<Compile Include="antlr\LLkParser.cs" />
|
||||
<Compile Include="antlr\MismatchedCharException.cs" />
|
||||
<Compile Include="antlr\MismatchedTokenException.cs" />
|
||||
<Compile Include="antlr\NoViableAltException.cs" />
|
||||
<Compile Include="antlr\NoViableAltForCharException.cs" />
|
||||
<Compile Include="antlr\Parser.cs" />
|
||||
<Compile Include="antlr\ParserSharedInputState.cs" />
|
||||
<Compile Include="antlr\ParseTree.cs" />
|
||||
<Compile Include="antlr\ParseTreeRule.cs" />
|
||||
<Compile Include="antlr\ParseTreeToken.cs" />
|
||||
<Compile Include="antlr\RecognitionException.cs" />
|
||||
<Compile Include="antlr\SemanticException.cs" />
|
||||
<Compile Include="antlr\StringUtils.cs" />
|
||||
<Compile Include="antlr\SupportClass.cs" />
|
||||
<Compile Include="antlr\Token.cs" />
|
||||
<Compile Include="antlr\TokenBuffer.cs" />
|
||||
<Compile Include="antlr\TokenCreator.cs" />
|
||||
<Compile Include="antlr\TokenQueue.cs" />
|
||||
<Compile Include="antlr\TokenStream.cs" />
|
||||
<Compile Include="antlr\TokenStreamBasicFilter.cs" />
|
||||
<Compile Include="antlr\TokenStreamException.cs" />
|
||||
<Compile Include="antlr\TokenStreamHiddenTokenFilter.cs" />
|
||||
<Compile Include="antlr\TokenStreamIOException.cs" />
|
||||
<Compile Include="antlr\TokenStreamRecognitionException.cs" />
|
||||
<Compile Include="antlr\TokenStreamRetryException.cs" />
|
||||
<Compile Include="antlr\TokenStreamRewriteEngine.cs" />
|
||||
<Compile Include="antlr\TokenStreamSelector.cs" />
|
||||
<Compile Include="antlr\TokenWithIndex.cs" />
|
||||
<Compile Include="antlr\TreeParser.cs" />
|
||||
<Compile Include="antlr\TreeParserSharedInputState.cs" />
|
||||
<Compile Include="AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
@@ -1106,6 +1203,7 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="README_ANTLR.txt" />
|
||||
<Content Include="Expressions\Parser\ExpressionParserTokenTypes.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
<warning number="219" />
|
||||
<warning number="162" />
|
||||
<warning number="618" /> <!-- disable deprecation warnings (due to deprecated code generated by antlr ) -->
|
||||
<warning number="${nowarn.numbers},0612,1570,1584,1591" if="${nant.settings.currentframework=='mono-2.0'}"/>
|
||||
<warning number="1591" /> <!-- disable slashdoc warnings (due to uncommented antlr sources) -->
|
||||
<warning number="${nowarn.numbers},0612,1570,1584,1591" if="${nant.settings.currentframework=='mono-2.0'}"/>
|
||||
</nowarn>
|
||||
<sources failonempty="true">
|
||||
<include name="**/*.cs" />
|
||||
@@ -39,7 +40,6 @@
|
||||
</resources>
|
||||
<references basedir="${current.bin.dir}">
|
||||
<include name="Common.Logging.dll"/>
|
||||
<include name="antlr.runtime.dll" />
|
||||
<include name="System.Drawing.dll"/>
|
||||
<include name="System.Configuration.dll"/>
|
||||
<include name="System.Xml.dll"/>
|
||||
|
||||
35
src/Spring/Spring.Core/antlr/ANTLRException.cs
Normal file
35
src/Spring/Spring.Core/antlr/ANTLRException.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class ANTLRException : Exception
|
||||
{
|
||||
public ANTLRException() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public ANTLRException(string s) : base(s)
|
||||
{
|
||||
}
|
||||
|
||||
public ANTLRException(string s, Exception inner) : base(s, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
35
src/Spring/Spring.Core/antlr/ANTLRPanicException.cs
Normal file
35
src/Spring/Spring.Core/antlr/ANTLRPanicException.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class ANTLRPanicException : ANTLRException
|
||||
{
|
||||
public ANTLRPanicException() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public ANTLRPanicException(string s) : base(s)
|
||||
{
|
||||
}
|
||||
|
||||
public ANTLRPanicException(string s, Exception inner) : base(s, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
696
src/Spring/Spring.Core/antlr/ASTFactory.cs
Normal file
696
src/Spring/Spring.Core/antlr/ASTFactory.cs
Normal file
@@ -0,0 +1,696 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Assembly = System.Reflection.Assembly;
|
||||
using ArrayList = System.Collections.ArrayList;
|
||||
using Debug = System.Diagnostics.Debug;
|
||||
using AST = antlr.collections.AST;
|
||||
using ASTArray = antlr.collections.impl.ASTArray;
|
||||
using ANTLRException = antlr.ANTLRException;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
|
||||
// HISTORY:
|
||||
//
|
||||
// 19-Aug-2002 kunle Augmented the basic flexibility of the default ASTFactory with a map
|
||||
// of TokenID-to-NodeTypeName. It's now a proper GoF-style Factory ;-)
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// AST Support code shared by TreeParser and Parser.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// We use delegation to share code (and have only one
|
||||
/// bit of code to maintain) rather than subclassing
|
||||
/// or superclassing (forces AST support code to be
|
||||
/// loaded even when you don't want to do AST stuff).
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Typically, <see cref="setASTNodeType"/> is used to specify the
|
||||
/// homogeneous type of node to create, but you can override
|
||||
/// <see cref="create()"/> to make heterogeneous nodes etc...
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public class ASTFactory
|
||||
{
|
||||
//---------------------------------------------------------------------
|
||||
// CONSTRUCTORS
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an <c>ASTFactory</c> with the default AST node type of
|
||||
/// <see cref="antlr.CommonAST"/>.
|
||||
/// </summary>
|
||||
public ASTFactory() : this("antlr.CommonAST")
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an <c>ASTFactory</c> and use the specified AST node type
|
||||
/// as the default.
|
||||
/// </summary>
|
||||
/// <param name="nodeTypeName">
|
||||
/// Name of default AST node type for this factory.
|
||||
/// </param>
|
||||
public ASTFactory(string nodeTypeName)
|
||||
{
|
||||
heteroList_ = new FactoryEntry[Token.MIN_USER_TYPE+1];
|
||||
defaultASTNodeTypeObject_ = loadNodeTypeObject(nodeTypeName);
|
||||
defaultCreator_ = null;
|
||||
typename2creator_ = new Hashtable(32, (float) 0.3);
|
||||
typename2creator_["antlr.CommonAST"] = CommonAST.Creator;
|
||||
typename2creator_["antlr.CommonASTWithHiddenTokens"] = CommonASTWithHiddenTokens.Creator;
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// DATA MEMBERS
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Stores the Type of the default AST node class to be used during tree construction.
|
||||
/// </summary>
|
||||
protected Type defaultASTNodeTypeObject_;
|
||||
protected ASTNodeCreator defaultCreator_;
|
||||
|
||||
/// <summary>
|
||||
/// Stores the mapping between custom AST NodeTypes and their NodeTypeName/NodeTypeClass
|
||||
/// and ASTNodeCreator.
|
||||
/// </summary>
|
||||
protected FactoryEntry[] heteroList_;
|
||||
|
||||
/// <summary>
|
||||
/// Stores the mapping between AST node typenames and their token ID.
|
||||
/// </summary>
|
||||
protected Hashtable typename2creator_;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// FUNCTION MEMBERS
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Specify an "override" for the <see cref="AST"/> type created for
|
||||
/// the specified Token type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method is useful for situations that ANTLR cannot oridinarily deal
|
||||
/// with (i.e., when you create a token based upon a nonliteral token symbol
|
||||
/// like #[LT(1)]. This is a runtime value and ANTLR cannot determine the token
|
||||
/// type (and hence the AST) statically.
|
||||
/// </remarks>
|
||||
/// <param name="tokenType">Token type to override.</param>
|
||||
/// <param name="NodeTypeName">
|
||||
/// Fully qualified AST typename (or null to specify
|
||||
/// the factory's default AST type).
|
||||
/// </param>
|
||||
public void setTokenTypeASTNodeType(int tokenType, string NodeTypeName)
|
||||
{
|
||||
// check validity of arguments...
|
||||
if( tokenType < Token.MIN_USER_TYPE )
|
||||
throw new ANTLRException("Internal parser error: Cannot change AST Node Type for Token ID '" + tokenType + "'");
|
||||
|
||||
// resize up to and including 'type' and initialize any gaps to default
|
||||
// factory.
|
||||
if (tokenType > (heteroList_.Length+1))
|
||||
setMaxNodeType(tokenType);
|
||||
// And add new thing..
|
||||
if (heteroList_[tokenType] == null)
|
||||
heteroList_[tokenType] = new FactoryEntry(loadNodeTypeObject(NodeTypeName));
|
||||
else
|
||||
heteroList_[tokenType].NodeTypeObject = loadNodeTypeObject(NodeTypeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register an AST Node Type for a given Token type ID.
|
||||
/// </summary>
|
||||
/// <param name="NodeType">The Token type ID.</param>
|
||||
/// <param name="NodeTypeName">The AST Node Type to register.</param>
|
||||
[Obsolete("Replaced by setTokenTypeASTNodeType(int, string) since version 2.7.2.6", true)]
|
||||
public void registerFactory(int NodeType, string NodeTypeName)
|
||||
{
|
||||
setTokenTypeASTNodeType(NodeType, NodeTypeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register an ASTNodeCreator for a given Token type ID.
|
||||
/// </summary>
|
||||
/// <param name="NodeType">The Token type ID.</param>
|
||||
/// <param name="creator">The creater to register.</param>
|
||||
public void setTokenTypeASTNodeCreator(int NodeType, ASTNodeCreator creator)
|
||||
{
|
||||
// check validity of arguments...
|
||||
if( NodeType < Token.MIN_USER_TYPE )
|
||||
throw new ANTLRException("Internal parser error: Cannot change AST Node Type for Token ID '" + NodeType + "'");
|
||||
|
||||
// resize up to and including 'type' and initialize any gaps to default
|
||||
// factory.
|
||||
if (NodeType > (heteroList_.Length+1))
|
||||
setMaxNodeType(NodeType);
|
||||
// And add new thing..
|
||||
if (heteroList_[NodeType] == null)
|
||||
heteroList_[NodeType] = new FactoryEntry(creator);
|
||||
else
|
||||
heteroList_[NodeType].Creator = creator;
|
||||
|
||||
//typename2creator_[NodeType.ToString()] = creator;
|
||||
typename2creator_[creator.ASTNodeTypeName] = creator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register an ASTNodeCreator to be used for creating node by default.
|
||||
/// </summary>
|
||||
/// <param name="creator">The ASTNodeCreator.</param>
|
||||
public void setASTNodeCreator(ASTNodeCreator creator)
|
||||
{
|
||||
defaultCreator_ = creator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pre-expands the internal list of TokenTypeID-to-ASTNodeType mappings
|
||||
/// to the specified size.
|
||||
/// This is primarily a convenience method that can be used to prevent
|
||||
/// unnecessary and costly re-org of the mappings list.
|
||||
/// </summary>
|
||||
/// <param name="NodeType">Maximum Token Type ID.</param>
|
||||
public void setMaxNodeType( int NodeType )
|
||||
{
|
||||
//Debug.WriteLine(this, "NodeType = " + NodeType + " and NodeList.Length = " + nodeTypeList_.Length);
|
||||
if (heteroList_ == null)
|
||||
{
|
||||
heteroList_ = new FactoryEntry[NodeType+1];
|
||||
}
|
||||
else
|
||||
{
|
||||
int length = heteroList_.Length;
|
||||
|
||||
if ( NodeType >= length )
|
||||
{
|
||||
FactoryEntry[] newList = new FactoryEntry[NodeType+1];
|
||||
Array.Copy(heteroList_, 0, newList, 0, length);
|
||||
heteroList_ = newList;
|
||||
}
|
||||
else if ( NodeType < length )
|
||||
{
|
||||
FactoryEntry[] newList = new FactoryEntry[NodeType+1];
|
||||
Array.Copy(heteroList_, 0, newList, 0, (NodeType+1));
|
||||
heteroList_ = newList;
|
||||
}
|
||||
}
|
||||
//Debug.WriteLine(this, "NodeType = " + NodeType + " and NodeList.Length = " + nodeTypeList_.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a child to the current AST
|
||||
/// </summary>
|
||||
/// <param name="currentAST">The AST to add a child to</param>
|
||||
/// <param name="child">The child AST to be added</param>
|
||||
public virtual void addASTChild(ref ASTPair currentAST, AST child)
|
||||
{
|
||||
if (child != null)
|
||||
{
|
||||
if (currentAST.root == null)
|
||||
{
|
||||
// Make new child the current root
|
||||
currentAST.root = child;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentAST.child == null)
|
||||
{
|
||||
// Add new child to current root
|
||||
currentAST.root.setFirstChild(child);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentAST.child.setNextSibling(child);
|
||||
}
|
||||
}
|
||||
// Make new child the current child
|
||||
currentAST.child = child;
|
||||
currentAST.advanceChildToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new uninitialized AST node. Since a specific AST Node Type
|
||||
/// wasn't indicated, the new AST node is created using the current default
|
||||
/// AST Node type - <see cref="defaultASTNodeTypeObject_"/>
|
||||
/// </summary>
|
||||
/// <returns>An uninitialized AST node object.</returns>
|
||||
public virtual AST create()
|
||||
{
|
||||
AST newNode;
|
||||
|
||||
if (defaultCreator_ == null)
|
||||
newNode = createFromNodeTypeObject(defaultASTNodeTypeObject_);
|
||||
else
|
||||
newNode = defaultCreator_.Create();
|
||||
|
||||
return newNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and initializes a new AST node using the specified Token Type ID.
|
||||
/// The <see cref="System.Type"/> used for creating this new AST node is
|
||||
/// determined by the following:
|
||||
/// <list type="bullet">
|
||||
/// <item>the current TokenTypeID-to-ASTNodeType mapping (if any) or,</item>
|
||||
/// <item>the <see cref="defaultASTNodeTypeObject_"/> otherwise</item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
/// <param name="type">Token type ID to be used to create new AST Node.</param>
|
||||
/// <returns>An initialized AST node object.</returns>
|
||||
public virtual AST create(int type)
|
||||
{
|
||||
AST newNode = createFromNodeType(type);
|
||||
newNode.initialize(type, "");
|
||||
return newNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and initializes a new AST node using the specified Token Type ID.
|
||||
/// The <see cref="System.Type"/> used for creating this new AST node is
|
||||
/// determined by the following:
|
||||
/// <list type="bullet">
|
||||
/// <item>the current TokenTypeID-to-ASTNodeType mapping (if any) or,</item>
|
||||
/// <item>the <see cref="defaultASTNodeTypeObject_"/> otherwise</item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
/// <param name="type">Token type ID to be used to create new AST Node.</param>
|
||||
/// <param name="txt">Text for initializing the new AST Node.</param>
|
||||
/// <returns>An initialized AST node object.</returns>
|
||||
public virtual AST create(int type, string txt)
|
||||
{
|
||||
AST newNode = createFromNodeType(type);
|
||||
newNode.initialize(type, txt);
|
||||
return newNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new AST node using the specified AST Node Type name. Once created,
|
||||
/// the new AST node is initialized with the specified Token type ID and string.
|
||||
/// The <see cref="System.Type"/> used for creating this new AST node is
|
||||
/// determined solely by <c>ASTNodeTypeName</c>.
|
||||
/// The AST Node type must have a default/parameterless constructor.
|
||||
/// </summary>
|
||||
/// <param name="type">Token type ID to be used to create new AST Node.</param>
|
||||
/// <param name="txt">Text for initializing the new AST Node.</param>
|
||||
/// <param name="ASTNodeTypeName">Fully qualified name of the Type to be used for creating the new AST Node.</param>
|
||||
/// <returns>An initialized AST node object.</returns>
|
||||
public virtual AST create(int type, string txt, string ASTNodeTypeName)
|
||||
{
|
||||
AST newNode = createFromNodeName(ASTNodeTypeName);
|
||||
newNode.initialize(type, txt);
|
||||
return newNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new AST node using the specified AST Node Type name.
|
||||
/// </summary>
|
||||
/// <param name="tok">Token instance to be used to initialize the new AST Node.</param>
|
||||
/// <param name="ASTNodeTypeName">
|
||||
/// Fully qualified name of the Type to be used for creating the new AST Node.
|
||||
/// </param>
|
||||
/// <returns>A newly created and initialized AST node object.</returns>
|
||||
/// <remarks>
|
||||
/// Once created, the new AST node is initialized with the specified Token
|
||||
/// instance. The <see cref="System.Type"/> used for creating this new AST
|
||||
/// node is determined solely by <c>ASTNodeTypeName</c>.
|
||||
/// <para>The AST Node type must have a default/parameterless constructor.</para>
|
||||
/// </remarks>
|
||||
public virtual AST create(IToken tok, string ASTNodeTypeName)
|
||||
{
|
||||
AST newNode = createFromNodeName(ASTNodeTypeName);
|
||||
newNode.initialize(tok);
|
||||
return newNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and initializes a new AST node using the specified AST Node instance.
|
||||
/// the new AST node is initialized with the specified Token type ID and string.
|
||||
/// The <see cref="System.Type"/> used for creating this new AST node is
|
||||
/// determined solely by <c>aNode</c>.
|
||||
/// The AST Node type must have a default/parameterless constructor.
|
||||
/// </summary>
|
||||
/// <param name="aNode">AST Node instance to be used for creating the new AST Node.</param>
|
||||
/// <returns>An initialized AST node object.</returns>
|
||||
public virtual AST create(AST aNode)
|
||||
{
|
||||
AST newNode;
|
||||
|
||||
if (aNode == null)
|
||||
newNode = null;
|
||||
else
|
||||
{
|
||||
newNode = createFromAST(aNode);
|
||||
newNode.initialize(aNode);
|
||||
}
|
||||
return newNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and initializes a new AST node using the specified Token instance.
|
||||
/// The <see cref="System.Type"/> used for creating this new AST node is
|
||||
/// determined by the following:
|
||||
/// <list type="bullet">
|
||||
/// <item>the current TokenTypeID-to-ASTNodeType mapping (if any) or,</item>
|
||||
/// <item>the <see cref="defaultASTNodeTypeObject_"/> otherwise</item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
/// <param name="tok">Token instance to be used to create new AST Node.</param>
|
||||
/// <returns>An initialized AST node object.</returns>
|
||||
public virtual AST create(IToken tok)
|
||||
{
|
||||
AST newNode;
|
||||
|
||||
if (tok == null)
|
||||
newNode = null;
|
||||
else
|
||||
{
|
||||
newNode = createFromNodeType(tok.Type);
|
||||
newNode.initialize(tok);
|
||||
}
|
||||
return newNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a copy of the specified AST Node instance. The copy is obtained by
|
||||
/// using the <see cref="ICloneable"/> method Clone().
|
||||
/// </summary>
|
||||
/// <param name="t">AST Node to copy.</param>
|
||||
/// <returns>An AST Node (or null if <c>t</c> is null).</returns>
|
||||
public virtual AST dup(AST t)
|
||||
{
|
||||
// The Java version is implemented using code like this:
|
||||
if (t == null)
|
||||
return null;
|
||||
|
||||
AST dup_edNode = createFromAST(t);
|
||||
dup_edNode.initialize(t);
|
||||
return dup_edNode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Duplicate AST Node tree rooted at specified AST node and all of it's siblings.
|
||||
/// </summary>
|
||||
/// <param name="t">Root of AST Node tree.</param>
|
||||
/// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
|
||||
public virtual AST dupList(AST t)
|
||||
{
|
||||
AST result = dupTree(t); // if t == null, then result==null
|
||||
AST nt = result;
|
||||
while (t != null)
|
||||
{
|
||||
// for each sibling of the root
|
||||
t = t.getNextSibling();
|
||||
nt.setNextSibling(dupTree(t)); // dup each subtree, building new tree
|
||||
nt = nt.getNextSibling();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Duplicate AST Node tree rooted at specified AST node. Ignore it's siblings.
|
||||
/// </summary>
|
||||
/// <param name="t">Root of AST Node tree.</param>
|
||||
/// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
|
||||
public virtual AST dupTree(AST t)
|
||||
{
|
||||
AST result = dup(t); // make copy of root
|
||||
// copy all children of root.
|
||||
if (t != null)
|
||||
{
|
||||
result.setFirstChild(dupList(t.getFirstChild()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a tree from a list of nodes. The first element in the
|
||||
/// array is the root. If the root is null, then the tree is
|
||||
/// a simple list not a tree. Handles null children nodes correctly.
|
||||
/// For example, build(a, b, null, c) yields tree (a b c). build(null,a,b)
|
||||
/// yields tree (nil a b).
|
||||
/// </summary>
|
||||
/// <param name="nodes">List of Nodes.</param>
|
||||
/// <returns>AST Node tree.</returns>
|
||||
public virtual AST make(params AST[] nodes)
|
||||
{
|
||||
if (nodes == null || nodes.Length == 0)
|
||||
return null;
|
||||
AST root = nodes[0];
|
||||
AST tail = null;
|
||||
if (root != null)
|
||||
{
|
||||
root.setFirstChild(null); // don't leave any old pointers set
|
||||
}
|
||||
// link in children;
|
||||
for (int i = 1; i < nodes.Length; i++)
|
||||
{
|
||||
if (nodes[i] == null)
|
||||
continue;
|
||||
// ignore null nodes
|
||||
if (root == null)
|
||||
{
|
||||
// Set the root and set it up for a flat list
|
||||
root = (tail = nodes[i]);
|
||||
}
|
||||
else if (tail == null)
|
||||
{
|
||||
root.setFirstChild(nodes[i]);
|
||||
tail = root.getFirstChild();
|
||||
}
|
||||
else
|
||||
{
|
||||
tail.setNextSibling(nodes[i]);
|
||||
tail = tail.getNextSibling();
|
||||
}
|
||||
// Chase tail to last sibling
|
||||
while (tail.getNextSibling() != null)
|
||||
{
|
||||
tail = tail.getNextSibling();
|
||||
}
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a tree from a list of nodes, where the nodes are contained
|
||||
/// in an ASTArray object.
|
||||
/// </summary>
|
||||
/// <param name="nodes">List of Nodes.</param>
|
||||
/// <returns>AST Node tree.</returns>
|
||||
public virtual AST make(ASTArray nodes)
|
||||
{
|
||||
return make(nodes.array);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make an AST the root of current AST.
|
||||
/// </summary>
|
||||
/// <param name="currentAST"></param>
|
||||
/// <param name="root"></param>
|
||||
public virtual void makeASTRoot(ref ASTPair currentAST, AST root)
|
||||
{
|
||||
if (root != null)
|
||||
{
|
||||
// Add the current root as a child of new root
|
||||
root.addChild(currentAST.root);
|
||||
// The new current child is the last sibling of the old root
|
||||
currentAST.child = currentAST.root;
|
||||
currentAST.advanceChildToEnd();
|
||||
// Set the new root
|
||||
currentAST.root = root;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the global default AST Node Type for this ASTFactory instance.
|
||||
/// This method also attempts to load the <see cref="System.Type"/> instance
|
||||
/// for the specified typename.
|
||||
/// </summary>
|
||||
/// <param name="t">Fully qualified AST Node Type name.</param>
|
||||
public virtual void setASTNodeType(string t)
|
||||
{
|
||||
if (defaultCreator_ != null)
|
||||
{
|
||||
if (t != defaultCreator_.ASTNodeTypeName)
|
||||
{
|
||||
defaultCreator_ = null;
|
||||
}
|
||||
}
|
||||
defaultASTNodeTypeObject_ = loadNodeTypeObject(t);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// To change where error messages go, can subclass/override this method
|
||||
/// and then setASTFactory in Parser and TreeParser. This method removes
|
||||
/// a prior dependency on class antlr.Tool.
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
public virtual void error(string e)
|
||||
{
|
||||
Console.Error.WriteLine(e);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// PRIVATE FUNCTION MEMBERS
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
private Type loadNodeTypeObject(string nodeTypeName)
|
||||
{
|
||||
Type nodeTypeObject = null;
|
||||
bool typeCreated = false;
|
||||
|
||||
if (nodeTypeName != null)
|
||||
{
|
||||
foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
try
|
||||
{
|
||||
nodeTypeObject = assem.GetType(nodeTypeName);
|
||||
if (nodeTypeObject != null)
|
||||
{
|
||||
typeCreated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
typeCreated = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!typeCreated)
|
||||
{
|
||||
throw new TypeLoadException("Unable to load AST Node Type: '" + nodeTypeName + "'");
|
||||
}
|
||||
return nodeTypeObject;
|
||||
}
|
||||
|
||||
private AST createFromAST(AST node)
|
||||
{
|
||||
AST newNode = null;
|
||||
Type nodeAsTypeObj = node.GetType();
|
||||
|
||||
ASTNodeCreator creator = (ASTNodeCreator) typename2creator_[nodeAsTypeObj.FullName];
|
||||
if (creator != null)
|
||||
{
|
||||
newNode = creator.Create();
|
||||
if (newNode == null)
|
||||
{
|
||||
throw new ArgumentException("Unable to create AST Node Type: '" + nodeAsTypeObj.FullName + "'");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newNode = createFromNodeTypeObject(nodeAsTypeObj);
|
||||
}
|
||||
return newNode;
|
||||
}
|
||||
|
||||
private AST createFromNodeName(string nodeTypeName)
|
||||
{
|
||||
AST newNode = null;
|
||||
|
||||
ASTNodeCreator creator = (ASTNodeCreator) typename2creator_[nodeTypeName];
|
||||
if (creator != null)
|
||||
{
|
||||
newNode = creator.Create();
|
||||
if (newNode == null)
|
||||
{
|
||||
throw new ArgumentException("Unable to create AST Node Type: '" + nodeTypeName + "'");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newNode = createFromNodeTypeObject( loadNodeTypeObject(nodeTypeName) );
|
||||
}
|
||||
return newNode;
|
||||
}
|
||||
|
||||
private AST createFromNodeType(int nodeTypeIndex)
|
||||
{
|
||||
Debug.Assert((nodeTypeIndex >= 0) && (nodeTypeIndex <= heteroList_.Length), "Invalid AST node type!");
|
||||
AST newNode = null;
|
||||
|
||||
FactoryEntry entry = heteroList_[nodeTypeIndex];
|
||||
if ((entry != null) && (entry.Creator != null))
|
||||
{
|
||||
newNode = entry.Creator.Create();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((entry == null) || (entry.NodeTypeObject == null))
|
||||
{
|
||||
if (defaultCreator_ == null)
|
||||
{
|
||||
newNode = createFromNodeTypeObject(defaultASTNodeTypeObject_);
|
||||
}
|
||||
else
|
||||
newNode = defaultCreator_.Create();
|
||||
}
|
||||
else
|
||||
newNode = createFromNodeTypeObject( entry.NodeTypeObject );
|
||||
}
|
||||
return newNode;
|
||||
}
|
||||
|
||||
private AST createFromNodeTypeObject(Type nodeTypeObject)
|
||||
{
|
||||
AST newNode = null;
|
||||
|
||||
try
|
||||
{
|
||||
newNode = (AST) Activator.CreateInstance(nodeTypeObject);
|
||||
if (newNode == null)
|
||||
{
|
||||
throw new ArgumentException("Unable to create AST Node Type: '" + nodeTypeObject.FullName + "'");
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
throw new ArgumentException("Unable to create AST Node Type: '" + nodeTypeObject.FullName + "'", ex);
|
||||
}
|
||||
return newNode;
|
||||
}
|
||||
|
||||
protected class FactoryEntry
|
||||
{
|
||||
public FactoryEntry(Type typeObj, ASTNodeCreator creator)
|
||||
{
|
||||
NodeTypeObject = typeObj;
|
||||
Creator = creator;
|
||||
}
|
||||
|
||||
public FactoryEntry(Type typeObj)
|
||||
{
|
||||
NodeTypeObject = typeObj;
|
||||
}
|
||||
|
||||
public FactoryEntry(ASTNodeCreator creator)
|
||||
{
|
||||
Creator = creator;
|
||||
}
|
||||
|
||||
public Type NodeTypeObject;
|
||||
public ASTNodeCreator Creator;
|
||||
}
|
||||
}
|
||||
}
|
||||
123
src/Spring/Spring.Core/antlr/ASTNULLType.cs
Normal file
123
src/Spring/Spring.Core/antlr/ASTNULLType.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using IEnumerator = System.Collections.IEnumerator;
|
||||
|
||||
using AST = antlr.collections.AST;
|
||||
using Token = antlr.Token;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*There is only one instance of this class **/
|
||||
public class ASTNULLType : AST
|
||||
{
|
||||
public virtual void addChild(AST c) {}
|
||||
|
||||
public virtual bool Equals(AST t)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public virtual bool EqualsList(AST t)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public virtual bool EqualsListPartial(AST t)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public virtual bool EqualsTree(AST t)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public virtual bool EqualsTreePartial(AST t)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public virtual IEnumerator findAll(AST tree)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public virtual IEnumerator findAllPartial(AST subtree)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public virtual AST getFirstChild()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public virtual AST getNextSibling()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public virtual string getText()
|
||||
{
|
||||
return "<ASTNULL>";
|
||||
}
|
||||
public virtual int Type
|
||||
{
|
||||
get { return Token.NULL_TREE_LOOKAHEAD; }
|
||||
set { ; }
|
||||
}
|
||||
public int getNumberOfChildren()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public virtual void initialize(int t, string txt)
|
||||
{
|
||||
}
|
||||
public virtual void initialize(AST t)
|
||||
{
|
||||
}
|
||||
public virtual void initialize(IToken t)
|
||||
{
|
||||
}
|
||||
public virtual void setFirstChild(AST c)
|
||||
{
|
||||
;
|
||||
}
|
||||
public virtual void setNextSibling(AST n)
|
||||
{
|
||||
;
|
||||
}
|
||||
public virtual void setText(string text)
|
||||
{
|
||||
;
|
||||
}
|
||||
public virtual void setType(int ttype)
|
||||
{
|
||||
this.Type = ttype;
|
||||
}
|
||||
override public string ToString()
|
||||
{
|
||||
return getText();
|
||||
}
|
||||
public virtual string ToStringList()
|
||||
{
|
||||
return getText();
|
||||
}
|
||||
public virtual string ToStringTree()
|
||||
{
|
||||
return getText();
|
||||
}
|
||||
|
||||
#region Implementation of ICloneable
|
||||
public object Clone()
|
||||
{
|
||||
return MemberwiseClone();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
52
src/Spring/Spring.Core/antlr/ASTNodeCreator.cs
Normal file
52
src/Spring/Spring.Core/antlr/ASTNodeCreator.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
namespace antlr
|
||||
{
|
||||
using System;
|
||||
using AST = antlr.collections.AST;
|
||||
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// A creator of AST node instances.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This class and it's sub-classes exists primarily as an optimization
|
||||
/// of the reflection-based mechanism(s) previously used exclusively to
|
||||
/// create instances of AST node objects.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Parsers and TreeParsers already use the ASTFactory class in ANTLR whenever
|
||||
/// they need to create an AST node objeect. What this class does is to support
|
||||
/// performant extensibility of the basic ASTFactory. The ASTFactory can now be
|
||||
/// extnded as run-time to support more new AST node types without using needing
|
||||
/// to use reflection.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public abstract class ASTNodeCreator
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the fully qualified name of the AST type that this
|
||||
/// class creates.
|
||||
/// </summary>
|
||||
public abstract string ASTNodeTypeName
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an <see cref="AST"/> instance.
|
||||
/// </summary>
|
||||
public abstract AST Create();
|
||||
}
|
||||
}
|
||||
68
src/Spring/Spring.Core/antlr/ASTPair.cs
Normal file
68
src/Spring/Spring.Core/antlr/ASTPair.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
namespace antlr
|
||||
{
|
||||
using System;
|
||||
using Queue = System.Collections.Queue;
|
||||
using AST = antlr.collections.AST;
|
||||
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
|
||||
/*ASTPair: utility class used for manipulating a pair of ASTs
|
||||
* representing the current AST root and current AST sibling.
|
||||
* This exists to compensate for the lack of pointers or 'var'
|
||||
* arguments in Java.
|
||||
*/
|
||||
|
||||
public struct ASTPair
|
||||
{
|
||||
public AST root; // current root of tree
|
||||
public AST child; // current child to which siblings are added
|
||||
|
||||
/*Make sure that child is the last sibling */
|
||||
public void advanceChildToEnd()
|
||||
{
|
||||
if (child != null)
|
||||
{
|
||||
while (child.getNextSibling() != null)
|
||||
{
|
||||
child = child.getNextSibling();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*Copy an ASTPair. Don't call it clone() because we want type-safety */
|
||||
public ASTPair copy()
|
||||
{
|
||||
ASTPair tmp = new ASTPair();
|
||||
tmp.root = root;
|
||||
tmp.child = child;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
private void reset()
|
||||
{
|
||||
root = null;
|
||||
child = null;
|
||||
}
|
||||
|
||||
override public string ToString()
|
||||
{
|
||||
string r = (root == null) ? "null" : root.getText();
|
||||
string c = (child == null) ? "null" : child.getText();
|
||||
return "[" + r + "," + c + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/Spring/Spring.Core/antlr/ASTVisitor.cs
Normal file
29
src/Spring/Spring.Core/antlr/ASTVisitor.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
|
||||
using AST = antlr.collections.AST;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/* ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for ASTVisitor.
|
||||
/// </summary>
|
||||
public interface ASTVisitor
|
||||
{
|
||||
void visit(AST node);
|
||||
}
|
||||
}
|
||||
616
src/Spring/Spring.Core/antlr/BaseAST.cs
Normal file
616
src/Spring/Spring.Core/antlr/BaseAST.cs
Normal file
@@ -0,0 +1,616 @@
|
||||
using System;
|
||||
using StringBuilder = System.Text.StringBuilder;
|
||||
using ISerializable = System.Runtime.Serialization.ISerializable;
|
||||
using TextWriter = System.IO.TextWriter;
|
||||
using ArrayList = System.Collections.ArrayList;
|
||||
using IEnumerator = System.Collections.IEnumerator;
|
||||
|
||||
using AST = antlr.collections.AST;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*
|
||||
* A Child-Sibling Tree.
|
||||
*
|
||||
* A tree with PLUS at the root and with two children 3 and 4 is
|
||||
* structured as:
|
||||
*
|
||||
* PLUS
|
||||
* |
|
||||
* 3 -- 4
|
||||
*
|
||||
* and can be specified easily in LISP notation as
|
||||
*
|
||||
* (PLUS 3 4)
|
||||
*
|
||||
* where every '(' starts a new subtree.
|
||||
*
|
||||
* These trees are particular useful for translators because of
|
||||
* the flexibility of the children lists. They are also very easy
|
||||
* to walk automatically, whereas trees with specific children
|
||||
* reference fields can't easily be walked automatically.
|
||||
*
|
||||
* This class contains the basic support for an AST.
|
||||
* Most people will create ASTs that are subclasses of
|
||||
* BaseAST or of CommonAST.
|
||||
*/
|
||||
[Serializable()]
|
||||
public abstract class BaseAST : AST
|
||||
{
|
||||
protected internal BaseAST down;
|
||||
protected internal BaseAST right;
|
||||
|
||||
private static bool verboseStringConversion = false;
|
||||
private static string[] tokenNames = null;
|
||||
|
||||
/*Add a node to the end of the child list for this node */
|
||||
public virtual void addChild(AST node)
|
||||
{
|
||||
if (node == null)
|
||||
return ;
|
||||
BaseAST t = this.down;
|
||||
if (t != null)
|
||||
{
|
||||
while (t.right != null)
|
||||
{
|
||||
t = t.right;
|
||||
}
|
||||
t.right = (BaseAST) node;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.down = (BaseAST) node;
|
||||
}
|
||||
}
|
||||
|
||||
private void doWorkForFindAll(ArrayList v, AST target, bool partialMatch)
|
||||
{
|
||||
AST sibling;
|
||||
|
||||
// Start walking sibling lists, looking for matches.
|
||||
//siblingWalk:
|
||||
for (sibling = this; sibling != null; sibling = sibling.getNextSibling())
|
||||
{
|
||||
if ((partialMatch && sibling.EqualsTreePartial(target)) || (!partialMatch && sibling.EqualsTree(target)))
|
||||
{
|
||||
v.Add(sibling);
|
||||
}
|
||||
// regardless of match or not, check any children for matches
|
||||
if (sibling.getFirstChild() != null)
|
||||
{
|
||||
((BaseAST) sibling.getFirstChild()).doWorkForFindAll(v, target, partialMatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (this.GetType() != obj.GetType())
|
||||
return false;
|
||||
return Equals((AST)obj);
|
||||
}
|
||||
|
||||
/*Is node t equal to this in terms of token type and text? */
|
||||
public virtual bool Equals(AST t)
|
||||
{
|
||||
if (t == null)
|
||||
return false;
|
||||
|
||||
return (Object.Equals(this.getText(), t.getText())) &&
|
||||
(this.Type == t.Type);
|
||||
}
|
||||
|
||||
/*Is t an exact structural and equals() match of this tree. The
|
||||
* 'this' reference is considered the start of a sibling list.
|
||||
*/
|
||||
public virtual bool EqualsList(AST t)
|
||||
{
|
||||
AST sibling;
|
||||
|
||||
// the empty tree is not a match of any non-null tree.
|
||||
if (t == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise, start walking sibling lists. First mismatch, return false.
|
||||
for (sibling = this; sibling != null && t != null; sibling = sibling.getNextSibling(), t = t.getNextSibling())
|
||||
{
|
||||
// as a quick optimization, check roots first.
|
||||
if (!sibling.Equals(t))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// if roots match, do full list match test on children.
|
||||
if (sibling.getFirstChild() != null)
|
||||
{
|
||||
if (!sibling.getFirstChild().EqualsList(t.getFirstChild()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (t.getFirstChild() != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (sibling == null && t == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// one sibling list has more than the other
|
||||
return false;
|
||||
}
|
||||
|
||||
/*Is 'sub' a subtree of this list?
|
||||
* The siblings of the root are NOT ignored.
|
||||
*/
|
||||
public virtual bool EqualsListPartial(AST sub)
|
||||
{
|
||||
AST sibling;
|
||||
|
||||
// the empty tree is always a subset of any tree.
|
||||
if (sub == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, start walking sibling lists. First mismatch, return false.
|
||||
for (sibling = this; sibling != null && sub != null; sibling = sibling.getNextSibling(), sub = sub.getNextSibling())
|
||||
{
|
||||
// as a quick optimization, check roots first.
|
||||
if (!sibling.Equals(sub))
|
||||
return false;
|
||||
// if roots match, do partial list match test on children.
|
||||
if (sibling.getFirstChild() != null)
|
||||
{
|
||||
if (!sibling.getFirstChild().EqualsListPartial(sub.getFirstChild()))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (sibling == null && sub != null)
|
||||
{
|
||||
// nothing left to match in this tree, but subtree has more
|
||||
return false;
|
||||
}
|
||||
// either both are null or sibling has more, but subtree doesn't
|
||||
return true;
|
||||
}
|
||||
|
||||
/*Is tree rooted at 'this' equal to 't'? The siblings
|
||||
* of 'this' are ignored.
|
||||
*/
|
||||
public virtual bool EqualsTree(AST t)
|
||||
{
|
||||
// check roots first.
|
||||
if (!this.Equals(t))
|
||||
return false;
|
||||
// if roots match, do full list match test on children.
|
||||
if (this.getFirstChild() != null)
|
||||
{
|
||||
if (!this.getFirstChild().EqualsList(t.getFirstChild()))
|
||||
return false;
|
||||
}
|
||||
else if (t.getFirstChild() != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*Is 't' a subtree of the tree rooted at 'this'? The siblings
|
||||
* of 'this' are ignored.
|
||||
*/
|
||||
public virtual bool EqualsTreePartial(AST sub)
|
||||
{
|
||||
// the empty tree is always a subset of any tree.
|
||||
if (sub == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// check roots first.
|
||||
if (!this.Equals(sub))
|
||||
return false;
|
||||
// if roots match, do full list partial match test on children.
|
||||
if (this.getFirstChild() != null)
|
||||
{
|
||||
if (!this.getFirstChild().EqualsListPartial(sub.getFirstChild()))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*Walk the tree looking for all exact subtree matches. Return
|
||||
* an IEnumerator that lets the caller walk the list
|
||||
* of subtree roots found herein.
|
||||
*/
|
||||
public virtual IEnumerator findAll(AST target)
|
||||
{
|
||||
ArrayList roots = new ArrayList(10);
|
||||
//AST sibling;
|
||||
|
||||
// the empty tree cannot result in an enumeration
|
||||
if (target == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
doWorkForFindAll(roots, target, false); // find all matches recursively
|
||||
|
||||
return roots.GetEnumerator();
|
||||
}
|
||||
|
||||
/*Walk the tree looking for all subtrees. Return
|
||||
* an IEnumerator that lets the caller walk the list
|
||||
* of subtree roots found herein.
|
||||
*/
|
||||
public virtual IEnumerator findAllPartial(AST sub)
|
||||
{
|
||||
ArrayList roots = new ArrayList(10);
|
||||
//AST sibling;
|
||||
|
||||
// the empty tree cannot result in an enumeration
|
||||
if (sub == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
doWorkForFindAll(roots, sub, true); // find all matches recursively
|
||||
|
||||
return roots.GetEnumerator();
|
||||
}
|
||||
|
||||
/*Get the first child of this node; null if not children */
|
||||
public virtual AST getFirstChild()
|
||||
{
|
||||
return down;
|
||||
}
|
||||
|
||||
/*Get the next sibling in line after this one */
|
||||
public virtual AST getNextSibling()
|
||||
{
|
||||
return right;
|
||||
}
|
||||
|
||||
/*Get the token text for this node */
|
||||
public virtual string getText()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
/*Get the token type for this node */
|
||||
public virtual int Type
|
||||
{
|
||||
get { return 0; }
|
||||
set { ; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get number of children of this node; if leaf, returns 0
|
||||
/// </summary>
|
||||
/// <returns>Number of children</returns>
|
||||
public int getNumberOfChildren()
|
||||
{
|
||||
BaseAST t = this.down;
|
||||
int n = 0;
|
||||
if (t != null)
|
||||
{
|
||||
n = 1;
|
||||
while (t.right != null)
|
||||
{
|
||||
t = t.right;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public abstract void initialize(int t, string txt);
|
||||
|
||||
public abstract void initialize(AST t);
|
||||
|
||||
public abstract void initialize(IToken t);
|
||||
|
||||
/*Remove all children */
|
||||
public virtual void removeChildren()
|
||||
{
|
||||
down = null;
|
||||
}
|
||||
|
||||
public virtual void setFirstChild(AST c)
|
||||
{
|
||||
down = (BaseAST) c;
|
||||
}
|
||||
|
||||
public virtual void setNextSibling(AST n)
|
||||
{
|
||||
right = (BaseAST) n;
|
||||
}
|
||||
|
||||
/*Set the token text for this node */
|
||||
public virtual void setText(string text)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
/*Set the token type for this node */
|
||||
public virtual void setType(int ttype)
|
||||
{
|
||||
this.Type = ttype;
|
||||
}
|
||||
|
||||
public static void setVerboseStringConversion(bool verbose, string[] names)
|
||||
{
|
||||
verboseStringConversion = verbose;
|
||||
tokenNames = names;
|
||||
}
|
||||
|
||||
override public string ToString()
|
||||
{
|
||||
StringBuilder b = new StringBuilder();
|
||||
// if verbose and type name not same as text (keyword probably)
|
||||
if (verboseStringConversion &&
|
||||
(0 != String.Compare(getText(), (tokenNames[Type]), true)) &&
|
||||
(0 != String.Compare(getText(), StringUtils.stripFrontBack(tokenNames[Type], @"""", @""""), true)))
|
||||
{
|
||||
b.Append('[');
|
||||
b.Append(getText());
|
||||
b.Append(",<");
|
||||
b.Append(tokenNames[Type]);
|
||||
b.Append(">]");
|
||||
return b.ToString();
|
||||
}
|
||||
return getText();
|
||||
}
|
||||
|
||||
/*Print out a child-sibling tree in LISP notation */
|
||||
public virtual string ToStringList()
|
||||
{
|
||||
AST t = this;
|
||||
string ts = "";
|
||||
if (t.getFirstChild() != null)
|
||||
ts += " (";
|
||||
ts += " " + this.ToString();
|
||||
if (t.getFirstChild() != null)
|
||||
{
|
||||
ts += ((BaseAST) t.getFirstChild()).ToStringList();
|
||||
}
|
||||
if (t.getFirstChild() != null)
|
||||
ts += " )";
|
||||
if (t.getNextSibling() != null)
|
||||
{
|
||||
ts += ((BaseAST) t.getNextSibling()).ToStringList();
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
public virtual string ToStringTree()
|
||||
{
|
||||
AST t = this;
|
||||
string ts = "";
|
||||
if (t.getFirstChild() != null)
|
||||
{
|
||||
ts += " (";
|
||||
}
|
||||
ts += " " + this.ToString();
|
||||
if (t.getFirstChild() != null)
|
||||
{
|
||||
ts += ((BaseAST) t.getFirstChild()).ToStringList();
|
||||
}
|
||||
if (t.getFirstChild() != null)
|
||||
{
|
||||
ts += " )";
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
public virtual string ToTree()
|
||||
{
|
||||
return ToTree(string.Empty);
|
||||
}
|
||||
|
||||
public virtual string ToTree(string prefix)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(prefix);
|
||||
|
||||
// Replace vertical bar if there is no next sibling.
|
||||
if ( (getNextSibling() == null) )
|
||||
sb.Append("+--");
|
||||
else
|
||||
sb.Append("|--");
|
||||
|
||||
sb.Append( ToString() );
|
||||
sb.Append( Environment.NewLine );
|
||||
|
||||
if ( getFirstChild() != null )
|
||||
{
|
||||
// Replace vertical bar if there is no next sibling.
|
||||
if ( getNextSibling() == null )
|
||||
sb.Append( ((BaseAST) getFirstChild()).ToTree(prefix + " ") );
|
||||
else
|
||||
sb.Append( ((BaseAST) getFirstChild()).ToTree(prefix + "| ") );
|
||||
}
|
||||
|
||||
if ( getNextSibling() != null )
|
||||
sb.Append( ((BaseAST) getNextSibling()).ToTree(prefix) );
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string decode(string text)
|
||||
{
|
||||
char c, c1, c2, c3, c4, c5;
|
||||
StringBuilder n = new StringBuilder();
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
c = text[i];
|
||||
if (c == '&')
|
||||
{
|
||||
c1 = text[i + 1];
|
||||
c2 = text[i + 2];
|
||||
c3 = text[i + 3];
|
||||
c4 = text[i + 4];
|
||||
c5 = text[i + 5];
|
||||
|
||||
if (c1 == 'a' && c2 == 'm' && c3 == 'p' && c4 == ';')
|
||||
{
|
||||
n.Append("&");
|
||||
i += 5;
|
||||
}
|
||||
else if (c1 == 'l' && c2 == 't' && c3 == ';')
|
||||
{
|
||||
n.Append("<");
|
||||
i += 4;
|
||||
}
|
||||
else if (c1 == 'g' && c2 == 't' && c3 == ';')
|
||||
{
|
||||
n.Append(">");
|
||||
i += 4;
|
||||
}
|
||||
else if (c1 == 'q' && c2 == 'u' && c3 == 'o' && c4 == 't' && c5 == ';')
|
||||
{
|
||||
n.Append("\"");
|
||||
i += 6;
|
||||
}
|
||||
else if (c1 == 'a' && c2 == 'p' && c3 == 'o' && c4 == 's' && c5 == ';')
|
||||
{
|
||||
n.Append("'");
|
||||
i += 6;
|
||||
}
|
||||
else
|
||||
n.Append("&");
|
||||
}
|
||||
else
|
||||
n.Append(c);
|
||||
}
|
||||
return n.ToString();
|
||||
}
|
||||
|
||||
public static string encode(string text)
|
||||
{
|
||||
char c;
|
||||
StringBuilder n = new StringBuilder();
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
c = text[i];
|
||||
switch (c)
|
||||
{
|
||||
case '&':
|
||||
{
|
||||
n.Append("&");
|
||||
break;
|
||||
}
|
||||
|
||||
case '<':
|
||||
{
|
||||
n.Append("<");
|
||||
break;
|
||||
}
|
||||
|
||||
case '>':
|
||||
{
|
||||
n.Append(">");
|
||||
break;
|
||||
}
|
||||
|
||||
case '"':
|
||||
{
|
||||
n.Append(""");
|
||||
break;
|
||||
}
|
||||
|
||||
case '\'':
|
||||
{
|
||||
n.Append("'");
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
n.Append(c);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return n.ToString();
|
||||
}
|
||||
|
||||
public virtual void xmlSerializeNode(TextWriter outWriter)
|
||||
{
|
||||
StringBuilder buf = new StringBuilder(100);
|
||||
buf.Append("<");
|
||||
buf.Append(GetType().FullName + " ");
|
||||
buf.Append("text=\"" + encode(getText()) + "\" type=\"" + Type + "\"/>");
|
||||
outWriter.Write(buf.ToString());
|
||||
}
|
||||
|
||||
public virtual void xmlSerializeRootOpen(TextWriter outWriter)
|
||||
{
|
||||
StringBuilder buf = new StringBuilder(100);
|
||||
buf.Append("<");
|
||||
buf.Append(GetType().FullName + " ");
|
||||
buf.Append("text=\"" + encode(getText()) + "\" type=\"" + Type + "\">\n");
|
||||
outWriter.Write(buf.ToString());
|
||||
}
|
||||
|
||||
public virtual void xmlSerializeRootClose(TextWriter outWriter)
|
||||
{
|
||||
outWriter.Write("</" + GetType().FullName + ">\n");
|
||||
}
|
||||
|
||||
public virtual void xmlSerialize(TextWriter outWriter)
|
||||
{
|
||||
// print out this node and all siblings
|
||||
for (AST node = this; node != null; node = node.getNextSibling())
|
||||
{
|
||||
if (node.getFirstChild() == null)
|
||||
{
|
||||
// print guts (class name, attributes)
|
||||
((BaseAST) node).xmlSerializeNode(outWriter);
|
||||
}
|
||||
else
|
||||
{
|
||||
((BaseAST) node).xmlSerializeRootOpen(outWriter);
|
||||
|
||||
// print children
|
||||
((BaseAST) node.getFirstChild()).xmlSerialize(outWriter);
|
||||
|
||||
// print end tag
|
||||
((BaseAST) node).xmlSerializeRootClose(outWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Implementation of ICloneable
|
||||
[Obsolete("Deprecated since version 2.7.2. Use ASTFactory.dup() instead.", false)]
|
||||
public virtual object Clone()
|
||||
{
|
||||
return MemberwiseClone();
|
||||
}
|
||||
#endregion
|
||||
|
||||
public override Int32 GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
93
src/Spring/Spring.Core/antlr/ByteBuffer.cs
Normal file
93
src/Spring/Spring.Core/antlr/ByteBuffer.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Stream = System.IO.Stream;
|
||||
using BinaryReader = System.IO.BinaryReader;
|
||||
using IOException = System.IO.IOException;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*A Stream of characters fed to the lexer from a InputStream that can
|
||||
* be rewound via mark()/rewind() methods.
|
||||
* <p>
|
||||
* A dynamic array is used to buffer up all the input characters. Normally,
|
||||
* "k" characters are stored in the buffer. More characters may be stored during
|
||||
* guess mode (testing syntactic predicate), or when LT(i>k) is referenced.
|
||||
* Consumption of characters is deferred. In other words, reading the next
|
||||
* character is not done by conume(), but deferred until needed by LA or LT.
|
||||
* <p>
|
||||
*/
|
||||
|
||||
// SAS: added this class to handle Binary input w/ FileInputStream
|
||||
|
||||
public class ByteBuffer:InputBuffer
|
||||
{
|
||||
|
||||
// char source
|
||||
[NonSerialized()]
|
||||
internal Stream input;
|
||||
|
||||
private const int BUF_SIZE = 16;
|
||||
/// <summary>
|
||||
/// Small buffer used to avoid reading individual chars
|
||||
/// </summary>
|
||||
private byte[] buf = new byte[BUF_SIZE];
|
||||
|
||||
|
||||
/*Create a character buffer */
|
||||
public ByteBuffer(Stream input_) : base()
|
||||
{
|
||||
input = input_;
|
||||
}
|
||||
|
||||
/*Ensure that the character buffer is sufficiently full */
|
||||
override public void fill(int amount)
|
||||
{
|
||||
// try
|
||||
// {
|
||||
syncConsume();
|
||||
// Fill the buffer sufficiently to hold needed characters
|
||||
int bytesToRead = (amount + markerOffset) - queue.Count;
|
||||
int c;
|
||||
|
||||
while (bytesToRead > 0)
|
||||
{
|
||||
// Read a few characters
|
||||
c = input.Read(buf, 0, BUF_SIZE);
|
||||
for (int i = 0; i < c; i++)
|
||||
{
|
||||
// Append the next character
|
||||
queue.Add(unchecked((char) buf[i]));
|
||||
}
|
||||
if (c < BUF_SIZE)
|
||||
{
|
||||
while ((bytesToRead-- > 0) && (queue.Count < BUF_SIZE))
|
||||
{
|
||||
queue.Add(CharScanner.EOF_CHAR);
|
||||
}
|
||||
break;
|
||||
}
|
||||
bytesToRead -= c;
|
||||
}
|
||||
// }
|
||||
// catch (IOException io)
|
||||
// {
|
||||
// throw new CharStreamIOException(io);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
92
src/Spring/Spring.Core/antlr/CharBuffer.cs
Normal file
92
src/Spring/Spring.Core/antlr/CharBuffer.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using TextReader = System.IO.TextReader;
|
||||
using IOException = System.IO.IOException;
|
||||
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*A Stream of characters fed to the lexer from a InputStream that can
|
||||
* be rewound via mark()/rewind() methods.
|
||||
* <p>
|
||||
* A dynamic array is used to buffer up all the input characters. Normally,
|
||||
* "k" characters are stored in the buffer. More characters may be stored during
|
||||
* guess mode (testing syntactic predicate), or when LT(i>k) is referenced.
|
||||
* Consumption of characters is deferred. In other words, reading the next
|
||||
* character is not done by conume(), but deferred until needed by LA or LT.
|
||||
* <p>
|
||||
*/
|
||||
|
||||
// SAS: Move most functionality into InputBuffer -- just the file-specific
|
||||
// stuff is in here
|
||||
public class CharBuffer : InputBuffer
|
||||
{
|
||||
// char source
|
||||
[NonSerialized()]
|
||||
internal TextReader input;
|
||||
|
||||
private const int BUF_SIZE = 16;
|
||||
/// <summary>
|
||||
/// Small buffer used to avoid reading individual chars
|
||||
/// </summary>
|
||||
private char[] buf = new char[BUF_SIZE];
|
||||
|
||||
|
||||
/*Create a character buffer */
|
||||
public CharBuffer(TextReader input_) : base()
|
||||
{
|
||||
input = input_;
|
||||
}
|
||||
|
||||
/*Ensure that the character buffer is sufficiently full */
|
||||
override public void fill(int amount)
|
||||
{
|
||||
try
|
||||
{
|
||||
syncConsume();
|
||||
// Fill the buffer sufficiently to hold needed characters
|
||||
int charsToRead = (amount + markerOffset) - queue.Count;
|
||||
int c;
|
||||
|
||||
while (charsToRead > 0)
|
||||
{
|
||||
// Read a few characters
|
||||
c = input.Read(buf, 0, BUF_SIZE);
|
||||
for (int i = 0; i < c; i++)
|
||||
{
|
||||
// Append the next character
|
||||
queue.Add(buf[i]);
|
||||
}
|
||||
if (c < BUF_SIZE)
|
||||
{
|
||||
while ((charsToRead-- > 0) && (queue.Count < BUF_SIZE))
|
||||
{
|
||||
queue.Add(CharScanner.EOF_CHAR);
|
||||
}
|
||||
break;
|
||||
}
|
||||
charsToRead -= c;
|
||||
}
|
||||
}
|
||||
catch (IOException io)
|
||||
{
|
||||
throw new CharStreamIOException(io);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
120
src/Spring/Spring.Core/antlr/CharQueue.cs
Normal file
120
src/Spring/Spring.Core/antlr/CharQueue.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*A circular buffer object used by CharBuffer */
|
||||
public class CharQueue
|
||||
{
|
||||
/*Physical circular buffer of tokens */
|
||||
protected internal char[] buffer;
|
||||
/*buffer.length-1 for quick modulos */
|
||||
private int sizeLessOne;
|
||||
/*physical index of front token */
|
||||
private int offset;
|
||||
/*number of tokens in the queue */
|
||||
protected internal int nbrEntries;
|
||||
|
||||
public CharQueue(int minSize)
|
||||
{
|
||||
// Find first power of 2 >= to requested size
|
||||
int size;
|
||||
if (minSize < 0)
|
||||
{
|
||||
init(16); // pick some value for them
|
||||
return ;
|
||||
}
|
||||
// check for overflow
|
||||
if (minSize >= (Int32.MaxValue / 2))
|
||||
{
|
||||
init(Int32.MaxValue); // wow that's big.
|
||||
return ;
|
||||
}
|
||||
for (size = 2; size < minSize; size *= 2)
|
||||
{
|
||||
;
|
||||
}
|
||||
init(size);
|
||||
}
|
||||
|
||||
/*Add token to end of the queue
|
||||
* @param tok The token to add
|
||||
*/
|
||||
public void append(char tok)
|
||||
{
|
||||
if (nbrEntries == buffer.Length)
|
||||
{
|
||||
expand();
|
||||
}
|
||||
buffer[(offset + nbrEntries) & sizeLessOne] = tok;
|
||||
nbrEntries++;
|
||||
}
|
||||
|
||||
/*Fetch a token from the queue by index
|
||||
* @param idx The index of the token to fetch, where zero is the token at the front of the queue
|
||||
*/
|
||||
public char elementAt(int idx)
|
||||
{
|
||||
return buffer[(offset + idx) & sizeLessOne];
|
||||
}
|
||||
|
||||
/*Expand the token buffer by doubling its capacity */
|
||||
private void expand()
|
||||
{
|
||||
char[] newBuffer = new char[buffer.Length * 2];
|
||||
// Copy the contents to the new buffer
|
||||
// Note that this will store the first logical item in the
|
||||
// first physical array element.
|
||||
for (int i = 0; i < buffer.Length; i++)
|
||||
{
|
||||
newBuffer[i] = elementAt(i);
|
||||
}
|
||||
// Re-initialize with new contents, keep old nbrEntries
|
||||
buffer = newBuffer;
|
||||
sizeLessOne = buffer.Length - 1;
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
/*Initialize the queue.
|
||||
* @param size The initial size of the queue
|
||||
*/
|
||||
public virtual void init(int size)
|
||||
{
|
||||
// Allocate buffer
|
||||
buffer = new char[size];
|
||||
// Other initialization
|
||||
sizeLessOne = size - 1;
|
||||
offset = 0;
|
||||
nbrEntries = 0;
|
||||
}
|
||||
|
||||
/*Clear the queue. Leaving the previous buffer alone.
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
offset = 0;
|
||||
nbrEntries = 0;
|
||||
}
|
||||
|
||||
/*Remove char from front of queue */
|
||||
public void removeFirst()
|
||||
{
|
||||
offset = (offset + 1) & sizeLessOne;
|
||||
nbrEntries--;
|
||||
}
|
||||
}
|
||||
}
|
||||
814
src/Spring/Spring.Core/antlr/CharScanner.cs
Normal file
814
src/Spring/Spring.Core/antlr/CharScanner.cs
Normal file
@@ -0,0 +1,814 @@
|
||||
using System;
|
||||
using Stream = System.IO.Stream;
|
||||
using TextReader = System.IO.TextReader;
|
||||
using StringBuilder = System.Text.StringBuilder;
|
||||
using Hashtable = System.Collections.Hashtable;
|
||||
using Assembly = System.Reflection.Assembly;
|
||||
using EventHandlerList = System.ComponentModel.EventHandlerList;
|
||||
|
||||
using BitSet = antlr.collections.impl.BitSet;
|
||||
using antlr.debug;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
public abstract class CharScanner : TokenStream, ICharScannerDebugSubject
|
||||
{
|
||||
internal const char NO_CHAR = (char) (0);
|
||||
public static readonly char EOF_CHAR = Char.MaxValue;
|
||||
|
||||
// Used to store event delegates
|
||||
private EventHandlerList events_ = new EventHandlerList();
|
||||
|
||||
protected internal EventHandlerList Events
|
||||
{
|
||||
get { return events_; }
|
||||
}
|
||||
|
||||
// The unique keys for each event that CharScanner [objects] can generate
|
||||
internal static readonly object EnterRuleEventKey = new object();
|
||||
internal static readonly object ExitRuleEventKey = new object();
|
||||
internal static readonly object DoneEventKey = new object();
|
||||
internal static readonly object ReportErrorEventKey = new object();
|
||||
internal static readonly object ReportWarningEventKey = new object();
|
||||
internal static readonly object NewLineEventKey = new object();
|
||||
internal static readonly object MatchEventKey = new object();
|
||||
internal static readonly object MatchNotEventKey = new object();
|
||||
internal static readonly object MisMatchEventKey = new object();
|
||||
internal static readonly object MisMatchNotEventKey = new object();
|
||||
internal static readonly object ConsumeEventKey = new object();
|
||||
internal static readonly object LAEventKey = new object();
|
||||
internal static readonly object SemPredEvaluatedEventKey = new object();
|
||||
internal static readonly object SynPredStartedEventKey = new object();
|
||||
internal static readonly object SynPredFailedEventKey = new object();
|
||||
internal static readonly object SynPredSucceededEventKey = new object();
|
||||
|
||||
protected internal StringBuilder text; // text of current token
|
||||
|
||||
protected bool saveConsumedInput = true; // does consume() save characters?
|
||||
|
||||
/// <summary>Used for creating Token instances.</summary>
|
||||
protected TokenCreator tokenCreator;
|
||||
|
||||
/// <summary>Used for caching lookahead characters.</summary>
|
||||
protected char cached_LA1;
|
||||
protected char cached_LA2;
|
||||
|
||||
protected bool caseSensitive = true;
|
||||
protected bool caseSensitiveLiterals = true;
|
||||
protected Hashtable literals; // set by subclass
|
||||
|
||||
/*Tab chars are handled by tab() according to this value; override
|
||||
* method to do anything weird with tabs.
|
||||
*/
|
||||
protected internal int tabsize = 8;
|
||||
|
||||
protected internal IToken returnToken_ = null; // used to return tokens w/o using return val.
|
||||
|
||||
protected internal LexerSharedInputState inputState;
|
||||
|
||||
/*Used during filter mode to indicate that path is desired.
|
||||
* A subsequent scan error will report an error as usual if
|
||||
* acceptPath=true;
|
||||
*/
|
||||
protected internal bool commitToPath = false;
|
||||
|
||||
/*Used to keep track of indentdepth for traceIn/Out */
|
||||
protected internal int traceDepth = 0;
|
||||
|
||||
public CharScanner()
|
||||
{
|
||||
text = new StringBuilder();
|
||||
setTokenCreator(new CommonToken.CommonTokenCreator());
|
||||
}
|
||||
|
||||
public CharScanner(InputBuffer cb) : this()
|
||||
{
|
||||
inputState = new LexerSharedInputState(cb);
|
||||
cached_LA2 = inputState.input.LA(2);
|
||||
cached_LA1 = inputState.input.LA(1);
|
||||
}
|
||||
|
||||
public CharScanner(LexerSharedInputState sharedState) : this()
|
||||
{
|
||||
inputState = sharedState;
|
||||
if (inputState != null)
|
||||
{
|
||||
cached_LA2 = inputState.input.LA(2);
|
||||
cached_LA1 = inputState.input.LA(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public event TraceEventHandler EnterRule
|
||||
{
|
||||
add { Events.AddHandler(EnterRuleEventKey, value); }
|
||||
remove { Events.RemoveHandler(EnterRuleEventKey, value); }
|
||||
}
|
||||
|
||||
public event TraceEventHandler ExitRule
|
||||
{
|
||||
add { Events.AddHandler(ExitRuleEventKey, value); }
|
||||
remove { Events.RemoveHandler(ExitRuleEventKey, value); }
|
||||
}
|
||||
|
||||
public event TraceEventHandler Done
|
||||
{
|
||||
add { Events.AddHandler(DoneEventKey, value); }
|
||||
remove { Events.RemoveHandler(DoneEventKey, value); }
|
||||
}
|
||||
|
||||
public event MessageEventHandler ErrorReported
|
||||
{
|
||||
add { Events.AddHandler(ReportErrorEventKey, value); }
|
||||
remove { Events.RemoveHandler(ReportErrorEventKey, value); }
|
||||
}
|
||||
|
||||
public event MessageEventHandler WarningReported
|
||||
{
|
||||
add { Events.AddHandler(ReportWarningEventKey, value); }
|
||||
remove { Events.RemoveHandler(ReportWarningEventKey, value); }
|
||||
}
|
||||
|
||||
public event NewLineEventHandler HitNewLine
|
||||
{
|
||||
add { Events.AddHandler(NewLineEventKey, value); }
|
||||
remove { Events.RemoveHandler(NewLineEventKey, value); }
|
||||
}
|
||||
|
||||
public event MatchEventHandler MatchedChar
|
||||
{
|
||||
add { Events.AddHandler(MatchEventKey, value); }
|
||||
remove { Events.RemoveHandler(MatchEventKey, value); }
|
||||
}
|
||||
|
||||
public event MatchEventHandler MatchedNotChar
|
||||
{
|
||||
add { Events.AddHandler(MatchNotEventKey, value); }
|
||||
remove { Events.RemoveHandler(MatchNotEventKey, value); }
|
||||
}
|
||||
|
||||
public event MatchEventHandler MisMatchedChar
|
||||
{
|
||||
add { Events.AddHandler(MisMatchEventKey, value); }
|
||||
remove { Events.RemoveHandler(MisMatchEventKey, value); }
|
||||
}
|
||||
|
||||
public event MatchEventHandler MisMatchedNotChar
|
||||
{
|
||||
add { Events.AddHandler(MisMatchNotEventKey, value); }
|
||||
remove { Events.RemoveHandler(MisMatchNotEventKey, value); }
|
||||
}
|
||||
|
||||
public event TokenEventHandler ConsumedChar
|
||||
{
|
||||
add { Events.AddHandler(ConsumeEventKey, value); }
|
||||
remove { Events.RemoveHandler(ConsumeEventKey, value); }
|
||||
}
|
||||
|
||||
public event TokenEventHandler CharLA
|
||||
{
|
||||
add { Events.AddHandler(LAEventKey, value); }
|
||||
remove { Events.RemoveHandler(LAEventKey, value); }
|
||||
}
|
||||
|
||||
public event SemanticPredicateEventHandler SemPredEvaluated
|
||||
{
|
||||
add { Events.AddHandler(SemPredEvaluatedEventKey, value); }
|
||||
remove { Events.RemoveHandler(SemPredEvaluatedEventKey, value); }
|
||||
}
|
||||
|
||||
public event SyntacticPredicateEventHandler SynPredStarted
|
||||
{
|
||||
add { Events.AddHandler(SynPredStartedEventKey, value); }
|
||||
remove { Events.RemoveHandler(SynPredStartedEventKey, value); }
|
||||
}
|
||||
|
||||
public event SyntacticPredicateEventHandler SynPredFailed
|
||||
{
|
||||
add { Events.AddHandler(SynPredFailedEventKey, value); }
|
||||
remove { Events.RemoveHandler(SynPredFailedEventKey, value); }
|
||||
}
|
||||
|
||||
public event SyntacticPredicateEventHandler SynPredSucceeded
|
||||
{
|
||||
add { Events.AddHandler(SynPredSucceededEventKey, value); }
|
||||
remove { Events.RemoveHandler(SynPredSucceededEventKey, value); }
|
||||
}
|
||||
|
||||
// From interface TokenStream
|
||||
public virtual IToken nextToken() { return null; }
|
||||
|
||||
public virtual void append(char c)
|
||||
{
|
||||
if (saveConsumedInput)
|
||||
{
|
||||
text.Append(c);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void append(string s)
|
||||
{
|
||||
if (saveConsumedInput)
|
||||
{
|
||||
text.Append(s);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void commit()
|
||||
{
|
||||
inputState.input.commit();
|
||||
}
|
||||
|
||||
public virtual void recover(RecognitionException ex, BitSet tokenSet)
|
||||
{
|
||||
consume();
|
||||
consumeUntil(tokenSet);
|
||||
}
|
||||
|
||||
public virtual void consume()
|
||||
{
|
||||
if (inputState.guessing == 0)
|
||||
{
|
||||
if (caseSensitive)
|
||||
{
|
||||
append(cached_LA1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// use input.LA(), not LA(), to get original case
|
||||
// CharScanner.LA() would toLower it.
|
||||
append(inputState.input.LA(1));
|
||||
}
|
||||
if (cached_LA1 == '\t')
|
||||
{
|
||||
tab();
|
||||
}
|
||||
else
|
||||
{
|
||||
inputState.column++;
|
||||
}
|
||||
}
|
||||
if (caseSensitive)
|
||||
{
|
||||
cached_LA1 = inputState.input.consume();
|
||||
cached_LA2 = inputState.input.LA(2);
|
||||
}
|
||||
else
|
||||
{
|
||||
cached_LA1 = toLower(inputState.input.consume());
|
||||
cached_LA2 = toLower(inputState.input.LA(2));
|
||||
}
|
||||
}
|
||||
|
||||
/*Consume chars until one matches the given char */
|
||||
public virtual void consumeUntil(int c)
|
||||
{
|
||||
while ((EOF_CHAR != cached_LA1) && (c != cached_LA1))
|
||||
{
|
||||
consume();
|
||||
}
|
||||
}
|
||||
|
||||
/*Consume chars until one matches the given set */
|
||||
public virtual void consumeUntil(BitSet bset)
|
||||
{
|
||||
while (cached_LA1 != EOF_CHAR && !bset.member(cached_LA1))
|
||||
{
|
||||
consume();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool getCaseSensitive()
|
||||
{
|
||||
return caseSensitive;
|
||||
}
|
||||
|
||||
public bool getCaseSensitiveLiterals()
|
||||
{
|
||||
return caseSensitiveLiterals;
|
||||
}
|
||||
|
||||
public virtual int getColumn()
|
||||
{
|
||||
return inputState.column;
|
||||
}
|
||||
|
||||
public virtual void setColumn(int c)
|
||||
{
|
||||
inputState.column = c;
|
||||
}
|
||||
|
||||
public virtual bool getCommitToPath()
|
||||
{
|
||||
return commitToPath;
|
||||
}
|
||||
|
||||
public virtual string getFilename()
|
||||
{
|
||||
return inputState.filename;
|
||||
}
|
||||
|
||||
public virtual InputBuffer getInputBuffer()
|
||||
{
|
||||
return inputState.input;
|
||||
}
|
||||
|
||||
public virtual LexerSharedInputState getInputState()
|
||||
{
|
||||
return inputState;
|
||||
}
|
||||
|
||||
public virtual void setInputState(LexerSharedInputState state)
|
||||
{
|
||||
inputState = state;
|
||||
}
|
||||
|
||||
public virtual int getLine()
|
||||
{
|
||||
return inputState.line;
|
||||
}
|
||||
|
||||
/*return a copy of the current text buffer */
|
||||
public virtual string getText()
|
||||
{
|
||||
return text.ToString();
|
||||
}
|
||||
|
||||
public virtual IToken getTokenObject()
|
||||
{
|
||||
return returnToken_;
|
||||
}
|
||||
|
||||
public virtual char LA(int i)
|
||||
{
|
||||
if (i == 1)
|
||||
{
|
||||
return cached_LA1;
|
||||
}
|
||||
if (i == 2)
|
||||
{
|
||||
return cached_LA2;
|
||||
}
|
||||
if (caseSensitive)
|
||||
{
|
||||
return inputState.input.LA(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
return toLower(inputState.input.LA(i));
|
||||
}
|
||||
}
|
||||
|
||||
protected internal virtual IToken makeToken(int t)
|
||||
{
|
||||
IToken newToken = null;
|
||||
bool typeCreated;
|
||||
|
||||
try
|
||||
{
|
||||
newToken = tokenCreator.Create();
|
||||
if (newToken != null)
|
||||
{
|
||||
newToken.Type = t;
|
||||
newToken.setColumn(inputState.tokenStartColumn);
|
||||
newToken.setLine(inputState.tokenStartLine);
|
||||
// tracking real start line now: newToken.setLine(inputState.line);
|
||||
newToken.setFilename(inputState.filename);
|
||||
}
|
||||
typeCreated = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
typeCreated = false;
|
||||
}
|
||||
|
||||
if (!typeCreated)
|
||||
{
|
||||
panic("Can't create Token object '" + tokenCreator.TokenTypeName + "'");
|
||||
newToken = Token.badToken;
|
||||
}
|
||||
return newToken;
|
||||
}
|
||||
|
||||
public virtual int mark()
|
||||
{
|
||||
return inputState.input.mark();
|
||||
}
|
||||
|
||||
public virtual void match(char c)
|
||||
{
|
||||
match((int) c);
|
||||
}
|
||||
|
||||
public virtual void match(int c)
|
||||
{
|
||||
if (cached_LA1 != c)
|
||||
{
|
||||
throw new MismatchedCharException(cached_LA1, Convert.ToChar(c), false, this);
|
||||
}
|
||||
consume();
|
||||
}
|
||||
|
||||
public virtual void match(BitSet b)
|
||||
{
|
||||
if (!b.member(cached_LA1))
|
||||
{
|
||||
throw new MismatchedCharException(cached_LA1, b, false, this);
|
||||
}
|
||||
consume();
|
||||
}
|
||||
|
||||
public virtual void match(string s)
|
||||
{
|
||||
int len = s.Length;
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (cached_LA1 != s[i])
|
||||
{
|
||||
throw new MismatchedCharException(cached_LA1, s[i], false, this);
|
||||
}
|
||||
consume();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void matchNot(char c)
|
||||
{
|
||||
matchNot((int) c);
|
||||
}
|
||||
|
||||
public virtual void matchNot(int c)
|
||||
{
|
||||
if (cached_LA1 == c)
|
||||
{
|
||||
throw new MismatchedCharException(cached_LA1, Convert.ToChar(c), true, this);
|
||||
}
|
||||
consume();
|
||||
}
|
||||
|
||||
public virtual void matchRange(int c1, int c2)
|
||||
{
|
||||
if (cached_LA1 < c1 || cached_LA1 > c2)
|
||||
{
|
||||
throw new MismatchedCharException(cached_LA1, Convert.ToChar(c1), Convert.ToChar(c2), false, this);
|
||||
}
|
||||
consume();
|
||||
}
|
||||
|
||||
public virtual void matchRange(char c1, char c2)
|
||||
{
|
||||
matchRange((int) c1, (int) c2);
|
||||
}
|
||||
|
||||
public virtual void newline()
|
||||
{
|
||||
inputState.line++;
|
||||
inputState.column = 1;
|
||||
}
|
||||
|
||||
/*advance the current column number by an appropriate amount
|
||||
* according to tab size. This method is called from consume().
|
||||
*/
|
||||
public virtual void tab()
|
||||
{
|
||||
int c = getColumn();
|
||||
int nc = (((c - 1) / tabsize) + 1) * tabsize + 1; // calculate tab stop
|
||||
setColumn(nc);
|
||||
}
|
||||
|
||||
public virtual void setTabSize(int size)
|
||||
{
|
||||
tabsize = size;
|
||||
}
|
||||
|
||||
public virtual int getTabSize()
|
||||
{
|
||||
return tabsize;
|
||||
}
|
||||
|
||||
public virtual void panic()
|
||||
{
|
||||
//Console.Error.WriteLine("CharScanner: panic");
|
||||
//Environment.Exit(1);
|
||||
panic("");
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is executed by ANTLR internally when it detected an illegal
|
||||
/// state that cannot be recovered from.
|
||||
/// The previous implementation of this method called <see cref="Environment.Exit"/>
|
||||
/// and writes directly to <see cref="Console.Error"/>, which is usually not
|
||||
/// appropriate when a translator is embedded into a larger application.
|
||||
/// </summary>
|
||||
/// <param name="s">Error message.</param>
|
||||
public virtual void panic(string s)
|
||||
{
|
||||
//Console.Error.WriteLine("CharScanner; panic: " + s);
|
||||
//Environment.Exit(1);
|
||||
throw new ANTLRPanicException("CharScanner::panic: " + s);
|
||||
}
|
||||
|
||||
/*Parser error-reporting function can be overridden in subclass */
|
||||
public virtual void reportError(RecognitionException ex)
|
||||
{
|
||||
Console.Error.WriteLine(ex);
|
||||
}
|
||||
|
||||
/*Parser error-reporting function can be overridden in subclass */
|
||||
public virtual void reportError(string s)
|
||||
{
|
||||
if (getFilename() == null)
|
||||
{
|
||||
Console.Error.WriteLine("error: " + s);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine(getFilename() + ": error: " + s);
|
||||
}
|
||||
}
|
||||
|
||||
/*Parser warning-reporting function can be overridden in subclass */
|
||||
public virtual void reportWarning(string s)
|
||||
{
|
||||
if (getFilename() == null)
|
||||
{
|
||||
Console.Error.WriteLine("warning: " + s);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine(getFilename() + ": warning: " + s);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void refresh()
|
||||
{
|
||||
if (caseSensitive)
|
||||
{
|
||||
cached_LA2 = inputState.input.LA(2);
|
||||
cached_LA1 = inputState.input.LA(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
cached_LA2 = toLower(inputState.input.LA(2));
|
||||
cached_LA1 = toLower(inputState.input.LA(1));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void resetState(InputBuffer ib)
|
||||
{
|
||||
text.Length = 0;
|
||||
traceDepth = 0;
|
||||
inputState.resetInput(ib);
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void resetState(Stream s)
|
||||
{
|
||||
resetState(new ByteBuffer(s));
|
||||
}
|
||||
|
||||
public void resetState(TextReader tr)
|
||||
{
|
||||
resetState(new CharBuffer(tr));
|
||||
}
|
||||
|
||||
public virtual void resetText()
|
||||
{
|
||||
text.Length = 0;
|
||||
inputState.tokenStartColumn = inputState.column;
|
||||
inputState.tokenStartLine = inputState.line;
|
||||
}
|
||||
|
||||
public virtual void rewind(int pos)
|
||||
{
|
||||
inputState.input.rewind(pos);
|
||||
//setColumn(inputState.tokenStartColumn);
|
||||
if (caseSensitive)
|
||||
{
|
||||
cached_LA2 = inputState.input.LA(2);
|
||||
cached_LA1 = inputState.input.LA(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
cached_LA2 = toLower(inputState.input.LA(2));
|
||||
cached_LA1 = toLower(inputState.input.LA(1));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void setCaseSensitive(bool t)
|
||||
{
|
||||
caseSensitive = t;
|
||||
if (caseSensitive)
|
||||
{
|
||||
cached_LA2 = inputState.input.LA(2);
|
||||
cached_LA1 = inputState.input.LA(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
cached_LA2 = toLower(inputState.input.LA(2));
|
||||
cached_LA1 = toLower(inputState.input.LA(1));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void setCommitToPath(bool commit)
|
||||
{
|
||||
commitToPath = commit;
|
||||
}
|
||||
|
||||
public virtual void setFilename(string f)
|
||||
{
|
||||
inputState.filename = f;
|
||||
}
|
||||
|
||||
public virtual void setLine(int line)
|
||||
{
|
||||
inputState.line = line;
|
||||
}
|
||||
|
||||
public virtual void setText(string s)
|
||||
{
|
||||
resetText();
|
||||
text.Append(s);
|
||||
}
|
||||
|
||||
public virtual void setTokenObjectClass(string cl)
|
||||
{
|
||||
this.tokenCreator = new ReflectionBasedTokenCreator(this, cl);
|
||||
}
|
||||
|
||||
public virtual void setTokenCreator(TokenCreator tokenCreator)
|
||||
{
|
||||
this.tokenCreator = tokenCreator;
|
||||
}
|
||||
|
||||
// Test the token text against the literals table
|
||||
// Override this method to perform a different literals test
|
||||
public virtual int testLiteralsTable(int ttype)
|
||||
{
|
||||
string tokenText = text.ToString();
|
||||
|
||||
if ( (tokenText == null) || (tokenText == string.Empty) )
|
||||
return ttype;
|
||||
else
|
||||
{
|
||||
object typeAsObject = literals[tokenText];
|
||||
return (typeAsObject == null) ? ttype : ((int) typeAsObject);
|
||||
}
|
||||
}
|
||||
|
||||
/*Test the text passed in against the literals table
|
||||
* Override this method to perform a different literals test
|
||||
* This is used primarily when you want to test a portion of
|
||||
* a token.
|
||||
*/
|
||||
public virtual int testLiteralsTable(string someText, int ttype)
|
||||
{
|
||||
if ( (someText == null) || (someText == string.Empty) )
|
||||
return ttype;
|
||||
else
|
||||
{
|
||||
object typeAsObject = literals[someText];
|
||||
return (typeAsObject == null) ? ttype : ((int) typeAsObject);
|
||||
}
|
||||
}
|
||||
|
||||
// Override this method to get more specific case handling
|
||||
public virtual char toLower(int c)
|
||||
{
|
||||
return Char.ToLower(Convert.ToChar(c), System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public virtual void traceIndent()
|
||||
{
|
||||
for (int i = 0; i < traceDepth; i++)
|
||||
Console.Out.Write(" ");
|
||||
}
|
||||
|
||||
public virtual void traceIn(string rname)
|
||||
{
|
||||
traceDepth += 1;
|
||||
traceIndent();
|
||||
Console.Out.WriteLine("> lexer " + rname + "; c==" + LA(1));
|
||||
}
|
||||
|
||||
public virtual void traceOut(string rname)
|
||||
{
|
||||
traceIndent();
|
||||
Console.Out.WriteLine("< lexer " + rname + "; c==" + LA(1));
|
||||
traceDepth -= 1;
|
||||
}
|
||||
|
||||
/*This method is called by YourLexer.nextToken() when the lexer has
|
||||
* hit EOF condition. EOF is NOT a character.
|
||||
* This method is not called if EOF is reached during
|
||||
* syntactic predicate evaluation or during evaluation
|
||||
* of normal lexical rules, which presumably would be
|
||||
* an IOException. This traps the "normal" EOF condition.
|
||||
*
|
||||
* uponEOF() is called after the complete evaluation of
|
||||
* the previous token and only if your parser asks
|
||||
* for another token beyond that last non-EOF token.
|
||||
*
|
||||
* You might want to throw token or char stream exceptions
|
||||
* like: "Heh, premature eof" or a retry stream exception
|
||||
* ("I found the end of this file, go back to referencing file").
|
||||
*/
|
||||
public virtual void uponEOF()
|
||||
{
|
||||
}
|
||||
|
||||
private class ReflectionBasedTokenCreator : TokenCreator
|
||||
{
|
||||
protected ReflectionBasedTokenCreator() {}
|
||||
|
||||
public ReflectionBasedTokenCreator(CharScanner owner, string tokenTypeName)
|
||||
{
|
||||
this.owner = owner;
|
||||
SetTokenType(tokenTypeName);
|
||||
}
|
||||
|
||||
private CharScanner owner;
|
||||
|
||||
/// <summary>
|
||||
/// The fully qualified name of the Token type to create.
|
||||
/// </summary>
|
||||
private string tokenTypeName;
|
||||
|
||||
/// <summary>
|
||||
/// Type object used as a template for creating tokens by reflection.
|
||||
/// </summary>
|
||||
private Type tokenTypeObject;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the fully qualified name of the Token type that this
|
||||
/// class creates.
|
||||
/// </summary>
|
||||
private void SetTokenType(string tokenTypeName)
|
||||
{
|
||||
this.tokenTypeName = tokenTypeName;
|
||||
foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
try
|
||||
{
|
||||
tokenTypeObject = assem.GetType(tokenTypeName);
|
||||
if (tokenTypeObject != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new TypeLoadException("Unable to load Type for Token class '" + tokenTypeName + "'");
|
||||
}
|
||||
}
|
||||
if (tokenTypeObject==null)
|
||||
throw new TypeLoadException("Unable to load Type for Token class '" + tokenTypeName + "'");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the fully qualified name of the Token type that this
|
||||
/// class creates.
|
||||
/// </summary>
|
||||
public override string TokenTypeName
|
||||
{
|
||||
get
|
||||
{
|
||||
return tokenTypeName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a <see cref="Token"/> instance.
|
||||
/// </summary>
|
||||
public override IToken Create()
|
||||
{
|
||||
IToken newToken = null;
|
||||
|
||||
try
|
||||
{
|
||||
newToken = (Token) Activator.CreateInstance(tokenTypeObject);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// supress exception
|
||||
}
|
||||
return newToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/Spring/Spring.Core/antlr/CharStreamException.cs
Normal file
34
src/Spring/Spring.Core/antlr/CharStreamException.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*
|
||||
* Anything that goes wrong while generating a stream of characters
|
||||
*/
|
||||
|
||||
[Serializable]
|
||||
public class CharStreamException : ANTLRException
|
||||
{
|
||||
/*
|
||||
* CharStreamException constructor comment.
|
||||
*/
|
||||
public CharStreamException(string s) : base(s)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/Spring/Spring.Core/antlr/CharStreamIOException.cs
Normal file
34
src/Spring/Spring.Core/antlr/CharStreamIOException.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using IOException = System.IO.IOException;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*
|
||||
* Wrap an IOException in a CharStreamException
|
||||
*/
|
||||
[Serializable]
|
||||
public class CharStreamIOException : CharStreamException
|
||||
{
|
||||
public IOException io;
|
||||
|
||||
public CharStreamIOException(IOException io) : base(io.Message)
|
||||
{
|
||||
this.io = io;
|
||||
}
|
||||
}
|
||||
}
|
||||
123
src/Spring/Spring.Core/antlr/CommonAST.cs
Normal file
123
src/Spring/Spring.Core/antlr/CommonAST.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using AST = antlr.collections.AST;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*Common AST node implementation */
|
||||
public class CommonAST : BaseAST
|
||||
{
|
||||
public static readonly CommonAST.CommonASTCreator Creator = new CommonASTCreator();
|
||||
|
||||
internal int ttype = Token.INVALID_TYPE;
|
||||
internal string text;
|
||||
|
||||
|
||||
[Obsolete("Deprecated since version 2.7.2. Use ASTFactory.dup() instead.", false)]
|
||||
protected CommonAST(CommonAST another)
|
||||
{
|
||||
// don't include child/sibling pointers in Clone()/dup()
|
||||
//down = another.down;
|
||||
//right = another.right;
|
||||
ttype = another.ttype;
|
||||
text = (another.text==null) ? null : String.Copy(another.text);
|
||||
}
|
||||
|
||||
/*Get the token text for this node */
|
||||
override public string getText()
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
/*Get the token type for this node */
|
||||
override public int Type
|
||||
{
|
||||
get { return ttype; }
|
||||
set { ttype = value; }
|
||||
}
|
||||
|
||||
override public void initialize(int t, string txt)
|
||||
{
|
||||
Type = t;
|
||||
setText(txt);
|
||||
}
|
||||
|
||||
override public void initialize(AST t)
|
||||
{
|
||||
setText(t.getText());
|
||||
Type = t.Type;
|
||||
}
|
||||
|
||||
public CommonAST()
|
||||
{
|
||||
}
|
||||
|
||||
public CommonAST(IToken tok)
|
||||
{
|
||||
initialize(tok);
|
||||
}
|
||||
|
||||
override public void initialize(IToken tok)
|
||||
{
|
||||
setText(tok.getText());
|
||||
Type = tok.Type;
|
||||
}
|
||||
/*Set the token text for this node */
|
||||
override public void setText(string text_)
|
||||
{
|
||||
text = text_;
|
||||
}
|
||||
/*Set the token type for this node */
|
||||
override public void setType(int ttype_)
|
||||
{
|
||||
this.Type = ttype_;
|
||||
}
|
||||
|
||||
#region Implementation of ICloneable
|
||||
[Obsolete("Deprecated since version 2.7.2. Use ASTFactory.dup() instead.", false)]
|
||||
override public object Clone()
|
||||
{
|
||||
return new CommonAST(this);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public class CommonASTCreator : ASTNodeCreator
|
||||
{
|
||||
public CommonASTCreator() {}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the fully qualified name of the AST type that this
|
||||
/// class creates.
|
||||
/// </summary>
|
||||
public override string ASTNodeTypeName
|
||||
{
|
||||
get
|
||||
{
|
||||
return typeof(antlr.CommonAST).FullName;;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a <see cref="AST"/> instance.
|
||||
/// </summary>
|
||||
public override AST Create()
|
||||
{
|
||||
return new CommonAST();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
104
src/Spring/Spring.Core/antlr/CommonASTWithHiddenTokens.cs
Normal file
104
src/Spring/Spring.Core/antlr/CommonASTWithHiddenTokens.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using AST = antlr.collections.AST;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*A CommonAST whose initialization copies hidden token
|
||||
* information from the Token used to create a node.
|
||||
*/
|
||||
|
||||
public class CommonASTWithHiddenTokens : CommonAST
|
||||
{
|
||||
new public static readonly CommonASTWithHiddenTokens.CommonASTWithHiddenTokensCreator Creator = new CommonASTWithHiddenTokensCreator();
|
||||
|
||||
protected internal IHiddenStreamToken hiddenBefore, hiddenAfter; // references to hidden tokens
|
||||
|
||||
public CommonASTWithHiddenTokens() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public CommonASTWithHiddenTokens(IToken tok) : base(tok)
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("Deprecated since version 2.7.2. Use ASTFactory.dup() instead.", false)]
|
||||
protected CommonASTWithHiddenTokens(CommonASTWithHiddenTokens another) : base(another)
|
||||
{
|
||||
hiddenBefore = another.hiddenBefore;
|
||||
hiddenAfter = another.hiddenAfter;
|
||||
}
|
||||
|
||||
public virtual IHiddenStreamToken getHiddenAfter()
|
||||
{
|
||||
return hiddenAfter;
|
||||
}
|
||||
|
||||
public virtual IHiddenStreamToken getHiddenBefore()
|
||||
{
|
||||
return hiddenBefore;
|
||||
}
|
||||
|
||||
override public void initialize(AST t)
|
||||
{
|
||||
hiddenBefore = ((CommonASTWithHiddenTokens) t).getHiddenBefore();
|
||||
hiddenAfter = ((CommonASTWithHiddenTokens) t).getHiddenAfter();
|
||||
base.initialize(t);
|
||||
}
|
||||
|
||||
override public void initialize(IToken tok)
|
||||
{
|
||||
IHiddenStreamToken t = (IHiddenStreamToken) tok;
|
||||
base.initialize(t);
|
||||
hiddenBefore = t.getHiddenBefore();
|
||||
hiddenAfter = t.getHiddenAfter();
|
||||
}
|
||||
|
||||
#region Implementation of ICloneable
|
||||
[Obsolete("Deprecated since version 2.7.2. Use ASTFactory.dup() instead.", false)]
|
||||
override public object Clone()
|
||||
{
|
||||
return new CommonASTWithHiddenTokens(this);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public class CommonASTWithHiddenTokensCreator : ASTNodeCreator
|
||||
{
|
||||
public CommonASTWithHiddenTokensCreator() {}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the fully qualified name of the AST type that this
|
||||
/// class creates.
|
||||
/// </summary>
|
||||
public override string ASTNodeTypeName
|
||||
{
|
||||
get
|
||||
{
|
||||
return typeof(antlr.CommonASTWithHiddenTokens).FullName;;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a <see cref="AST"/> instance.
|
||||
/// </summary>
|
||||
public override AST Create()
|
||||
{
|
||||
return new CommonASTWithHiddenTokens();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
84
src/Spring/Spring.Core/antlr/CommonHiddenStreamToken.cs
Normal file
84
src/Spring/Spring.Core/antlr/CommonHiddenStreamToken.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
public class CommonHiddenStreamToken : CommonToken, IHiddenStreamToken
|
||||
{
|
||||
new public static readonly CommonHiddenStreamToken.CommonHiddenStreamTokenCreator Creator = new CommonHiddenStreamTokenCreator();
|
||||
|
||||
protected internal IHiddenStreamToken hiddenBefore;
|
||||
protected internal IHiddenStreamToken hiddenAfter;
|
||||
|
||||
public CommonHiddenStreamToken() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public CommonHiddenStreamToken(int t, string txt) : base(t, txt)
|
||||
{
|
||||
}
|
||||
|
||||
public CommonHiddenStreamToken(string s) : base(s)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual IHiddenStreamToken getHiddenAfter()
|
||||
{
|
||||
return hiddenAfter;
|
||||
}
|
||||
|
||||
public virtual IHiddenStreamToken getHiddenBefore()
|
||||
{
|
||||
return hiddenBefore;
|
||||
}
|
||||
|
||||
public virtual void setHiddenAfter(IHiddenStreamToken t)
|
||||
{
|
||||
hiddenAfter = t;
|
||||
}
|
||||
|
||||
public virtual void setHiddenBefore(IHiddenStreamToken t)
|
||||
{
|
||||
hiddenBefore = t;
|
||||
}
|
||||
|
||||
public class CommonHiddenStreamTokenCreator : TokenCreator
|
||||
{
|
||||
public CommonHiddenStreamTokenCreator() {}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the fully qualified name of the Token type that this
|
||||
/// class creates.
|
||||
/// </summary>
|
||||
public override string TokenTypeName
|
||||
{
|
||||
get
|
||||
{
|
||||
return typeof(antlr.CommonHiddenStreamToken).FullName;;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a <see cref="Token"/> instance.
|
||||
/// </summary>
|
||||
public override IToken Create()
|
||||
{
|
||||
return new CommonHiddenStreamToken();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
105
src/Spring/Spring.Core/antlr/CommonToken.cs
Normal file
105
src/Spring/Spring.Core/antlr/CommonToken.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
public class CommonToken : Token
|
||||
{
|
||||
public static readonly CommonToken.CommonTokenCreator Creator = new CommonTokenCreator();
|
||||
|
||||
// most tokens will want line and text information
|
||||
protected internal int line;
|
||||
protected internal string text = null;
|
||||
protected internal int col;
|
||||
|
||||
public CommonToken()
|
||||
{
|
||||
}
|
||||
|
||||
public CommonToken(int t, string txt)
|
||||
{
|
||||
type_ = t;
|
||||
setText(txt);
|
||||
}
|
||||
|
||||
public CommonToken(string s)
|
||||
{
|
||||
text = s;
|
||||
}
|
||||
|
||||
override public int getLine()
|
||||
{
|
||||
return line;
|
||||
}
|
||||
|
||||
override public string getText()
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
override public void setLine(int l)
|
||||
{
|
||||
line = l;
|
||||
}
|
||||
|
||||
override public void setText(string s)
|
||||
{
|
||||
text = s;
|
||||
}
|
||||
|
||||
override public string ToString()
|
||||
{
|
||||
return "[\"" + getText() + "\",<" + type_ + ">,line=" + line + ",col=" + col + "]";
|
||||
}
|
||||
|
||||
/*Return token's start column */
|
||||
override public int getColumn()
|
||||
{
|
||||
return col;
|
||||
}
|
||||
|
||||
override public void setColumn(int c)
|
||||
{
|
||||
col = c;
|
||||
}
|
||||
|
||||
public class CommonTokenCreator : TokenCreator
|
||||
{
|
||||
public CommonTokenCreator() {}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the fully qualified name of the Token type that this
|
||||
/// class creates.
|
||||
/// </summary>
|
||||
public override string TokenTypeName
|
||||
{
|
||||
get
|
||||
{
|
||||
return typeof(antlr.CommonToken).FullName;;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a <see cref="Token"/> instance.
|
||||
/// </summary>
|
||||
public override IToken Create()
|
||||
{
|
||||
return new CommonToken();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
48
src/Spring/Spring.Core/antlr/DefaultFileLineFormatter.cs
Normal file
48
src/Spring/Spring.Core/antlr/DefaultFileLineFormatter.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using StringBuilder = System.Text.StringBuilder;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
public class DefaultFileLineFormatter : FileLineFormatter
|
||||
{
|
||||
public override string getFormatString(string fileName, int line, int column)
|
||||
{
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
if (fileName != null)
|
||||
buf.Append(fileName + ":");
|
||||
|
||||
if (line != - 1)
|
||||
{
|
||||
if (fileName == null)
|
||||
buf.Append("line ");
|
||||
|
||||
buf.Append(line);
|
||||
|
||||
if (column != - 1)
|
||||
buf.Append(":" + column);
|
||||
|
||||
buf.Append(":");
|
||||
}
|
||||
|
||||
buf.Append(" ");
|
||||
|
||||
return buf.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
95
src/Spring/Spring.Core/antlr/DumpASTVisitor.cs
Normal file
95
src/Spring/Spring.Core/antlr/DumpASTVisitor.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
|
||||
using AST = antlr.collections.AST;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/* ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for DumpASTVisitor.
|
||||
/// </summary>
|
||||
/** Simple class to dump the contents of an AST to the output */
|
||||
public class DumpASTVisitor : ASTVisitor
|
||||
{
|
||||
protected int level = 0;
|
||||
|
||||
|
||||
private void tabs()
|
||||
{
|
||||
for (int i = 0; i < level; i++)
|
||||
{
|
||||
Console.Out.Write(" ");
|
||||
}
|
||||
}
|
||||
|
||||
public void visit(AST node)
|
||||
{
|
||||
// Flatten this level of the tree if it has no children
|
||||
bool flatten = /*true*/ false;
|
||||
AST node2;
|
||||
for (node2 = node; node2 != null; node2 = node2.getNextSibling())
|
||||
{
|
||||
if (node2.getFirstChild() != null)
|
||||
{
|
||||
flatten = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (node2 = node; node2 != null; node2 = node2.getNextSibling())
|
||||
{
|
||||
if (!flatten || node2 == node)
|
||||
{
|
||||
tabs();
|
||||
}
|
||||
if (node2.getText() == null)
|
||||
{
|
||||
Console.Out.Write("nil");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Out.Write(node2.getText());
|
||||
}
|
||||
|
||||
Console.Out.Write(" [" + node2.Type + "] ");
|
||||
|
||||
if (flatten)
|
||||
{
|
||||
Console.Out.Write(" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Out.WriteLine("");
|
||||
}
|
||||
|
||||
if (node2.getFirstChild() != null)
|
||||
{
|
||||
level++;
|
||||
visit(node2.getFirstChild());
|
||||
level--;
|
||||
}
|
||||
}
|
||||
|
||||
if (flatten)
|
||||
{
|
||||
Console.Out.WriteLine("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
41
src/Spring/Spring.Core/antlr/FileLineFormatter.cs
Normal file
41
src/Spring/Spring.Core/antlr/FileLineFormatter.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
public abstract class FileLineFormatter
|
||||
{
|
||||
|
||||
private static FileLineFormatter formatter = new DefaultFileLineFormatter();
|
||||
|
||||
public static FileLineFormatter getFormatter()
|
||||
{
|
||||
return formatter;
|
||||
}
|
||||
|
||||
public static void setFormatter(FileLineFormatter f)
|
||||
{
|
||||
formatter = f;
|
||||
}
|
||||
|
||||
/*@param fileName the file that should appear in the prefix. (or null)
|
||||
* @param line the line (or -1)
|
||||
* @param column the column (or -1)
|
||||
*/
|
||||
public abstract string getFormatString(string fileName, int line, int column);
|
||||
}
|
||||
}
|
||||
28
src/Spring/Spring.Core/antlr/IHiddenStreamToken.cs
Normal file
28
src/Spring/Spring.Core/antlr/IHiddenStreamToken.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
public interface IHiddenStreamToken : IToken
|
||||
{
|
||||
IHiddenStreamToken getHiddenAfter();
|
||||
void setHiddenAfter(IHiddenStreamToken t);
|
||||
|
||||
IHiddenStreamToken getHiddenBefore();
|
||||
void setHiddenBefore(IHiddenStreamToken t);
|
||||
}
|
||||
}
|
||||
40
src/Spring/Spring.Core/antlr/IToken.cs
Normal file
40
src/Spring/Spring.Core/antlr/IToken.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// A token is minimally a token type. Subclasses can add the text matched
|
||||
/// for the token and line info.
|
||||
/// </summary>
|
||||
public interface IToken
|
||||
{
|
||||
int getColumn();
|
||||
void setColumn(int c);
|
||||
|
||||
int getLine();
|
||||
void setLine(int l);
|
||||
|
||||
string getFilename();
|
||||
void setFilename(string name);
|
||||
|
||||
string getText();
|
||||
void setText(string t);
|
||||
|
||||
int Type { get; set; }
|
||||
}
|
||||
}
|
||||
165
src/Spring/Spring.Core/antlr/InputBuffer.cs
Normal file
165
src/Spring/Spring.Core/antlr/InputBuffer.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
namespace antlr
|
||||
{
|
||||
using System;
|
||||
using ArrayList = System.Collections.ArrayList;
|
||||
using StringBuilder = System.Text.StringBuilder;
|
||||
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
// SAS: Added this class to genericise the input buffers for scanners
|
||||
// This allows a scanner to use a binary (FileInputStream) or
|
||||
// text (FileReader) stream of data; the generated scanner
|
||||
// subclass will define the input stream
|
||||
// There are two subclasses to this: CharBuffer and ByteBuffer
|
||||
|
||||
/// <summary>
|
||||
/// Represents a stream of characters fed to the lexer from that can be rewound
|
||||
/// via mark()/rewind() methods.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// A dynamic array is used to buffer up all the input characters. Normally,
|
||||
/// "k" characters are stored in the buffer. More characters may be stored
|
||||
/// during guess mode (testing syntactic predicate), or when LT(i>k) is referenced.
|
||||
/// Consumption of characters is deferred. In other words, reading the next
|
||||
/// character is not done by conume(), but deferred until needed by LA or LT.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public abstract class InputBuffer
|
||||
{
|
||||
// Number of active markers
|
||||
protected internal int nMarkers = 0;
|
||||
|
||||
// Additional offset used when markers are active
|
||||
protected internal int markerOffset = 0;
|
||||
|
||||
// Number of calls to consume() since last LA() or LT() call
|
||||
protected internal int numToConsume = 0;
|
||||
|
||||
// Circular queue
|
||||
protected ArrayList queue;
|
||||
|
||||
/*Create an input buffer */
|
||||
public InputBuffer()
|
||||
{
|
||||
queue = new ArrayList();
|
||||
}
|
||||
|
||||
/*This method updates the state of the input buffer so that
|
||||
* the text matched since the most recent mark() is no longer
|
||||
* held by the buffer. So, you either do a mark/rewind for
|
||||
* failed predicate or mark/commit to keep on parsing without
|
||||
* rewinding the input.
|
||||
*/
|
||||
public virtual void commit()
|
||||
{
|
||||
nMarkers--;
|
||||
}
|
||||
|
||||
/*Mark another character for deferred consumption */
|
||||
public virtual char consume()
|
||||
{
|
||||
numToConsume++;
|
||||
return LA(1);
|
||||
}
|
||||
|
||||
/*Ensure that the input buffer is sufficiently full */
|
||||
public abstract void fill(int amount);
|
||||
|
||||
public virtual string getLAChars()
|
||||
{
|
||||
StringBuilder la = new StringBuilder();
|
||||
|
||||
// copy buffer contents to array before looping thru contents (it's usually faster)
|
||||
char[] fastBuf = new char[queue.Count-markerOffset];
|
||||
queue.CopyTo(fastBuf, markerOffset);
|
||||
|
||||
la.Append(fastBuf);
|
||||
return la.ToString();
|
||||
}
|
||||
|
||||
public virtual string getMarkedChars()
|
||||
{
|
||||
StringBuilder marked = new StringBuilder();
|
||||
|
||||
// copy buffer contents to array before looping thru contents (it's usually faster)
|
||||
char[] fastBuf = new char[queue.Count-markerOffset];
|
||||
queue.CopyTo(fastBuf, markerOffset);
|
||||
|
||||
marked.Append(fastBuf);
|
||||
return marked.ToString();
|
||||
}
|
||||
|
||||
public virtual bool isMarked()
|
||||
{
|
||||
return (nMarkers != 0);
|
||||
}
|
||||
|
||||
/*Get a lookahead character */
|
||||
public virtual char LA(int i)
|
||||
{
|
||||
fill(i);
|
||||
return (char) queue[markerOffset + i - 1];
|
||||
}
|
||||
|
||||
/*Return an integer marker that can be used to rewind the buffer to
|
||||
* its current state.
|
||||
*/
|
||||
public virtual int mark()
|
||||
{
|
||||
syncConsume();
|
||||
nMarkers++;
|
||||
return markerOffset;
|
||||
}
|
||||
|
||||
/*Rewind the character buffer to a marker.
|
||||
* @param mark Marker returned previously from mark()
|
||||
*/
|
||||
public virtual void rewind(int mark)
|
||||
{
|
||||
syncConsume();
|
||||
markerOffset = mark;
|
||||
nMarkers--;
|
||||
}
|
||||
|
||||
/*Reset the input buffer
|
||||
*/
|
||||
public virtual void reset()
|
||||
{
|
||||
nMarkers = 0;
|
||||
markerOffset = 0;
|
||||
numToConsume = 0;
|
||||
queue.Clear();
|
||||
}
|
||||
|
||||
/*Sync up deferred consumption */
|
||||
protected internal virtual void syncConsume()
|
||||
{
|
||||
if (numToConsume > 0)
|
||||
{
|
||||
if (nMarkers > 0)
|
||||
{
|
||||
// guess mode -- leave leading characters and bump offset.
|
||||
markerOffset += numToConsume;
|
||||
}
|
||||
else
|
||||
{
|
||||
// normal mode -- remove "consumed" characters from buffer
|
||||
queue.RemoveRange(0, numToConsume);
|
||||
}
|
||||
numToConsume = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
100
src/Spring/Spring.Core/antlr/LLkParser.cs
Normal file
100
src/Spring/Spring.Core/antlr/LLkParser.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*An LL(k) parser.
|
||||
*
|
||||
* @see antlr.Token
|
||||
* @see antlr.TokenBuffer
|
||||
* @see antlr.LL1Parser
|
||||
*/
|
||||
public class LLkParser : Parser
|
||||
{
|
||||
internal int k;
|
||||
|
||||
public LLkParser(int k_)
|
||||
{
|
||||
k = k_;
|
||||
}
|
||||
public LLkParser(ParserSharedInputState state, int k_)
|
||||
{
|
||||
k = k_;
|
||||
inputState = state;
|
||||
}
|
||||
public LLkParser(TokenBuffer tokenBuf, int k_)
|
||||
{
|
||||
k = k_;
|
||||
setTokenBuffer(tokenBuf);
|
||||
}
|
||||
public LLkParser(TokenStream lexer, int k_)
|
||||
{
|
||||
k = k_;
|
||||
TokenBuffer tokenBuf = new TokenBuffer(lexer);
|
||||
setTokenBuffer(tokenBuf);
|
||||
}
|
||||
/*Consume another token from the input stream. Can only write sequentially!
|
||||
* If you need 3 tokens ahead, you must consume() 3 times.
|
||||
* <p>
|
||||
* Note that it is possible to overwrite tokens that have not been matched.
|
||||
* For example, calling consume() 3 times when k=2, means that the first token
|
||||
* consumed will be overwritten with the 3rd.
|
||||
*/
|
||||
override public void consume()
|
||||
{
|
||||
inputState.input.consume();
|
||||
}
|
||||
override public int LA(int i)
|
||||
{
|
||||
return inputState.input.LA(i);
|
||||
}
|
||||
override public IToken LT(int i)
|
||||
{
|
||||
return inputState.input.LT(i);
|
||||
}
|
||||
private void trace(string ee, string rname)
|
||||
{
|
||||
traceIndent();
|
||||
Console.Out.Write(ee + rname + ((inputState.guessing > 0)?"; [guessing]":"; "));
|
||||
for (int i = 1; i <= k; i++)
|
||||
{
|
||||
if (i != 1)
|
||||
{
|
||||
Console.Out.Write(", ");
|
||||
}
|
||||
if ( LT(i)!=null ) {
|
||||
Console.Out.Write("LA(" + i + ")==" + LT(i).getText());
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Out.Write("LA(" + i + ")==ull");
|
||||
}
|
||||
}
|
||||
Console.Out.WriteLine("");
|
||||
}
|
||||
override public void traceIn(string rname)
|
||||
{
|
||||
traceDepth += 1;
|
||||
trace("> ", rname);
|
||||
}
|
||||
override public void traceOut(string rname)
|
||||
{
|
||||
trace("< ", rname);
|
||||
traceDepth -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
88
src/Spring/Spring.Core/antlr/LexerSharedInputState.cs
Normal file
88
src/Spring/Spring.Core/antlr/LexerSharedInputState.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using Stream = System.IO.Stream;
|
||||
using TextReader = System.IO.TextReader;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*This object contains the data associated with an
|
||||
* input stream of characters. Multiple lexers
|
||||
* share a single LexerSharedInputState to lex
|
||||
* the same input stream.
|
||||
*/
|
||||
public class LexerSharedInputState
|
||||
{
|
||||
protected internal int column;
|
||||
protected internal int line;
|
||||
protected internal int tokenStartColumn;
|
||||
protected internal int tokenStartLine;
|
||||
protected internal InputBuffer input;
|
||||
|
||||
/*What file (if known) caused the problem? */
|
||||
protected internal string filename;
|
||||
|
||||
public int guessing;
|
||||
|
||||
public LexerSharedInputState(InputBuffer inbuf)
|
||||
{
|
||||
initialize();
|
||||
input = inbuf;
|
||||
}
|
||||
|
||||
public LexerSharedInputState(Stream inStream) : this(new ByteBuffer(inStream))
|
||||
{
|
||||
}
|
||||
|
||||
public LexerSharedInputState(TextReader inReader) : this(new CharBuffer(inReader))
|
||||
{
|
||||
}
|
||||
|
||||
private void initialize()
|
||||
{
|
||||
column = 1;
|
||||
line = 1;
|
||||
tokenStartColumn = 1;
|
||||
tokenStartLine = 1;
|
||||
guessing = 0;
|
||||
filename = null;
|
||||
}
|
||||
|
||||
public virtual void reset()
|
||||
{
|
||||
initialize();
|
||||
input.reset();
|
||||
}
|
||||
|
||||
public virtual void resetInput(InputBuffer ib)
|
||||
{
|
||||
reset();
|
||||
input = ib;
|
||||
}
|
||||
|
||||
public virtual void resetInput(Stream s)
|
||||
{
|
||||
reset();
|
||||
input = new ByteBuffer(s);
|
||||
}
|
||||
|
||||
public virtual void resetInput(TextReader tr)
|
||||
{
|
||||
reset();
|
||||
input = new CharBuffer(tr);
|
||||
}
|
||||
}
|
||||
}
|
||||
179
src/Spring/Spring.Core/antlr/MismatchedCharException.cs
Normal file
179
src/Spring/Spring.Core/antlr/MismatchedCharException.cs
Normal file
@@ -0,0 +1,179 @@
|
||||
using System;
|
||||
using StringBuilder = System.Text.StringBuilder;
|
||||
|
||||
using BitSet = antlr.collections.impl.BitSet;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
[Serializable]
|
||||
public class MismatchedCharException : RecognitionException
|
||||
{
|
||||
/*
|
||||
* Returns a clean error message (no line number/column information)
|
||||
*/
|
||||
override public string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
switch (mismatchType)
|
||||
{
|
||||
case CharTypeEnum.CharType:
|
||||
sb.Append("expecting "); appendCharName(sb, expecting);
|
||||
sb.Append(", found "); appendCharName(sb, foundChar);
|
||||
break;
|
||||
|
||||
case CharTypeEnum.NotCharType:
|
||||
sb.Append("expecting anything but '");
|
||||
appendCharName(sb, expecting);
|
||||
sb.Append("'; got it anyway");
|
||||
break;
|
||||
|
||||
case CharTypeEnum.RangeType:
|
||||
case CharTypeEnum.NotRangeType:
|
||||
sb.Append("expecting token ");
|
||||
if (mismatchType == CharTypeEnum.NotRangeType)
|
||||
sb.Append("NOT ");
|
||||
sb.Append("in range: ");
|
||||
appendCharName(sb, expecting);
|
||||
sb.Append("..");
|
||||
appendCharName(sb, upper);
|
||||
sb.Append(", found ");
|
||||
appendCharName(sb, foundChar);
|
||||
break;
|
||||
|
||||
case CharTypeEnum.SetType:
|
||||
case CharTypeEnum.NotSetType:
|
||||
sb.Append("expecting " + (mismatchType == CharTypeEnum.NotSetType ? "NOT " : "") + "one of (");
|
||||
int[] elems = bset.toArray();
|
||||
for (int i = 0; i < elems.Length; i++)
|
||||
{
|
||||
appendCharName(sb, elems[i]);
|
||||
}
|
||||
sb.Append("), found ");
|
||||
appendCharName(sb, foundChar);
|
||||
break;
|
||||
|
||||
default:
|
||||
sb.Append(base.Message);
|
||||
break;
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
// Types of chars
|
||||
|
||||
public enum CharTypeEnum
|
||||
{
|
||||
CharType = 1,
|
||||
NotCharType = 2,
|
||||
RangeType = 3,
|
||||
NotRangeType = 4,
|
||||
SetType = 5,
|
||||
NotSetType = 6
|
||||
}
|
||||
|
||||
// One of the above
|
||||
public CharTypeEnum mismatchType;
|
||||
|
||||
// what was found on the input stream
|
||||
public int foundChar;
|
||||
|
||||
// For CHAR/NOT_CHAR and RANGE/NOT_RANGE
|
||||
public int expecting;
|
||||
|
||||
// For RANGE/NOT_RANGE (expecting is lower bound of range)
|
||||
public int upper;
|
||||
|
||||
// For SET/NOT_SET
|
||||
public BitSet bset;
|
||||
|
||||
// who knows...they may want to ask scanner questions
|
||||
public CharScanner scanner;
|
||||
|
||||
/*
|
||||
* MismatchedCharException constructor comment.
|
||||
*/
|
||||
public MismatchedCharException() : base("Mismatched char")
|
||||
{
|
||||
}
|
||||
|
||||
// Expected range / not range
|
||||
public MismatchedCharException(char c, char lower, char upper_, bool matchNot, CharScanner scanner_) :
|
||||
base("Mismatched char", scanner_.getFilename(), scanner_.getLine(), scanner_.getColumn())
|
||||
{
|
||||
mismatchType = matchNot ? CharTypeEnum.NotRangeType : CharTypeEnum.RangeType;
|
||||
foundChar = c;
|
||||
expecting = lower;
|
||||
upper = upper_;
|
||||
scanner = scanner_;
|
||||
}
|
||||
|
||||
// Expected token / not token
|
||||
public MismatchedCharException(char c, char expecting_, bool matchNot, CharScanner scanner_) :
|
||||
base("Mismatched char", scanner_.getFilename(), scanner_.getLine(), scanner_.getColumn())
|
||||
{
|
||||
mismatchType = matchNot ? CharTypeEnum.NotCharType : CharTypeEnum.CharType;
|
||||
foundChar = c;
|
||||
expecting = expecting_;
|
||||
scanner = scanner_;
|
||||
}
|
||||
|
||||
// Expected BitSet / not BitSet
|
||||
public MismatchedCharException(char c, BitSet set_, bool matchNot, CharScanner scanner_) :
|
||||
base("Mismatched char", scanner_.getFilename(), scanner_.getLine(), scanner_.getColumn())
|
||||
{
|
||||
mismatchType = matchNot ? CharTypeEnum.NotSetType : CharTypeEnum.SetType;
|
||||
foundChar = c;
|
||||
bset = set_;
|
||||
scanner = scanner_;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append a char to the msg buffer. If special, then show escaped version
|
||||
/// </summary>
|
||||
/// <param name="sb">Message buffer</param>
|
||||
/// <param name="c">Char to append</param>
|
||||
private void appendCharName(StringBuilder sb, int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 65535 :
|
||||
// 65535 = (char) -1 = EOF
|
||||
sb.Append("'<EOF>'");
|
||||
break;
|
||||
case '\n' :
|
||||
sb.Append(@"'\n'");
|
||||
break;
|
||||
case '\r' :
|
||||
sb.Append(@"'\r'");
|
||||
break;
|
||||
case '\t' :
|
||||
sb.Append(@"'\t'");
|
||||
break;
|
||||
default :
|
||||
sb.Append('\'');
|
||||
sb.Append((char) c);
|
||||
sb.Append('\'');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
214
src/Spring/Spring.Core/antlr/MismatchedTokenException.cs
Normal file
214
src/Spring/Spring.Core/antlr/MismatchedTokenException.cs
Normal file
@@ -0,0 +1,214 @@
|
||||
using System;
|
||||
using StringBuilder = System.Text.StringBuilder;
|
||||
|
||||
using BitSet = antlr.collections.impl.BitSet;
|
||||
using AST = antlr.collections.AST;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
[Serializable]
|
||||
public class MismatchedTokenException : RecognitionException
|
||||
{
|
||||
// Token names array for formatting
|
||||
internal string[] tokenNames;
|
||||
// The token that was encountered
|
||||
public IToken token;
|
||||
// The offending AST node if tree walking
|
||||
public AST node;
|
||||
|
||||
internal string tokenText = null; // taken from node or token object
|
||||
|
||||
// Types of tokens
|
||||
public enum TokenTypeEnum
|
||||
{
|
||||
TokenType = 1,
|
||||
NotTokenType = 2,
|
||||
RangeType = 3,
|
||||
NotRangeType = 4,
|
||||
SetType = 5,
|
||||
NotSetType = 6
|
||||
}
|
||||
// One of the above
|
||||
public TokenTypeEnum mismatchType;
|
||||
|
||||
// For TOKEN/NOT_TOKEN and RANGE/NOT_RANGE
|
||||
public int expecting;
|
||||
|
||||
// For RANGE/NOT_RANGE (expecting is lower bound of range)
|
||||
public int upper;
|
||||
|
||||
// For SET/NOT_SET
|
||||
public BitSet bset;
|
||||
|
||||
/*Looking for AST wildcard, didn't find it */
|
||||
public MismatchedTokenException() : base("Mismatched Token: expecting any AST node", "<AST>", - 1, - 1)
|
||||
{
|
||||
}
|
||||
|
||||
// Expected range / not range
|
||||
public MismatchedTokenException(string[] tokenNames_, AST node_, int lower, int upper_, bool matchNot) :
|
||||
base("Mismatched Token", "<AST>", - 1, - 1)
|
||||
{
|
||||
tokenNames = tokenNames_;
|
||||
node = node_;
|
||||
if (node_ == null)
|
||||
{
|
||||
tokenText = "<empty tree>";
|
||||
}
|
||||
else
|
||||
{
|
||||
tokenText = node_.ToString();
|
||||
}
|
||||
mismatchType = matchNot ? TokenTypeEnum.NotRangeType : TokenTypeEnum.RangeType;
|
||||
expecting = lower;
|
||||
upper = upper_;
|
||||
}
|
||||
|
||||
// Expected token / not token
|
||||
public MismatchedTokenException(string[] tokenNames_, AST node_, int expecting_, bool matchNot) :
|
||||
base("Mismatched Token", "<AST>", - 1, - 1)
|
||||
{
|
||||
tokenNames = tokenNames_;
|
||||
node = node_;
|
||||
if (node_ == null)
|
||||
{
|
||||
tokenText = "<empty tree>";
|
||||
}
|
||||
else
|
||||
{
|
||||
tokenText = node_.ToString();
|
||||
}
|
||||
mismatchType = matchNot ? TokenTypeEnum.NotTokenType : TokenTypeEnum.TokenType;
|
||||
expecting = expecting_;
|
||||
}
|
||||
|
||||
// Expected BitSet / not BitSet
|
||||
public MismatchedTokenException(string[] tokenNames_, AST node_, BitSet set_, bool matchNot) :
|
||||
base("Mismatched Token", "<AST>", - 1, - 1)
|
||||
{
|
||||
tokenNames = tokenNames_;
|
||||
node = node_;
|
||||
if (node_ == null)
|
||||
{
|
||||
tokenText = "<empty tree>";
|
||||
}
|
||||
else
|
||||
{
|
||||
tokenText = node_.ToString();
|
||||
}
|
||||
mismatchType = matchNot ? TokenTypeEnum.NotSetType : TokenTypeEnum.SetType;
|
||||
bset = set_;
|
||||
}
|
||||
|
||||
// Expected range / not range
|
||||
public MismatchedTokenException(string[] tokenNames_, IToken token_, int lower, int upper_, bool matchNot, string fileName_) :
|
||||
base("Mismatched Token", fileName_, token_.getLine(), token_.getColumn())
|
||||
{
|
||||
tokenNames = tokenNames_;
|
||||
token = token_;
|
||||
tokenText = token_.getText();
|
||||
mismatchType = matchNot ? TokenTypeEnum.NotRangeType : TokenTypeEnum.RangeType;
|
||||
expecting = lower;
|
||||
upper = upper_;
|
||||
}
|
||||
|
||||
// Expected token / not token
|
||||
public MismatchedTokenException(string[] tokenNames_, IToken token_, int expecting_, bool matchNot, string fileName_) :
|
||||
base("Mismatched Token", fileName_, token_.getLine(), token_.getColumn())
|
||||
{
|
||||
tokenNames = tokenNames_;
|
||||
token = token_;
|
||||
tokenText = token_.getText();
|
||||
mismatchType = matchNot ? TokenTypeEnum.NotTokenType : TokenTypeEnum.TokenType;
|
||||
expecting = expecting_;
|
||||
}
|
||||
|
||||
// Expected BitSet / not BitSet
|
||||
public MismatchedTokenException(string[] tokenNames_, IToken token_, BitSet set_, bool matchNot, string fileName_) :
|
||||
base("Mismatched Token", fileName_, token_.getLine(), token_.getColumn())
|
||||
{
|
||||
tokenNames = tokenNames_;
|
||||
token = token_;
|
||||
tokenText = token_.getText();
|
||||
mismatchType = matchNot ? TokenTypeEnum.NotSetType : TokenTypeEnum.SetType;
|
||||
bset = set_;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a clean error message (no line number/column information)
|
||||
*/
|
||||
override public string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
switch (mismatchType)
|
||||
{
|
||||
case TokenTypeEnum.TokenType:
|
||||
sb.Append("expecting " + tokenName(expecting) + ", found '" + tokenText + "'");
|
||||
break;
|
||||
|
||||
case TokenTypeEnum.NotTokenType:
|
||||
sb.Append("expecting anything but " + tokenName(expecting) + "; got it anyway");
|
||||
break;
|
||||
|
||||
case TokenTypeEnum.RangeType:
|
||||
sb.Append("expecting token in range: " + tokenName(expecting) + ".." + tokenName(upper) + ", found '" + tokenText + "'");
|
||||
break;
|
||||
|
||||
case TokenTypeEnum.NotRangeType:
|
||||
sb.Append("expecting token NOT in range: " + tokenName(expecting) + ".." + tokenName(upper) + ", found '" + tokenText + "'");
|
||||
break;
|
||||
|
||||
case TokenTypeEnum.SetType: case TokenTypeEnum.NotSetType:
|
||||
sb.Append("expecting " + (mismatchType == TokenTypeEnum.NotSetType ? "NOT " : "") + "one of (");
|
||||
int[] elems = bset.toArray();
|
||||
for (int i = 0; i < elems.Length; i++)
|
||||
{
|
||||
sb.Append(" ");
|
||||
sb.Append(tokenName(elems[i]));
|
||||
}
|
||||
sb.Append("), found '" + tokenText + "'");
|
||||
break;
|
||||
|
||||
default:
|
||||
sb.Append(base.Message);
|
||||
break;
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private string tokenName(int tokenType)
|
||||
{
|
||||
if (tokenType == Token.INVALID_TYPE)
|
||||
{
|
||||
return "<Set of tokens>";
|
||||
}
|
||||
else if (tokenType < 0 || tokenType >= tokenNames.Length)
|
||||
{
|
||||
return "<" + tokenType.ToString() + ">";
|
||||
}
|
||||
else
|
||||
{
|
||||
return tokenNames[tokenType];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
61
src/Spring/Spring.Core/antlr/NoViableAltException.cs
Normal file
61
src/Spring/Spring.Core/antlr/NoViableAltException.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
|
||||
using AST = antlr.collections.AST;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
[Serializable]
|
||||
public class NoViableAltException : RecognitionException
|
||||
{
|
||||
public IToken token;
|
||||
public AST node; // handles parsing and treeparsing
|
||||
|
||||
public NoViableAltException(AST t) : base("NoViableAlt", "<AST>", - 1, - 1)
|
||||
{
|
||||
node = t;
|
||||
}
|
||||
|
||||
public NoViableAltException(IToken t, string fileName_) :
|
||||
base("NoViableAlt", fileName_, t.getLine(), t.getColumn())
|
||||
{
|
||||
token = t;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a clean error message (no line number/column information)
|
||||
*/
|
||||
override public string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
if (token != null)
|
||||
{
|
||||
//return "unexpected token: " + token.getText();
|
||||
return "unexpected token: " + token.ToString();
|
||||
}
|
||||
|
||||
// must a tree parser error if token==null
|
||||
if ( (node==null) || (node==TreeParser.ASTNULL) )
|
||||
{
|
||||
return "unexpected end of subtree";
|
||||
}
|
||||
return "unexpected AST node: " + node.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
66
src/Spring/Spring.Core/antlr/NoViableAltForCharException.cs
Normal file
66
src/Spring/Spring.Core/antlr/NoViableAltForCharException.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using StringBuilder = System.Text.StringBuilder;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
[Serializable]
|
||||
public class NoViableAltForCharException : RecognitionException
|
||||
{
|
||||
public char foundChar;
|
||||
|
||||
public NoViableAltForCharException(char c, CharScanner scanner) :
|
||||
base("NoViableAlt", scanner.getFilename(), scanner.getLine(), scanner.getColumn())
|
||||
{
|
||||
foundChar = c;
|
||||
}
|
||||
|
||||
public NoViableAltForCharException(char c, string fileName, int line, int column) :
|
||||
base("NoViableAlt", fileName, line, column)
|
||||
{
|
||||
foundChar = c;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a clean error message (no line number/column information)
|
||||
*/
|
||||
override public string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
StringBuilder mesg = new StringBuilder("unexpected char: ");
|
||||
|
||||
// I'm trying to mirror a change in the C++ stuff.
|
||||
// But java seems to lack something isprint-ish..
|
||||
// so we do it manually. This is probably too restrictive.
|
||||
|
||||
if ((foundChar >= ' ') && (foundChar <= '~'))
|
||||
{
|
||||
mesg.Append('\'');
|
||||
mesg.Append(foundChar);
|
||||
mesg.Append('\'');
|
||||
}
|
||||
else
|
||||
{
|
||||
mesg.Append("0x");
|
||||
mesg.Append(((int)foundChar).ToString("X"));
|
||||
}
|
||||
return mesg.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
75
src/Spring/Spring.Core/antlr/ParseTree.cs
Normal file
75
src/Spring/Spring.Core/antlr/ParseTree.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
namespace antlr
|
||||
{
|
||||
/* ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
|
||||
using System;
|
||||
using StringBuilder = System.Text.StringBuilder;
|
||||
using AST = antlr.collections.AST;
|
||||
|
||||
public abstract class ParseTree : BaseAST
|
||||
{
|
||||
/// <summary>
|
||||
/// Walk parse tree and return requested number of derivation steps.
|
||||
/// If steps less-than 0, return node text. If steps equals 1, return derivation
|
||||
/// string at step.
|
||||
/// </summary>
|
||||
/// <param name="step">derivation steps</param>
|
||||
/// <returns></returns>
|
||||
public string getLeftmostDerivationStep(int step)
|
||||
{
|
||||
if ( step <= 0 )
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
StringBuilder buf = new StringBuilder (2000);
|
||||
getLeftmostDerivation(buf, step);
|
||||
return buf.ToString();
|
||||
}
|
||||
|
||||
public string getLeftmostDerivation(int maxSteps)
|
||||
{
|
||||
StringBuilder buf = new StringBuilder(2000);
|
||||
buf.Append(" " + this.ToString());
|
||||
buf.Append("\n");
|
||||
for (int d=1; d < maxSteps; d++)
|
||||
{
|
||||
buf.Append(" =>");
|
||||
buf.Append(getLeftmostDerivationStep(d));
|
||||
buf.Append("\n");
|
||||
}
|
||||
return buf.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get derivation and return how many you did (less than requested for
|
||||
/// subtree roots.
|
||||
/// </summary>
|
||||
/// <param name="buf">string buffer</param>
|
||||
/// <param name="step">derivation steps</param>
|
||||
/// <returns></returns>
|
||||
protected internal abstract int getLeftmostDerivation(StringBuilder buf, int step);
|
||||
|
||||
// just satisfy BaseAST interface; unused as we manually create nodes
|
||||
|
||||
public override void initialize(int i, string s)
|
||||
{
|
||||
}
|
||||
|
||||
public override void initialize(AST ast)
|
||||
{
|
||||
}
|
||||
|
||||
public override void initialize(IToken token)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
92
src/Spring/Spring.Core/antlr/ParseTreeRule.cs
Normal file
92
src/Spring/Spring.Core/antlr/ParseTreeRule.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
namespace antlr
|
||||
{
|
||||
|
||||
/* ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
|
||||
using System;
|
||||
using StringBuilder = System.Text.StringBuilder;
|
||||
using AST = antlr.collections.AST;
|
||||
|
||||
public class ParseTreeRule : ParseTree
|
||||
{
|
||||
public const int INVALID_ALT = -1;
|
||||
|
||||
protected string ruleName;
|
||||
protected int altNumber; // unused until I modify antlr to record this
|
||||
|
||||
public ParseTreeRule(string ruleName) : this(ruleName, INVALID_ALT)
|
||||
{
|
||||
}
|
||||
|
||||
public ParseTreeRule(string ruleName, int altNumber)
|
||||
{
|
||||
this.ruleName = ruleName;
|
||||
this.altNumber = altNumber;
|
||||
}
|
||||
|
||||
public string getRuleName()
|
||||
{
|
||||
return ruleName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do a step-first walk, building up a buffer of tokens until
|
||||
/// you've reached a particular step and print out any rule subroots
|
||||
/// insteads of descending.
|
||||
/// </summary>
|
||||
/// <param name="buf">derivation buffer</param>
|
||||
/// <param name="step">derivation steps</param>
|
||||
/// <returns></returns>
|
||||
protected internal override int getLeftmostDerivation(StringBuilder buf, int step)
|
||||
{
|
||||
int numReplacements = 0;
|
||||
if ( step <= 0 )
|
||||
{
|
||||
buf.Append(' ');
|
||||
buf.Append(ToString());
|
||||
return numReplacements;
|
||||
}
|
||||
AST child = getFirstChild();
|
||||
numReplacements = 1;
|
||||
// walk child printing them out, descending into at most one
|
||||
while ( child != null )
|
||||
{
|
||||
if ( (numReplacements >= step) || (child is ParseTreeToken) )
|
||||
{
|
||||
buf.Append(' ');
|
||||
buf.Append(child.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
// descend for at least one more derivation; update count
|
||||
int remainingReplacements = step - numReplacements;
|
||||
int n = ((ParseTree) child).getLeftmostDerivation(buf, remainingReplacements);
|
||||
numReplacements += n;
|
||||
}
|
||||
child = child.getNextSibling();
|
||||
}
|
||||
return numReplacements;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if ( altNumber == INVALID_ALT )
|
||||
{
|
||||
return '<'+ruleName+'>';
|
||||
}
|
||||
else
|
||||
{
|
||||
return '<'+ruleName+"["+altNumber+"]>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
44
src/Spring/Spring.Core/antlr/ParseTreeToken.cs
Normal file
44
src/Spring/Spring.Core/antlr/ParseTreeToken.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
namespace antlr
|
||||
{
|
||||
|
||||
/* ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
|
||||
using System;
|
||||
using StringBuilder = System.Text.StringBuilder;
|
||||
using AST = antlr.collections.AST;
|
||||
|
||||
public class ParseTreeToken : ParseTree
|
||||
{
|
||||
protected IToken token;
|
||||
|
||||
public ParseTreeToken(IToken token)
|
||||
{
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
protected override internal int getLeftmostDerivation(StringBuilder buf, int step)
|
||||
{
|
||||
buf.Append(' ');
|
||||
buf.Append(ToString());
|
||||
return step; // did on replacements
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if ( token != null )
|
||||
{
|
||||
return token.getText();
|
||||
}
|
||||
return "<missing token>";
|
||||
}
|
||||
}
|
||||
}
|
||||
507
src/Spring/Spring.Core/antlr/Parser.cs
Normal file
507
src/Spring/Spring.Core/antlr/Parser.cs
Normal file
@@ -0,0 +1,507 @@
|
||||
using System;
|
||||
using EventHandlerList = System.ComponentModel.EventHandlerList;
|
||||
|
||||
using BitSet = antlr.collections.impl.BitSet;
|
||||
using AST = antlr.collections.AST;
|
||||
using ASTArray = antlr.collections.impl.ASTArray;
|
||||
using antlr.debug;
|
||||
|
||||
using MessageListener = antlr.debug.MessageListener;
|
||||
using ParserListener = antlr.debug.ParserListener;
|
||||
using ParserMatchListener = antlr.debug.ParserMatchListener;
|
||||
using ParserTokenListener = antlr.debug.ParserTokenListener;
|
||||
using SemanticPredicateListener = antlr.debug.SemanticPredicateListener;
|
||||
using SyntacticPredicateListener = antlr.debug.SyntacticPredicateListener;
|
||||
using TraceListener = antlr.debug.TraceListener;
|
||||
|
||||
/*
|
||||
private Vector messageListeners;
|
||||
private Vector newLineListeners;
|
||||
private Vector matchListeners;
|
||||
private Vector tokenListeners;
|
||||
private Vector semPredListeners;
|
||||
private Vector synPredListeners;
|
||||
private Vector traceListeners;
|
||||
*/
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
public abstract class Parser : IParserDebugSubject
|
||||
{
|
||||
// Used to store event delegates
|
||||
private EventHandlerList events_ = new EventHandlerList();
|
||||
|
||||
protected internal EventHandlerList Events
|
||||
{
|
||||
get { return events_; }
|
||||
}
|
||||
|
||||
// The unique keys for each event that Parser [objects] can generate
|
||||
internal static readonly object EnterRuleEventKey = new object();
|
||||
internal static readonly object ExitRuleEventKey = new object();
|
||||
internal static readonly object DoneEventKey = new object();
|
||||
internal static readonly object ReportErrorEventKey = new object();
|
||||
internal static readonly object ReportWarningEventKey = new object();
|
||||
internal static readonly object NewLineEventKey = new object();
|
||||
internal static readonly object MatchEventKey = new object();
|
||||
internal static readonly object MatchNotEventKey = new object();
|
||||
internal static readonly object MisMatchEventKey = new object();
|
||||
internal static readonly object MisMatchNotEventKey = new object();
|
||||
internal static readonly object ConsumeEventKey = new object();
|
||||
internal static readonly object LAEventKey = new object();
|
||||
internal static readonly object SemPredEvaluatedEventKey = new object();
|
||||
internal static readonly object SynPredStartedEventKey = new object();
|
||||
internal static readonly object SynPredFailedEventKey = new object();
|
||||
internal static readonly object SynPredSucceededEventKey = new object();
|
||||
|
||||
protected internal ParserSharedInputState inputState;
|
||||
|
||||
/*Nesting level of registered handlers */
|
||||
// protected int exceptionLevel = 0;
|
||||
|
||||
/*Table of token type to token names */
|
||||
protected internal string[] tokenNames;
|
||||
|
||||
/*AST return value for a rule is squirreled away here */
|
||||
protected internal AST returnAST;
|
||||
|
||||
/*AST support code; parser and treeparser delegate to this object */
|
||||
protected internal ASTFactory astFactory = new ASTFactory();
|
||||
|
||||
private bool ignoreInvalidDebugCalls = false;
|
||||
|
||||
/*Used to keep track of indentdepth for traceIn/Out */
|
||||
protected internal int traceDepth = 0;
|
||||
|
||||
public Parser()
|
||||
{
|
||||
inputState = new ParserSharedInputState();
|
||||
}
|
||||
|
||||
public Parser(ParserSharedInputState state)
|
||||
{
|
||||
inputState = state;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
public event TraceEventHandler EnterRule
|
||||
{
|
||||
add { Events.AddHandler(EnterRuleEventKey, value); }
|
||||
remove { Events.RemoveHandler(EnterRuleEventKey, value); }
|
||||
}
|
||||
|
||||
public event TraceEventHandler ExitRule
|
||||
{
|
||||
add { Events.AddHandler(ExitRuleEventKey, value); }
|
||||
remove { Events.RemoveHandler(ExitRuleEventKey, value); }
|
||||
}
|
||||
|
||||
public event TraceEventHandler Done
|
||||
{
|
||||
add { Events.AddHandler(DoneEventKey, value); }
|
||||
remove { Events.RemoveHandler(DoneEventKey, value); }
|
||||
}
|
||||
|
||||
public event MessageEventHandler ErrorReported
|
||||
{
|
||||
add { Events.AddHandler(ReportErrorEventKey, value); }
|
||||
remove { Events.RemoveHandler(ReportErrorEventKey, value); }
|
||||
}
|
||||
|
||||
public event MessageEventHandler WarningReported
|
||||
{
|
||||
add { Events.AddHandler(ReportWarningEventKey, value); }
|
||||
remove { Events.RemoveHandler(ReportWarningEventKey, value); }
|
||||
}
|
||||
|
||||
public event MatchEventHandler MatchedToken
|
||||
{
|
||||
add { Events.AddHandler(MatchEventKey, value); }
|
||||
remove { Events.RemoveHandler(MatchEventKey, value); }
|
||||
}
|
||||
|
||||
public event MatchEventHandler MatchedNotToken
|
||||
{
|
||||
add { Events.AddHandler(MatchNotEventKey, value); }
|
||||
remove { Events.RemoveHandler(MatchNotEventKey, value); }
|
||||
}
|
||||
|
||||
public event MatchEventHandler MisMatchedToken
|
||||
{
|
||||
add { Events.AddHandler(MisMatchEventKey, value); }
|
||||
remove { Events.RemoveHandler(MisMatchEventKey, value); }
|
||||
}
|
||||
|
||||
public event MatchEventHandler MisMatchedNotToken
|
||||
{
|
||||
add { Events.AddHandler(MisMatchNotEventKey, value); }
|
||||
remove { Events.RemoveHandler(MisMatchNotEventKey, value); }
|
||||
}
|
||||
|
||||
public event TokenEventHandler ConsumedToken
|
||||
{
|
||||
add { Events.AddHandler(ConsumeEventKey, value); }
|
||||
remove { Events.RemoveHandler(ConsumeEventKey, value); }
|
||||
}
|
||||
|
||||
public event TokenEventHandler TokenLA
|
||||
{
|
||||
add { Events.AddHandler(LAEventKey, value); }
|
||||
remove { Events.RemoveHandler(LAEventKey, value); }
|
||||
}
|
||||
|
||||
public event SemanticPredicateEventHandler SemPredEvaluated
|
||||
{
|
||||
add { Events.AddHandler(SemPredEvaluatedEventKey, value); }
|
||||
remove { Events.RemoveHandler(SemPredEvaluatedEventKey, value); }
|
||||
}
|
||||
|
||||
public event SyntacticPredicateEventHandler SynPredStarted
|
||||
{
|
||||
add { Events.AddHandler(SynPredStartedEventKey, value); }
|
||||
remove { Events.RemoveHandler(SynPredStartedEventKey, value); }
|
||||
}
|
||||
|
||||
public event SyntacticPredicateEventHandler SynPredFailed
|
||||
{
|
||||
add { Events.AddHandler(SynPredFailedEventKey, value); }
|
||||
remove { Events.RemoveHandler(SynPredFailedEventKey, value); }
|
||||
}
|
||||
|
||||
public event SyntacticPredicateEventHandler SynPredSucceeded
|
||||
{
|
||||
add { Events.AddHandler(SynPredSucceededEventKey, value); }
|
||||
remove { Events.RemoveHandler(SynPredSucceededEventKey, value); }
|
||||
}
|
||||
|
||||
|
||||
public virtual void addMessageListener(MessageListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.ArgumentException("addMessageListener() is only valid if parser built for debugging");
|
||||
}
|
||||
|
||||
public virtual void addParserListener(ParserListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.ArgumentException("addParserListener() is only valid if parser built for debugging");
|
||||
}
|
||||
|
||||
public virtual void addParserMatchListener(ParserMatchListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.ArgumentException("addParserMatchListener() is only valid if parser built for debugging");
|
||||
}
|
||||
|
||||
public virtual void addParserTokenListener(ParserTokenListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.ArgumentException("addParserTokenListener() is only valid if parser built for debugging");
|
||||
}
|
||||
|
||||
public virtual void addSemanticPredicateListener(SemanticPredicateListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.ArgumentException("addSemanticPredicateListener() is only valid if parser built for debugging");
|
||||
}
|
||||
|
||||
public virtual void addSyntacticPredicateListener(SyntacticPredicateListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.ArgumentException("addSyntacticPredicateListener() is only valid if parser built for debugging");
|
||||
}
|
||||
|
||||
public virtual void addTraceListener(TraceListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.ArgumentException("addTraceListener() is only valid if parser built for debugging");
|
||||
}
|
||||
|
||||
/*Get another token object from the token stream */
|
||||
public abstract void consume();
|
||||
/*Consume tokens until one matches the given token */
|
||||
public virtual void consumeUntil(int tokenType)
|
||||
{
|
||||
while (LA(1) != Token.EOF_TYPE && LA(1) != tokenType)
|
||||
{
|
||||
consume();
|
||||
}
|
||||
}
|
||||
/*Consume tokens until one matches the given token set */
|
||||
public virtual void consumeUntil(BitSet bset)
|
||||
{
|
||||
while (LA(1) != Token.EOF_TYPE && !bset.member(LA(1)))
|
||||
{
|
||||
consume();
|
||||
}
|
||||
}
|
||||
protected internal virtual void defaultDebuggingSetup(TokenStream lexer, TokenBuffer tokBuf)
|
||||
{
|
||||
// by default, do nothing -- we're not debugging
|
||||
}
|
||||
/*Get the AST return value squirreled away in the parser */
|
||||
public virtual AST getAST()
|
||||
{
|
||||
return returnAST;
|
||||
}
|
||||
public virtual ASTFactory getASTFactory()
|
||||
{
|
||||
return astFactory;
|
||||
}
|
||||
public virtual string getFilename()
|
||||
{
|
||||
return inputState.filename;
|
||||
}
|
||||
|
||||
public virtual ParserSharedInputState getInputState()
|
||||
{
|
||||
return inputState;
|
||||
}
|
||||
|
||||
public virtual void setInputState(ParserSharedInputState state)
|
||||
{
|
||||
inputState = state;
|
||||
}
|
||||
|
||||
public virtual void resetState()
|
||||
{
|
||||
traceDepth = 0;
|
||||
inputState.reset();
|
||||
}
|
||||
|
||||
public virtual string getTokenName(int num)
|
||||
{
|
||||
return tokenNames[num];
|
||||
}
|
||||
public virtual string[] getTokenNames()
|
||||
{
|
||||
return tokenNames;
|
||||
}
|
||||
public virtual bool isDebugMode()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/*Return the token type of the ith token of lookahead where i=1
|
||||
* is the current token being examined by the parser (i.e., it
|
||||
* has not been matched yet).
|
||||
*/
|
||||
public abstract int LA(int i);
|
||||
/*Return the ith token of lookahead */
|
||||
public abstract IToken LT(int i);
|
||||
// Forwarded to TokenBuffer
|
||||
public virtual int mark()
|
||||
{
|
||||
return inputState.input.mark();
|
||||
}
|
||||
/*Make sure current lookahead symbol matches token type <tt>t</tt>.
|
||||
* Throw an exception upon mismatch, which is catch by either the
|
||||
* error handler or by the syntactic predicate.
|
||||
*/
|
||||
public virtual void match(int t)
|
||||
{
|
||||
if (LA(1) != t)
|
||||
throw new MismatchedTokenException(tokenNames, LT(1), t, false, getFilename());
|
||||
else
|
||||
consume();
|
||||
}
|
||||
/*Make sure current lookahead symbol matches the given set
|
||||
* Throw an exception upon mismatch, which is catch by either the
|
||||
* error handler or by the syntactic predicate.
|
||||
*/
|
||||
public virtual void match(BitSet b)
|
||||
{
|
||||
if (!b.member(LA(1)))
|
||||
throw new MismatchedTokenException(tokenNames, LT(1), b, false, getFilename());
|
||||
else
|
||||
consume();
|
||||
}
|
||||
public virtual void matchNot(int t)
|
||||
{
|
||||
if (LA(1) == t)
|
||||
throw new MismatchedTokenException(tokenNames, LT(1), t, true, getFilename());
|
||||
else
|
||||
consume();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// @deprecated as of 2.7.2. This method calls System.exit() and writes
|
||||
/// directly to stderr, which is usually not appropriate when
|
||||
/// a parser is embedded into a larger application. Since the method is
|
||||
/// <code>static</code>, it cannot be overridden to avoid these problems.
|
||||
/// ANTLR no longer uses this method internally or in generated code.
|
||||
/// </summary>
|
||||
///
|
||||
[Obsolete("De-activated since version 2.7.2.6 as it cannot be overidden.", true)]
|
||||
public static void panic()
|
||||
{
|
||||
System.Console.Error.WriteLine("Parser: panic");
|
||||
System.Environment.Exit(1);
|
||||
}
|
||||
|
||||
public virtual void removeMessageListener(MessageListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.SystemException("removeMessageListener() is only valid if parser built for debugging");
|
||||
}
|
||||
public virtual void removeParserListener(ParserListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.SystemException("removeParserListener() is only valid if parser built for debugging");
|
||||
}
|
||||
public virtual void removeParserMatchListener(ParserMatchListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.SystemException("removeParserMatchListener() is only valid if parser built for debugging");
|
||||
}
|
||||
public virtual void removeParserTokenListener(ParserTokenListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.SystemException("removeParserTokenListener() is only valid if parser built for debugging");
|
||||
}
|
||||
public virtual void removeSemanticPredicateListener(SemanticPredicateListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.ArgumentException("removeSemanticPredicateListener() is only valid if parser built for debugging");
|
||||
}
|
||||
public virtual void removeSyntacticPredicateListener(SyntacticPredicateListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.ArgumentException("removeSyntacticPredicateListener() is only valid if parser built for debugging");
|
||||
}
|
||||
public virtual void removeTraceListener(TraceListener l)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.SystemException("removeTraceListener() is only valid if parser built for debugging");
|
||||
}
|
||||
|
||||
/*Parser error-reporting function can be overridden in subclass */
|
||||
public virtual void reportError(RecognitionException ex)
|
||||
{
|
||||
Console.Error.WriteLine(ex);
|
||||
}
|
||||
|
||||
/*Parser error-reporting function can be overridden in subclass */
|
||||
public virtual void reportError(string s)
|
||||
{
|
||||
if (getFilename() == null)
|
||||
{
|
||||
Console.Error.WriteLine("error: " + s);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine(getFilename() + ": error: " + s);
|
||||
}
|
||||
}
|
||||
|
||||
/*Parser warning-reporting function can be overridden in subclass */
|
||||
public virtual void reportWarning(string s)
|
||||
{
|
||||
if (getFilename() == null)
|
||||
{
|
||||
Console.Error.WriteLine("warning: " + s);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine(getFilename() + ": warning: " + s);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void recover(RecognitionException ex, BitSet tokenSet)
|
||||
{
|
||||
consume();
|
||||
consumeUntil(tokenSet);
|
||||
}
|
||||
|
||||
public virtual void rewind(int pos)
|
||||
{
|
||||
inputState.input.rewind(pos);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specify an object with support code (shared by Parser and TreeParser.
|
||||
/// Normally, the programmer does not play with this, using
|
||||
/// <see cref="setASTNodeClass"/> instead.
|
||||
/// </summary>
|
||||
/// <param name="f"></param>
|
||||
public virtual void setASTFactory(ASTFactory f)
|
||||
{
|
||||
astFactory = f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specify the type of node to create during tree building.
|
||||
/// </summary>
|
||||
/// <param name="cl">Fully qualified AST Node type name.</param>
|
||||
public virtual void setASTNodeClass(string cl)
|
||||
{
|
||||
astFactory.setASTNodeType(cl);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specify the type of node to create during tree building.
|
||||
/// use <see cref="setASTNodeClass"/> now to be consistent with
|
||||
/// Token Object Type accessor.
|
||||
/// </summary>
|
||||
/// <param name="nodeType">Fully qualified AST Node type name.</param>
|
||||
[Obsolete("Replaced by setASTNodeClass(string) since version 2.7.1", true)]
|
||||
public virtual void setASTNodeType(string nodeType)
|
||||
{
|
||||
setASTNodeClass(nodeType);
|
||||
}
|
||||
|
||||
public virtual void setDebugMode(bool debugMode)
|
||||
{
|
||||
if (!ignoreInvalidDebugCalls)
|
||||
throw new System.SystemException("setDebugMode() only valid if parser built for debugging");
|
||||
}
|
||||
public virtual void setFilename(string f)
|
||||
{
|
||||
inputState.filename = f;
|
||||
}
|
||||
public virtual void setIgnoreInvalidDebugCalls(bool Value)
|
||||
{
|
||||
ignoreInvalidDebugCalls = Value;
|
||||
}
|
||||
/*Set or change the input token buffer */
|
||||
public virtual void setTokenBuffer(TokenBuffer t)
|
||||
{
|
||||
inputState.input = t;
|
||||
}
|
||||
|
||||
public virtual void traceIndent()
|
||||
{
|
||||
for (int i = 0; i < traceDepth; i++)
|
||||
Console.Out.Write(" ");
|
||||
}
|
||||
public virtual void traceIn(string rname)
|
||||
{
|
||||
traceDepth += 1;
|
||||
traceIndent();
|
||||
Console.Out.WriteLine("> " + rname + "; LA(1)==" + LT(1).getText() + ((inputState.guessing > 0)?" [guessing]":""));
|
||||
}
|
||||
public virtual void traceOut(string rname)
|
||||
{
|
||||
traceIndent();
|
||||
Console.Out.WriteLine("< " + rname + "; LA(1)==" + LT(1).getText() + ((inputState.guessing > 0)?" [guessing]":""));
|
||||
traceDepth -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
src/Spring/Spring.Core/antlr/ParserSharedInputState.cs
Normal file
44
src/Spring/Spring.Core/antlr/ParserSharedInputState.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*This object contains the data associated with an
|
||||
* input stream of tokens. Multiple parsers
|
||||
* share a single ParserSharedInputState to parse
|
||||
* the same stream of tokens.
|
||||
*/
|
||||
|
||||
public class ParserSharedInputState
|
||||
{
|
||||
/*Where to get token objects */
|
||||
protected internal TokenBuffer input;
|
||||
|
||||
/*Are we guessing (guessing>0)? */
|
||||
public int guessing = 0;
|
||||
|
||||
/*What file (if known) caused the problem? */
|
||||
protected internal string filename;
|
||||
|
||||
public virtual void reset()
|
||||
{
|
||||
guessing = 0;
|
||||
filename = null;
|
||||
input.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
82
src/Spring/Spring.Core/antlr/RecognitionException.cs
Normal file
82
src/Spring/Spring.Core/antlr/RecognitionException.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
[Serializable]
|
||||
public class RecognitionException : ANTLRException
|
||||
{
|
||||
public string fileName; // not used by treeparsers
|
||||
public int line; // not used by treeparsers
|
||||
public int column; // not used by treeparsers
|
||||
|
||||
public RecognitionException() : base("parsing error")
|
||||
{
|
||||
fileName = null;
|
||||
line = - 1;
|
||||
column = - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* RecognitionException constructor comment.
|
||||
* @param s java.lang.String
|
||||
*/
|
||||
public RecognitionException(string s) : base(s)
|
||||
{
|
||||
fileName = null;
|
||||
line = - 1;
|
||||
column = - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* RecognitionException constructor comment.
|
||||
* @param s java.lang.String
|
||||
*/
|
||||
public RecognitionException(string s, string fileName_, int line_, int column_) : base(s)
|
||||
{
|
||||
fileName = fileName_;
|
||||
line = line_;
|
||||
column = column_;
|
||||
}
|
||||
|
||||
public virtual string getFilename()
|
||||
{
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public virtual int getLine()
|
||||
{
|
||||
return line;
|
||||
}
|
||||
|
||||
public virtual int getColumn()
|
||||
{
|
||||
return column;
|
||||
}
|
||||
|
||||
[Obsolete("Replaced by Message property since version 2.7.0", true)]
|
||||
public virtual string getErrorMessage()
|
||||
{
|
||||
return Message;
|
||||
}
|
||||
|
||||
override public string ToString()
|
||||
{
|
||||
return FileLineFormatter.getFormatter().getFormatString(fileName, line, column) + Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
39
src/Spring/Spring.Core/antlr/SemanticException.cs
Normal file
39
src/Spring/Spring.Core/antlr/SemanticException.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
[Serializable]
|
||||
public class SemanticException : RecognitionException
|
||||
{
|
||||
public SemanticException(string s) : base(s)
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("Replaced by SemanticException(string, string, int, int) since version 2.7.2.6", false)]
|
||||
public SemanticException(String s, String fileName, int line) :
|
||||
this(s, fileName, line, -1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SemanticException(string s, string fileName, int line, int column) :
|
||||
base(s, fileName, line, column)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
119
src/Spring/Spring.Core/antlr/StringUtils.cs
Normal file
119
src/Spring/Spring.Core/antlr/StringUtils.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/* ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
public class StringUtils
|
||||
{
|
||||
/*General-purpose utility function for removing
|
||||
* characters from back of string
|
||||
* @param s The string to process
|
||||
* @param c The character to remove
|
||||
* @return The resulting string
|
||||
*/
|
||||
static public string stripBack(string s, char c)
|
||||
{
|
||||
while (s.Length > 0 && s[s.Length - 1] == c)
|
||||
{
|
||||
s = s.Substring(0, (s.Length - 1) - (0));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/*General-purpose utility function for removing
|
||||
* characters from back of string
|
||||
* @param s The string to process
|
||||
* @param remove A string containing the set of characters to remove
|
||||
* @return The resulting string
|
||||
*/
|
||||
static public string stripBack(string s, string remove)
|
||||
{
|
||||
bool changed;
|
||||
do
|
||||
{
|
||||
changed = false;
|
||||
for (int i = 0; i < remove.Length; i++)
|
||||
{
|
||||
char c = remove[i];
|
||||
while (s.Length > 0 && s[s.Length - 1] == c)
|
||||
{
|
||||
changed = true;
|
||||
s = s.Substring(0, (s.Length - 1) - (0));
|
||||
}
|
||||
}
|
||||
}
|
||||
while (changed);
|
||||
return s;
|
||||
}
|
||||
|
||||
/*General-purpose utility function for removing
|
||||
* characters from front of string
|
||||
* @param s The string to process
|
||||
* @param c The character to remove
|
||||
* @return The resulting string
|
||||
*/
|
||||
static public string stripFront(string s, char c)
|
||||
{
|
||||
while (s.Length > 0 && s[0] == c)
|
||||
{
|
||||
s = s.Substring(1);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/*General-purpose utility function for removing
|
||||
* characters from front of string
|
||||
* @param s The string to process
|
||||
* @param remove A string containing the set of characters to remove
|
||||
* @return The resulting string
|
||||
*/
|
||||
static public string stripFront(string s, string remove)
|
||||
{
|
||||
bool changed;
|
||||
do
|
||||
{
|
||||
changed = false;
|
||||
for (int i = 0; i < remove.Length; i++)
|
||||
{
|
||||
char c = remove[i];
|
||||
while (s.Length > 0 && s[0] == c)
|
||||
{
|
||||
changed = true;
|
||||
s = s.Substring(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (changed);
|
||||
return s;
|
||||
}
|
||||
|
||||
/*General-purpose utility function for removing
|
||||
* characters from the front and back of string
|
||||
* @param s The string to process
|
||||
* @param head exact string to strip from head
|
||||
* @param tail exact string to strip from tail
|
||||
* @return The resulting string
|
||||
*/
|
||||
public static string stripFrontBack(string src, string head, string tail)
|
||||
{
|
||||
int h = src.IndexOf(head);
|
||||
int t = src.LastIndexOf(tail);
|
||||
if (h == - 1 || t == - 1)
|
||||
return src;
|
||||
return src.Substring(h + 1, (t) - (h + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
33
src/Spring/Spring.Core/antlr/SupportClass.cs
Normal file
33
src/Spring/Spring.Core/antlr/SupportClass.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
internal class SupportClass
|
||||
{
|
||||
public static int URShift(int number, int bits)
|
||||
{
|
||||
if (number >= 0)
|
||||
return number >> bits;
|
||||
else
|
||||
return (number >> bits) + (2 << ~bits);
|
||||
}
|
||||
|
||||
public static int URShift(int number, long bits)
|
||||
{
|
||||
return URShift(number, (int)bits);
|
||||
}
|
||||
|
||||
public static long URShift(long number, int bits)
|
||||
{
|
||||
if (number >= 0)
|
||||
return number >> bits;
|
||||
else
|
||||
return (number >> bits) + (2L << ~bits);
|
||||
}
|
||||
|
||||
public static long URShift(long number, long bits)
|
||||
{
|
||||
return URShift(number, (int)bits);
|
||||
}
|
||||
}
|
||||
}
|
||||
99
src/Spring/Spring.Core/antlr/Token.cs
Normal file
99
src/Spring/Spring.Core/antlr/Token.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*A token is minimally a token type. Subclasses can add the text matched
|
||||
* for the token and line info.
|
||||
*/
|
||||
|
||||
public class Token : IToken //, ICloneable
|
||||
{
|
||||
// constants
|
||||
public const int MIN_USER_TYPE = 4;
|
||||
public const int NULL_TREE_LOOKAHEAD = 3;
|
||||
public const int INVALID_TYPE = 0;
|
||||
public const int EOF_TYPE = 1;
|
||||
public static readonly int SKIP = - 1;
|
||||
|
||||
// each Token has at least a token type
|
||||
protected int type_;
|
||||
|
||||
// the illegal token object
|
||||
public static Token badToken = new Token(INVALID_TYPE, "<no text>");
|
||||
|
||||
public Token()
|
||||
{
|
||||
type_ = INVALID_TYPE;
|
||||
}
|
||||
public Token(int t)
|
||||
{
|
||||
type_ = t;
|
||||
}
|
||||
public Token(int t, string txt)
|
||||
{
|
||||
type_ = t;
|
||||
setText(txt);
|
||||
}
|
||||
public virtual int getColumn()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public virtual int getLine()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public virtual string getFilename()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual void setFilename(string name)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual string getText()
|
||||
{
|
||||
return "<no text>";
|
||||
}
|
||||
|
||||
public int Type
|
||||
{
|
||||
get { return type_; }
|
||||
set { type_ = value; }
|
||||
}
|
||||
|
||||
public virtual void setType(int newType) { this.Type = newType; }
|
||||
|
||||
public virtual void setColumn(int c)
|
||||
{
|
||||
;
|
||||
}
|
||||
public virtual void setLine(int l)
|
||||
{
|
||||
;
|
||||
}
|
||||
public virtual void setText(string t)
|
||||
{
|
||||
;
|
||||
}
|
||||
override public string ToString()
|
||||
{
|
||||
return "[\"" + getText() + "\",<" + type_ + ">]";
|
||||
}
|
||||
}
|
||||
}
|
||||
146
src/Spring/Spring.Core/antlr/TokenBuffer.cs
Normal file
146
src/Spring/Spring.Core/antlr/TokenBuffer.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*A Stream of Token objects fed to the parser from a Tokenizer that can
|
||||
* be rewound via mark()/rewind() methods.
|
||||
* <p>
|
||||
* A dynamic array is used to buffer up all the input tokens. Normally,
|
||||
* "k" tokens are stored in the buffer. More tokens may be stored during
|
||||
* guess mode (testing syntactic predicate), or when LT(i>k) is referenced.
|
||||
* Consumption of tokens is deferred. In other words, reading the next
|
||||
* token is not done by conume(), but deferred until needed by LA or LT.
|
||||
* <p>
|
||||
*
|
||||
* @see antlr.Token
|
||||
* @see antlr.Tokenizer
|
||||
* @see antlr.TokenQueue
|
||||
*/
|
||||
|
||||
public class TokenBuffer
|
||||
{
|
||||
|
||||
// Token source
|
||||
protected internal TokenStream input;
|
||||
|
||||
// Number of active markers
|
||||
protected internal int nMarkers = 0;
|
||||
|
||||
// Additional offset used when markers are active
|
||||
protected internal int markerOffset = 0;
|
||||
|
||||
// Number of calls to consume() since last LA() or LT() call
|
||||
protected internal int numToConsume = 0;
|
||||
|
||||
// Circular queue
|
||||
internal TokenQueue queue;
|
||||
|
||||
/*Create a token buffer */
|
||||
public TokenBuffer(TokenStream input_)
|
||||
{
|
||||
input = input_;
|
||||
queue = new TokenQueue(1);
|
||||
}
|
||||
|
||||
/*Reset the input buffer to empty state */
|
||||
public virtual void reset()
|
||||
{
|
||||
nMarkers = 0;
|
||||
markerOffset = 0;
|
||||
numToConsume = 0;
|
||||
queue.reset();
|
||||
}
|
||||
|
||||
/*Mark another token for deferred consumption */
|
||||
public virtual void consume()
|
||||
{
|
||||
numToConsume++;
|
||||
}
|
||||
|
||||
/*Ensure that the token buffer is sufficiently full */
|
||||
protected virtual void fill(int amount)
|
||||
{
|
||||
syncConsume();
|
||||
// Fill the buffer sufficiently to hold needed tokens
|
||||
while (queue.nbrEntries < (amount + markerOffset))
|
||||
{
|
||||
// Append the next token
|
||||
queue.append(input.nextToken());
|
||||
}
|
||||
}
|
||||
|
||||
/*return the Tokenizer (needed by ParseView) */
|
||||
public virtual TokenStream getInput()
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
/*Get a lookahead token value */
|
||||
public virtual int LA(int i)
|
||||
{
|
||||
fill(i);
|
||||
return queue.elementAt(markerOffset + i - 1).Type;
|
||||
}
|
||||
|
||||
/*Get a lookahead token */
|
||||
public virtual IToken LT(int i)
|
||||
{
|
||||
fill(i);
|
||||
return queue.elementAt(markerOffset + i - 1);
|
||||
}
|
||||
|
||||
/*Return an integer marker that can be used to rewind the buffer to
|
||||
* its current state.
|
||||
*/
|
||||
public virtual int mark()
|
||||
{
|
||||
syncConsume();
|
||||
nMarkers++;
|
||||
return markerOffset;
|
||||
}
|
||||
|
||||
/*Rewind the token buffer to a marker.
|
||||
* @param mark Marker returned previously from mark()
|
||||
*/
|
||||
public virtual void rewind(int mark)
|
||||
{
|
||||
syncConsume();
|
||||
markerOffset = mark;
|
||||
nMarkers--;
|
||||
}
|
||||
|
||||
/*Sync up deferred consumption */
|
||||
protected virtual void syncConsume()
|
||||
{
|
||||
while (numToConsume > 0)
|
||||
{
|
||||
if (nMarkers > 0)
|
||||
{
|
||||
// guess mode -- leave leading tokens and bump offset.
|
||||
markerOffset++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// normal mode -- remove first token
|
||||
queue.removeFirst();
|
||||
}
|
||||
numToConsume--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
48
src/Spring/Spring.Core/antlr/TokenCreator.cs
Normal file
48
src/Spring/Spring.Core/antlr/TokenCreator.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
namespace antlr
|
||||
{
|
||||
using System;
|
||||
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// A creator of Token object instances.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This class and it's sub-classes exists primarily as an optimization
|
||||
/// of the reflection-based mechanism(s) previously used exclusively to
|
||||
/// create instances of Token objects.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Since Lexers in ANTLR use a single Token type, each TokenCreator can
|
||||
/// create one class of Token objects (that's why it's not called TokenFactory).
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public abstract class TokenCreator
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the fully qualified name of the Token type that this
|
||||
/// class creates.
|
||||
/// </summary>
|
||||
public abstract string TokenTypeName
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a <see cref="Token"/> instance.
|
||||
/// </summary>
|
||||
public abstract IToken Create();
|
||||
}
|
||||
}
|
||||
121
src/Spring/Spring.Core/antlr/TokenQueue.cs
Normal file
121
src/Spring/Spring.Core/antlr/TokenQueue.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*A private circular buffer object used by the token buffer */
|
||||
|
||||
class TokenQueue
|
||||
{
|
||||
/*Physical circular buffer of tokens */
|
||||
private IToken[] buffer;
|
||||
/*buffer.length-1 for quick modulos */
|
||||
private int sizeLessOne;
|
||||
/*physical index of front token */
|
||||
private int offset;
|
||||
/*number of tokens in the queue */
|
||||
protected internal int nbrEntries;
|
||||
|
||||
public TokenQueue(int minSize)
|
||||
{
|
||||
// Find first power of 2 >= to requested size
|
||||
int size;
|
||||
if (minSize < 0)
|
||||
{
|
||||
init(16); // pick some value for them
|
||||
return ;
|
||||
}
|
||||
// check for overflow
|
||||
if (minSize >= (int.MaxValue / 2))
|
||||
{
|
||||
init(int.MaxValue); // wow that's big.
|
||||
return ;
|
||||
}
|
||||
for (size = 2; size < minSize; size *= 2)
|
||||
{
|
||||
;
|
||||
}
|
||||
init(size);
|
||||
}
|
||||
|
||||
/*Add token to end of the queue
|
||||
* @param tok The token to add
|
||||
*/
|
||||
public void append(IToken tok)
|
||||
{
|
||||
if (nbrEntries == buffer.Length)
|
||||
{
|
||||
expand();
|
||||
}
|
||||
buffer[(offset + nbrEntries) & sizeLessOne] = tok;
|
||||
nbrEntries++;
|
||||
}
|
||||
|
||||
/*Fetch a token from the queue by index
|
||||
* @param idx The index of the token to fetch, where zero is the token at the front of the queue
|
||||
*/
|
||||
public IToken elementAt(int idx)
|
||||
{
|
||||
return buffer[(offset + idx) & sizeLessOne];
|
||||
}
|
||||
|
||||
/*Expand the token buffer by doubling its capacity */
|
||||
private void expand()
|
||||
{
|
||||
IToken[] newBuffer = new IToken[buffer.Length * 2];
|
||||
// Copy the contents to the new buffer
|
||||
// Note that this will store the first logical item in the
|
||||
// first physical array element.
|
||||
for (int i = 0; i < buffer.Length; i++)
|
||||
{
|
||||
newBuffer[i] = elementAt(i);
|
||||
}
|
||||
// Re-initialize with new contents, keep old nbrEntries
|
||||
buffer = newBuffer;
|
||||
sizeLessOne = buffer.Length - 1;
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
/*Initialize the queue.
|
||||
* @param size The initial size of the queue
|
||||
*/
|
||||
private void init(int size)
|
||||
{
|
||||
// Allocate buffer
|
||||
buffer = new IToken[size];
|
||||
// Other initialization
|
||||
sizeLessOne = size - 1;
|
||||
offset = 0;
|
||||
nbrEntries = 0;
|
||||
}
|
||||
|
||||
/*Clear the queue. Leaving the previous buffer alone.
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
offset = 0;
|
||||
nbrEntries = 0;
|
||||
}
|
||||
|
||||
/*Remove token from front of queue */
|
||||
public void removeFirst()
|
||||
{
|
||||
offset = (offset + 1) & sizeLessOne;
|
||||
nbrEntries--;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
src/Spring/Spring.Core/antlr/TokenStream.cs
Normal file
26
src/Spring/Spring.Core/antlr/TokenStream.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
public interface TokenStream
|
||||
{
|
||||
IToken nextToken();
|
||||
}
|
||||
|
||||
}
|
||||
56
src/Spring/Spring.Core/antlr/TokenStreamBasicFilter.cs
Normal file
56
src/Spring/Spring.Core/antlr/TokenStreamBasicFilter.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using BitSet = antlr.collections.impl.BitSet;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*This object is a TokenStream that passes through all
|
||||
* tokens except for those that you tell it to discard.
|
||||
* There is no buffering of the tokens.
|
||||
*/
|
||||
public class TokenStreamBasicFilter : TokenStream
|
||||
{
|
||||
/*The set of token types to discard */
|
||||
protected internal BitSet discardMask;
|
||||
|
||||
/*The input stream */
|
||||
protected internal TokenStream input;
|
||||
|
||||
public TokenStreamBasicFilter(TokenStream input)
|
||||
{
|
||||
this.input = input;
|
||||
discardMask = new BitSet();
|
||||
}
|
||||
public virtual void discard(int ttype)
|
||||
{
|
||||
discardMask.add(ttype);
|
||||
}
|
||||
public virtual void discard(BitSet mask)
|
||||
{
|
||||
discardMask = mask;
|
||||
}
|
||||
public virtual IToken nextToken()
|
||||
{
|
||||
IToken tok = input.nextToken();
|
||||
while (tok != null && discardMask.member(tok.Type))
|
||||
{
|
||||
tok = input.nextToken();
|
||||
}
|
||||
return tok;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/Spring/Spring.Core/antlr/TokenStreamException.cs
Normal file
34
src/Spring/Spring.Core/antlr/TokenStreamException.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*
|
||||
* Anything that goes wrong while generating a stream of tokens.
|
||||
*/
|
||||
|
||||
[Serializable]
|
||||
public class TokenStreamException : ANTLRException
|
||||
{
|
||||
public TokenStreamException()
|
||||
{
|
||||
}
|
||||
public TokenStreamException(string s) : base(s)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
179
src/Spring/Spring.Core/antlr/TokenStreamHiddenTokenFilter.cs
Normal file
179
src/Spring/Spring.Core/antlr/TokenStreamHiddenTokenFilter.cs
Normal file
@@ -0,0 +1,179 @@
|
||||
using System;
|
||||
using BitSet = antlr.collections.impl.BitSet;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*This object filters a token stream coming from a lexer
|
||||
* or another TokenStream so that only certain token channels
|
||||
* get transmitted to the parser.
|
||||
*
|
||||
* Any of the channels can be filtered off as "hidden" channels whose
|
||||
* tokens can be accessed from the parser.
|
||||
*/
|
||||
public class TokenStreamHiddenTokenFilter : TokenStreamBasicFilter, TokenStream
|
||||
{
|
||||
// protected BitSet discardMask;
|
||||
protected internal BitSet hideMask;
|
||||
|
||||
private IHiddenStreamToken nextMonitoredToken;
|
||||
|
||||
/*track tail of hidden list emanating from previous
|
||||
* monitored token
|
||||
*/
|
||||
protected internal IHiddenStreamToken lastHiddenToken;
|
||||
|
||||
protected internal IHiddenStreamToken firstHidden = null;
|
||||
|
||||
public TokenStreamHiddenTokenFilter(TokenStream input) : base(input)
|
||||
{
|
||||
hideMask = new BitSet();
|
||||
}
|
||||
protected internal virtual void consume()
|
||||
{
|
||||
nextMonitoredToken = (IHiddenStreamToken) input.nextToken();
|
||||
}
|
||||
private void consumeFirst()
|
||||
{
|
||||
consume(); // get first token of input stream
|
||||
|
||||
// Handle situation where hidden or discarded tokens
|
||||
// appear first in input stream
|
||||
IHiddenStreamToken p = null;
|
||||
// while hidden or discarded scarf tokens
|
||||
while (hideMask.member(LA(1).Type) || discardMask.member(LA(1).Type))
|
||||
{
|
||||
if (hideMask.member(LA(1).Type))
|
||||
{
|
||||
if (p == null)
|
||||
{
|
||||
p = LA(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
p.setHiddenAfter(LA(1));
|
||||
LA(1).setHiddenBefore(p); // double-link
|
||||
p = LA(1);
|
||||
}
|
||||
lastHiddenToken = p;
|
||||
if (firstHidden == null)
|
||||
{
|
||||
firstHidden = p; // record hidden token if first
|
||||
}
|
||||
}
|
||||
consume();
|
||||
}
|
||||
}
|
||||
public virtual BitSet getDiscardMask()
|
||||
{
|
||||
return discardMask;
|
||||
}
|
||||
/*Return a ptr to the hidden token appearing immediately after
|
||||
* token t in the input stream.
|
||||
*/
|
||||
public virtual IHiddenStreamToken getHiddenAfter(IHiddenStreamToken t)
|
||||
{
|
||||
return t.getHiddenAfter();
|
||||
}
|
||||
/*Return a ptr to the hidden token appearing immediately before
|
||||
* token t in the input stream.
|
||||
*/
|
||||
public virtual IHiddenStreamToken getHiddenBefore(IHiddenStreamToken t)
|
||||
{
|
||||
return t.getHiddenBefore();
|
||||
}
|
||||
public virtual BitSet getHideMask()
|
||||
{
|
||||
return hideMask;
|
||||
}
|
||||
/*Return the first hidden token if one appears
|
||||
* before any monitored token.
|
||||
*/
|
||||
public virtual IHiddenStreamToken getInitialHiddenToken()
|
||||
{
|
||||
return firstHidden;
|
||||
}
|
||||
public virtual void hide(int m)
|
||||
{
|
||||
hideMask.add(m);
|
||||
}
|
||||
public virtual void hide(BitSet mask)
|
||||
{
|
||||
hideMask = mask;
|
||||
}
|
||||
protected internal virtual IHiddenStreamToken LA(int i)
|
||||
{
|
||||
return nextMonitoredToken;
|
||||
}
|
||||
/*Return the next monitored token.
|
||||
* Test the token following the monitored token.
|
||||
* If following is another monitored token, save it
|
||||
* for the next invocation of nextToken (like a single
|
||||
* lookahead token) and return it then.
|
||||
* If following is unmonitored, nondiscarded (hidden)
|
||||
* channel token, add it to the monitored token.
|
||||
*
|
||||
* Note: EOF must be a monitored Token.
|
||||
*/
|
||||
override public IToken nextToken()
|
||||
{
|
||||
// handle an initial condition; don't want to get lookahead
|
||||
// token of this splitter until first call to nextToken
|
||||
if (LA(1) == null)
|
||||
{
|
||||
consumeFirst();
|
||||
}
|
||||
|
||||
// we always consume hidden tokens after monitored, thus,
|
||||
// upon entry LA(1) is a monitored token.
|
||||
IHiddenStreamToken monitored = LA(1);
|
||||
// point to hidden tokens found during last invocation
|
||||
monitored.setHiddenBefore(lastHiddenToken);
|
||||
lastHiddenToken = null;
|
||||
|
||||
// Look for hidden tokens, hook them into list emanating
|
||||
// from the monitored tokens.
|
||||
consume();
|
||||
IHiddenStreamToken p = monitored;
|
||||
// while hidden or discarded scarf tokens
|
||||
while (hideMask.member(LA(1).Type) || discardMask.member(LA(1).Type))
|
||||
{
|
||||
if (hideMask.member(LA(1).Type))
|
||||
{
|
||||
// attach the hidden token to the monitored in a chain
|
||||
// link forwards
|
||||
p.setHiddenAfter(LA(1));
|
||||
// link backwards
|
||||
if (p != monitored)
|
||||
{
|
||||
//hidden cannot point to monitored tokens
|
||||
LA(1).setHiddenBefore(p);
|
||||
}
|
||||
p = (lastHiddenToken = LA(1));
|
||||
}
|
||||
consume();
|
||||
}
|
||||
return monitored;
|
||||
}
|
||||
public virtual void resetState()
|
||||
{
|
||||
firstHidden = null;
|
||||
lastHiddenToken = null;
|
||||
nextMonitoredToken = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/Spring/Spring.Core/antlr/TokenStreamIOException.cs
Normal file
37
src/Spring/Spring.Core/antlr/TokenStreamIOException.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using IOException = System.IO.IOException;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*
|
||||
* Wraps an IOException in a TokenStreamException
|
||||
*/
|
||||
[Serializable]
|
||||
public class TokenStreamIOException : TokenStreamException
|
||||
{
|
||||
public IOException io;
|
||||
/*
|
||||
* TokenStreamIOException constructor comment.
|
||||
* @param s java.lang.String
|
||||
*/
|
||||
public TokenStreamIOException(IOException io) : base(io.Message)
|
||||
{
|
||||
this.io = io;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*
|
||||
* Wraps a RecognitionException in a TokenStreamException so you
|
||||
* can pass it along.
|
||||
*/
|
||||
|
||||
[Serializable]
|
||||
public class TokenStreamRecognitionException : TokenStreamException
|
||||
{
|
||||
public RecognitionException recog;
|
||||
|
||||
public TokenStreamRecognitionException(RecognitionException re) :
|
||||
base(re.Message)
|
||||
{
|
||||
this.recog = re;
|
||||
}
|
||||
|
||||
override public string ToString()
|
||||
{
|
||||
return recog.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/Spring/Spring.Core/antlr/TokenStreamRetryException.cs
Normal file
31
src/Spring/Spring.Core/antlr/TokenStreamRetryException.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*
|
||||
* Aborted recognition of current token. Try to get one again.
|
||||
* Used by TokenStreamSelector.retry() to force nextToken()
|
||||
* of stream to re-enter and retry.
|
||||
*/
|
||||
|
||||
[Serializable]
|
||||
public class TokenStreamRetryException : TokenStreamException
|
||||
{
|
||||
public TokenStreamRetryException() {}
|
||||
}
|
||||
}
|
||||
552
src/Spring/Spring.Core/antlr/TokenStreamRewriteEngine.cs
Normal file
552
src/Spring/Spring.Core/antlr/TokenStreamRewriteEngine.cs
Normal file
@@ -0,0 +1,552 @@
|
||||
namespace antlr
|
||||
{
|
||||
/* ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
|
||||
using System;
|
||||
using IList = System.Collections.IList;
|
||||
using IDictionary = System.Collections.IDictionary;
|
||||
using ArrayList = System.Collections.ArrayList;
|
||||
using Hashtable = System.Collections.Hashtable;
|
||||
using IComparer = System.Collections.IComparer;
|
||||
using StringBuilder = System.Text.StringBuilder;
|
||||
using BitSet = antlr.collections.impl.BitSet;
|
||||
|
||||
/// <summary>
|
||||
/// This token stream tracks the *entire* token stream coming from
|
||||
/// a lexer, but does not pass on the whitespace (or whatever else
|
||||
/// you want to discard) to the parser.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This class can then be asked for the ith token in the input stream.
|
||||
/// Useful for dumping out the input stream exactly after doing some
|
||||
/// augmentation or other manipulations. Tokens are index from 0..n-1
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// You can insert stuff, replace, and delete chunks. Note that the
|
||||
/// operations are done lazily--only if you convert the buffer to a
|
||||
/// string. This is very efficient because you are not moving data around
|
||||
/// all the time. As the buffer of tokens is converted to strings, the
|
||||
/// toString() method(s) check to see if there is an operation at the
|
||||
/// current index. If so, the operation is done and then normal string
|
||||
/// rendering continues on the buffer. This is like having multiple Turing
|
||||
/// machine instruction streams (programs) operating on a single input tape. :)
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Since the operations are done lazily at toString-time, operations do not
|
||||
/// screw up the token index values. That is, an insert operation at token
|
||||
/// index i does not change the index values for tokens i+1..n-1.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Because operations never actually alter the buffer, you may always get
|
||||
/// the original token stream back without undoing anything. Since
|
||||
/// the instructions are queued up, you can easily simulate transactions and
|
||||
/// roll back any changes if there is an error just by removing instructions.
|
||||
/// For example,
|
||||
/// </para>
|
||||
/// <example>For example:
|
||||
/// <code>
|
||||
/// TokenStreamRewriteEngine rewriteEngine = new TokenStreamRewriteEngine(lexer);
|
||||
/// JavaRecognizer parser = new JavaRecognizer(rewriteEngine);
|
||||
/// ...
|
||||
/// rewriteEngine.insertAfter("pass1", t, "foobar");}
|
||||
/// rewriteEngine.insertAfter("pass2", u, "start");}
|
||||
/// System.Console.Out.WriteLine(rewriteEngine.ToString("pass1"));
|
||||
/// System.Console.Out.WriteLine(rewriteEngine.ToString("pass2"));
|
||||
/// </code>
|
||||
/// </example>
|
||||
/// <para>
|
||||
/// You can also have multiple "instruction streams" and get multiple
|
||||
/// rewrites from a single pass over the input. Just name the instruction
|
||||
/// streams and use that name again when printing the buffer. This could be
|
||||
/// useful for generating a C file and also its header file--all from the
|
||||
/// same buffer.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If you don't use named rewrite streams, a "default" stream is used.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Terence Parr, parrt@cs.usfca.edu
|
||||
/// University of San Francisco
|
||||
/// February 2004
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public class TokenStreamRewriteEngine : TokenStream
|
||||
{
|
||||
public const int MIN_TOKEN_INDEX = 0;
|
||||
|
||||
protected class RewriteOperation
|
||||
{
|
||||
protected internal int index;
|
||||
protected internal string text;
|
||||
|
||||
protected RewriteOperation(int index, string text)
|
||||
{
|
||||
this.index = index;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute the rewrite operation by possibly adding to the buffer.
|
||||
/// </summary>
|
||||
/// <param name="buf">rewrite buffer</param>
|
||||
/// <returns>The index of the next token to operate on.</returns>
|
||||
public virtual int execute(StringBuilder buf)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
protected class InsertBeforeOp : RewriteOperation
|
||||
{
|
||||
public InsertBeforeOp(int index, string text) : base(index, text)
|
||||
{
|
||||
}
|
||||
|
||||
public override int execute(StringBuilder buf)
|
||||
{
|
||||
buf.Append(text);
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
protected class ReplaceOp : RewriteOperation
|
||||
{
|
||||
protected int lastIndex;
|
||||
|
||||
public ReplaceOp(int from, int to, string text) : base(from, text)
|
||||
{
|
||||
lastIndex = to;
|
||||
}
|
||||
|
||||
public override int execute(StringBuilder buf)
|
||||
{
|
||||
if ( text != null )
|
||||
{
|
||||
buf.Append(text);
|
||||
}
|
||||
return lastIndex+1;
|
||||
}
|
||||
}
|
||||
|
||||
protected class DeleteOp : ReplaceOp
|
||||
{
|
||||
public DeleteOp(int from, int to) : base(from, to, null)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public const string DEFAULT_PROGRAM_NAME = "default";
|
||||
public const int PROGRAM_INIT_SIZE = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Track the incoming list of tokens
|
||||
/// </summary>
|
||||
protected IList tokens;
|
||||
|
||||
/// <summary>
|
||||
/// You may have multiple, named streams of rewrite operations.
|
||||
/// I'm calling these things "programs."
|
||||
/// Maps string (name) -> rewrite (List)
|
||||
/// </summary>
|
||||
protected IDictionary programs = null;
|
||||
|
||||
/// <summary>
|
||||
/// Map string (program name) -> Integer index
|
||||
/// </summary>
|
||||
protected IDictionary lastRewriteTokenIndexes = null;
|
||||
|
||||
/// <summary>
|
||||
/// track index of tokens
|
||||
/// </summary>
|
||||
protected int index = MIN_TOKEN_INDEX;
|
||||
|
||||
/// <summary>
|
||||
/// Who do we suck tokens from?
|
||||
/// </summary>
|
||||
protected TokenStream stream;
|
||||
|
||||
/// <summary>
|
||||
/// Which (whitespace) token(s) to throw out
|
||||
/// </summary>
|
||||
protected BitSet discardMask = new BitSet();
|
||||
|
||||
public TokenStreamRewriteEngine(TokenStream upstream) : this(upstream, 1000)
|
||||
{
|
||||
}
|
||||
|
||||
public TokenStreamRewriteEngine(TokenStream upstream, int initialSize)
|
||||
{
|
||||
stream = upstream;
|
||||
tokens = new ArrayList(initialSize);
|
||||
programs = new Hashtable();
|
||||
programs[DEFAULT_PROGRAM_NAME] = new ArrayList(PROGRAM_INIT_SIZE);
|
||||
lastRewriteTokenIndexes = new Hashtable();
|
||||
}
|
||||
|
||||
public IToken nextToken() // throws TokenStreamException
|
||||
{
|
||||
TokenWithIndex t;
|
||||
|
||||
// suck tokens until end of stream or we find a non-discarded token
|
||||
do
|
||||
{
|
||||
t = (TokenWithIndex) stream.nextToken();
|
||||
if ( t != null )
|
||||
{
|
||||
t.setIndex(index); // what is t's index in list?
|
||||
if ( t.Type != Token.EOF_TYPE )
|
||||
{
|
||||
tokens.Add(t); // track all tokens except EOF
|
||||
}
|
||||
index++; // move to next position
|
||||
}
|
||||
} while ( (t != null) && (discardMask.member(t.Type)) );
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
public void rollback(int instructionIndex)
|
||||
{
|
||||
rollback(DEFAULT_PROGRAM_NAME, instructionIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rollback the instruction stream for a program so that
|
||||
/// the indicated instruction (via instructionIndex) is no
|
||||
/// longer in the stream.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// UNTESTED!
|
||||
/// </remarks>
|
||||
/// <param name="programName"></param>
|
||||
/// <param name="instructionIndex"></param>
|
||||
public void rollback(string programName, int instructionIndex)
|
||||
{
|
||||
ArrayList il = (ArrayList) programs[programName];
|
||||
if ( il != null )
|
||||
{
|
||||
programs[programName] = il.GetRange(MIN_TOKEN_INDEX, (instructionIndex - MIN_TOKEN_INDEX));
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteProgram()
|
||||
{
|
||||
deleteProgram(DEFAULT_PROGRAM_NAME);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the program so that no instructions exist
|
||||
/// </summary>
|
||||
/// <param name="programName"></param>
|
||||
public void deleteProgram(string programName)
|
||||
{
|
||||
rollback(programName, MIN_TOKEN_INDEX);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If op.index > lastRewriteTokenIndexes, just add to the end.
|
||||
/// Otherwise, do linear
|
||||
/// </summary>
|
||||
/// <param name="op"></param>
|
||||
protected void addToSortedRewriteList(RewriteOperation op)
|
||||
{
|
||||
addToSortedRewriteList(DEFAULT_PROGRAM_NAME, op);
|
||||
}
|
||||
|
||||
protected void addToSortedRewriteList(string programName, RewriteOperation op)
|
||||
{
|
||||
ArrayList rewrites = (ArrayList) getProgram(programName);
|
||||
// if at or beyond last op's index, just append
|
||||
if ( op.index >= getLastRewriteTokenIndex(programName) )
|
||||
{
|
||||
rewrites.Add(op); // append to list of operations
|
||||
// record the index of this operation for next time through
|
||||
setLastRewriteTokenIndex(programName, op.index);
|
||||
return;
|
||||
}
|
||||
// not after the last one, so must insert to ordered list
|
||||
int pos = rewrites.BinarySearch(op, RewriteOperationComparer.Default);
|
||||
if (pos < 0)
|
||||
{
|
||||
rewrites.Insert(-pos-1, op);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertAfter(IToken t, string text)
|
||||
{
|
||||
insertAfter(DEFAULT_PROGRAM_NAME, t, text);
|
||||
}
|
||||
|
||||
public void insertAfter(int index, string text)
|
||||
{
|
||||
insertAfter(DEFAULT_PROGRAM_NAME, index, text);
|
||||
}
|
||||
|
||||
public void insertAfter(string programName, IToken t, string text)
|
||||
{
|
||||
insertAfter(programName,((TokenWithIndex) t).getIndex(), text);
|
||||
}
|
||||
|
||||
public void insertAfter(string programName, int index, string text)
|
||||
{
|
||||
// to insert after, just insert before next index (even if past end)
|
||||
insertBefore(programName, index+1, text);
|
||||
}
|
||||
|
||||
public void insertBefore(IToken t, string text)
|
||||
{
|
||||
insertBefore(DEFAULT_PROGRAM_NAME, t, text);
|
||||
}
|
||||
|
||||
public void insertBefore(int index, string text)
|
||||
{
|
||||
insertBefore(DEFAULT_PROGRAM_NAME, index, text);
|
||||
}
|
||||
|
||||
public void insertBefore(string programName, IToken t, string text)
|
||||
{
|
||||
insertBefore(programName, ((TokenWithIndex) t).getIndex(), text);
|
||||
}
|
||||
|
||||
public void insertBefore(string programName, int index, string text)
|
||||
{
|
||||
addToSortedRewriteList(programName, new InsertBeforeOp(index, text));
|
||||
}
|
||||
|
||||
public void replace(int index, string text)
|
||||
{
|
||||
replace(DEFAULT_PROGRAM_NAME, index, index, text);
|
||||
}
|
||||
|
||||
public void replace(int from, int to, string text)
|
||||
{
|
||||
replace(DEFAULT_PROGRAM_NAME, from, to, text);
|
||||
}
|
||||
|
||||
public void replace(IToken indexT, string text)
|
||||
{
|
||||
replace(DEFAULT_PROGRAM_NAME, indexT, indexT, text);
|
||||
}
|
||||
|
||||
public void replace(IToken from, IToken to, string text)
|
||||
{
|
||||
replace(DEFAULT_PROGRAM_NAME, from, to, text);
|
||||
}
|
||||
|
||||
public void replace(string programName, int from, int to, string text)
|
||||
{
|
||||
addToSortedRewriteList(new ReplaceOp(from, to, text));
|
||||
}
|
||||
|
||||
public void replace(string programName, IToken from, IToken to, string text)
|
||||
{
|
||||
replace(programName,
|
||||
((TokenWithIndex) from).getIndex(),
|
||||
((TokenWithIndex) to).getIndex(),
|
||||
text);
|
||||
}
|
||||
|
||||
public void delete(int index)
|
||||
{
|
||||
delete(DEFAULT_PROGRAM_NAME, index, index);
|
||||
}
|
||||
|
||||
public void delete(int from, int to)
|
||||
{
|
||||
delete(DEFAULT_PROGRAM_NAME, from, to);
|
||||
}
|
||||
|
||||
public void delete(IToken indexT)
|
||||
{
|
||||
delete(DEFAULT_PROGRAM_NAME, indexT, indexT);
|
||||
}
|
||||
|
||||
public void delete(IToken from, IToken to)
|
||||
{
|
||||
delete(DEFAULT_PROGRAM_NAME, from, to);
|
||||
}
|
||||
|
||||
public void delete(string programName, int from, int to)
|
||||
{
|
||||
replace(programName, from, to, null);
|
||||
}
|
||||
|
||||
public void delete(string programName, IToken from, IToken to)
|
||||
{
|
||||
replace(programName, from, to, null);
|
||||
}
|
||||
|
||||
public void discard(int ttype)
|
||||
{
|
||||
discardMask.add(ttype);
|
||||
}
|
||||
|
||||
public TokenWithIndex getToken(int i)
|
||||
{
|
||||
return (TokenWithIndex) tokens[i];
|
||||
}
|
||||
|
||||
public int getTokenStreamSize()
|
||||
{
|
||||
return tokens.Count;
|
||||
}
|
||||
|
||||
public string ToOriginalString()
|
||||
{
|
||||
return ToOriginalString(MIN_TOKEN_INDEX, getTokenStreamSize()-1);
|
||||
}
|
||||
|
||||
public string ToOriginalString(int start, int end)
|
||||
{
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (int i = start; (i >= MIN_TOKEN_INDEX) && (i <= end) && (i < tokens.Count); i++)
|
||||
{
|
||||
buf.Append(getToken(i).getText());
|
||||
}
|
||||
return buf.ToString();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ToString(MIN_TOKEN_INDEX, getTokenStreamSize());
|
||||
}
|
||||
|
||||
public string ToString(string programName)
|
||||
{
|
||||
return ToString(programName, MIN_TOKEN_INDEX, getTokenStreamSize());
|
||||
}
|
||||
|
||||
public string ToString(int start, int end)
|
||||
{
|
||||
return ToString(DEFAULT_PROGRAM_NAME, start, end);
|
||||
}
|
||||
|
||||
public string ToString(string programName, int start, int end)
|
||||
{
|
||||
IList rewrites = (IList) programs[programName];
|
||||
if (rewrites == null)
|
||||
{
|
||||
return null; // invalid program
|
||||
}
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
// Index of first rewrite we have not done
|
||||
int rewriteOpIndex = 0;
|
||||
|
||||
int tokenCursor = start;
|
||||
while ( (tokenCursor >= MIN_TOKEN_INDEX) &&
|
||||
(tokenCursor <= end) &&
|
||||
(tokenCursor < tokens.Count) )
|
||||
{
|
||||
if (rewriteOpIndex < rewrites.Count)
|
||||
{
|
||||
RewriteOperation op = (RewriteOperation) rewrites[rewriteOpIndex];
|
||||
while ( (tokenCursor == op.index) && (rewriteOpIndex < rewrites.Count) )
|
||||
{
|
||||
/*
|
||||
Console.Out.WriteLine("execute op "+rewriteOpIndex+
|
||||
" (type "+op.GetType().FullName+")"
|
||||
+" at index "+op.index);
|
||||
*/
|
||||
tokenCursor = op.execute(buf);
|
||||
rewriteOpIndex++;
|
||||
if (rewriteOpIndex < rewrites.Count)
|
||||
{
|
||||
op = (RewriteOperation) rewrites[rewriteOpIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( tokenCursor < end )
|
||||
{
|
||||
buf.Append(getToken(tokenCursor).getText());
|
||||
tokenCursor++;
|
||||
}
|
||||
}
|
||||
// now see if there are operations (append) beyond last token index
|
||||
for (int opi = rewriteOpIndex; opi < rewrites.Count; opi++)
|
||||
{
|
||||
RewriteOperation op = (RewriteOperation) rewrites[opi];
|
||||
op.execute(buf); // must be insertions if after last token
|
||||
}
|
||||
|
||||
return buf.ToString();
|
||||
}
|
||||
|
||||
public string ToDebugString()
|
||||
{
|
||||
return ToDebugString(MIN_TOKEN_INDEX, getTokenStreamSize());
|
||||
}
|
||||
|
||||
public string ToDebugString(int start, int end)
|
||||
{
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (int i = start; (i >= MIN_TOKEN_INDEX) && (i <= end) && (i < tokens.Count); i++)
|
||||
{
|
||||
buf.Append(getToken(i));
|
||||
}
|
||||
return buf.ToString();
|
||||
}
|
||||
|
||||
public int getLastRewriteTokenIndex()
|
||||
{
|
||||
return getLastRewriteTokenIndex(DEFAULT_PROGRAM_NAME);
|
||||
}
|
||||
|
||||
protected int getLastRewriteTokenIndex(string programName)
|
||||
{
|
||||
object i = lastRewriteTokenIndexes[programName];
|
||||
if (i == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return (int) i;
|
||||
}
|
||||
|
||||
protected void setLastRewriteTokenIndex(string programName, int i)
|
||||
{
|
||||
lastRewriteTokenIndexes[programName] = (object) i;
|
||||
}
|
||||
|
||||
protected IList getProgram(string name)
|
||||
{
|
||||
IList il = (IList) programs[name];
|
||||
if ( il == null )
|
||||
{
|
||||
il = initializeProgram(name);
|
||||
}
|
||||
return il;
|
||||
}
|
||||
|
||||
private IList initializeProgram(string name)
|
||||
{
|
||||
IList il = new ArrayList(PROGRAM_INIT_SIZE);
|
||||
programs[name] = il;
|
||||
return il;
|
||||
}
|
||||
|
||||
public class RewriteOperationComparer : IComparer
|
||||
{
|
||||
public static readonly RewriteOperationComparer Default = new RewriteOperationComparer();
|
||||
|
||||
public virtual int Compare(object o1, object o2)
|
||||
{
|
||||
RewriteOperation rop1 = (RewriteOperation) o1;
|
||||
RewriteOperation rop2 = (RewriteOperation) o2;
|
||||
|
||||
if (rop1.index < rop2.index) return -1;
|
||||
if (rop1.index > rop2.index) return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
126
src/Spring/Spring.Core/antlr/TokenStreamSelector.cs
Normal file
126
src/Spring/Spring.Core/antlr/TokenStreamSelector.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using Hashtable = System.Collections.Hashtable;
|
||||
using Stack = System.Collections.Stack;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*A token stream MUX (multiplexor) knows about n token streams
|
||||
* and can multiplex them onto the same channel for use by token
|
||||
* stream consumer like a parser. This is a way to have multiple
|
||||
* lexers break up the same input stream for a single parser.
|
||||
* Or, you can have multiple instances of the same lexer handle
|
||||
* multiple input streams; this works great for includes.
|
||||
*/
|
||||
public class TokenStreamSelector : TokenStream
|
||||
{
|
||||
/*The set of inputs to the MUX */
|
||||
protected internal Hashtable inputStreamNames;
|
||||
|
||||
/*The currently-selected token stream input */
|
||||
protected internal TokenStream input;
|
||||
|
||||
/*Used to track stack of input streams */
|
||||
protected internal Stack streamStack = new Stack();
|
||||
|
||||
public TokenStreamSelector() : base()
|
||||
{
|
||||
inputStreamNames = new Hashtable();
|
||||
}
|
||||
public virtual void addInputStream(TokenStream stream, string key)
|
||||
{
|
||||
inputStreamNames[key] = stream;
|
||||
}
|
||||
/*Return the stream from tokens are being pulled at
|
||||
* the moment.
|
||||
*/
|
||||
public virtual TokenStream getCurrentStream()
|
||||
{
|
||||
return input;
|
||||
}
|
||||
public virtual TokenStream getStream(string sname)
|
||||
{
|
||||
TokenStream stream = (TokenStream) inputStreamNames[sname];
|
||||
if (stream == null)
|
||||
{
|
||||
throw new System.ArgumentException("TokenStream " + sname + " not found");
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
public virtual IToken nextToken()
|
||||
{
|
||||
// return input.nextToken();
|
||||
// keep looking for a token until you don't
|
||||
// get a retry exception.
|
||||
for (; ; )
|
||||
{
|
||||
try
|
||||
{
|
||||
return input.nextToken();
|
||||
}
|
||||
catch (TokenStreamRetryException)
|
||||
{
|
||||
// just retry "forever"
|
||||
}
|
||||
}
|
||||
}
|
||||
public virtual TokenStream pop()
|
||||
{
|
||||
TokenStream stream = (TokenStream) streamStack.Pop();
|
||||
select(stream);
|
||||
return stream;
|
||||
}
|
||||
public virtual void push(TokenStream stream)
|
||||
{
|
||||
streamStack.Push(input); // save current stream
|
||||
select(stream);
|
||||
}
|
||||
public virtual void push(string sname)
|
||||
{
|
||||
streamStack.Push(input);
|
||||
select(sname);
|
||||
}
|
||||
/*Abort recognition of current Token and try again.
|
||||
* A stream can push a new stream (for include files
|
||||
* for example, and then retry(), which will cause
|
||||
* the current stream to abort back to this.nextToken().
|
||||
* this.nextToken() then asks for a token from the
|
||||
* current stream, which is the new "substream."
|
||||
*/
|
||||
public virtual void retry()
|
||||
{
|
||||
throw new TokenStreamRetryException();
|
||||
}
|
||||
/*Set the stream without pushing old stream */
|
||||
public virtual void select(TokenStream stream)
|
||||
{
|
||||
input = stream;
|
||||
if (input is CharScanner)
|
||||
{
|
||||
((CharScanner) input).refresh();
|
||||
}
|
||||
}
|
||||
public virtual void select(string sname)
|
||||
{
|
||||
input = getStream(sname);
|
||||
if (input is CharScanner)
|
||||
{
|
||||
((CharScanner) input).refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
51
src/Spring/Spring.Core/antlr/TokenWithIndex.cs
Normal file
51
src/Spring/Spring.Core/antlr/TokenWithIndex.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
namespace antlr
|
||||
{
|
||||
/* ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// This token tracks it's own index 0..n-1 relative to the beginning
|
||||
/// of the stream. It is designed to work with
|
||||
/// <see cref="TokenStreamRewriteEngine"/> in TokenStreamRewriteEngine.cs
|
||||
/// </summary>
|
||||
public class TokenWithIndex : CommonToken
|
||||
{
|
||||
/// <summary>
|
||||
/// Index into token array indicating position in input stream
|
||||
/// </summary>
|
||||
int index;
|
||||
|
||||
public TokenWithIndex() : base()
|
||||
{
|
||||
}
|
||||
|
||||
public TokenWithIndex(int i, string t) : base(i, t)
|
||||
{
|
||||
}
|
||||
|
||||
public void setIndex(int i)
|
||||
{
|
||||
index = i;
|
||||
}
|
||||
|
||||
public int getIndex()
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "["+index+":\"" + getText() + "\",<" + Type + ">,line=" + line + ",col=" + col + "]\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
178
src/Spring/Spring.Core/antlr/TreeParser.cs
Normal file
178
src/Spring/Spring.Core/antlr/TreeParser.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using AST = antlr.collections.AST;
|
||||
using BitSet = antlr.collections.impl.BitSet;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
public class TreeParser
|
||||
{
|
||||
/*The AST Null object; the parsing cursor is set to this when
|
||||
* it is found to be null. This way, we can test the
|
||||
* token type of a node without having to have tests for null
|
||||
* everywhere.
|
||||
*/
|
||||
public static ASTNULLType ASTNULL = new ASTNULLType();
|
||||
|
||||
/*Where did this rule leave off parsing; avoids a return parameter */
|
||||
protected internal AST retTree_;
|
||||
|
||||
/*guessing nesting level; guessing==0 implies not guessing */
|
||||
// protected int guessing = 0;
|
||||
|
||||
/*Nesting level of registered handlers */
|
||||
// protected int exceptionLevel = 0;
|
||||
|
||||
protected internal TreeParserSharedInputState inputState;
|
||||
|
||||
/*Table of token type to token names */
|
||||
protected internal string[] tokenNames;
|
||||
|
||||
/*AST return value for a rule is squirreled away here */
|
||||
protected internal AST returnAST;
|
||||
|
||||
/*AST support code; parser and treeparser delegate to this object */
|
||||
protected internal ASTFactory astFactory = new ASTFactory();
|
||||
|
||||
/*Used to keep track of indentdepth for traceIn/Out */
|
||||
protected internal int traceDepth = 0;
|
||||
|
||||
public TreeParser()
|
||||
{
|
||||
inputState = new TreeParserSharedInputState();
|
||||
}
|
||||
/*Get the AST return value squirreled away in the parser */
|
||||
public virtual AST getAST()
|
||||
{
|
||||
return returnAST;
|
||||
}
|
||||
public virtual ASTFactory getASTFactory()
|
||||
{
|
||||
return astFactory;
|
||||
}
|
||||
public virtual void resetState()
|
||||
{
|
||||
traceDepth = 0;
|
||||
returnAST = null;
|
||||
retTree_ = null;
|
||||
inputState.reset();
|
||||
}
|
||||
public virtual string getTokenName(int num)
|
||||
{
|
||||
return tokenNames[num];
|
||||
}
|
||||
public virtual string[] getTokenNames()
|
||||
{
|
||||
return tokenNames;
|
||||
}
|
||||
protected internal virtual void match(AST t, int ttype)
|
||||
{
|
||||
//System.out.println("match("+ttype+"); cursor is "+t);
|
||||
if (t == null || t == ASTNULL || t.Type != ttype)
|
||||
{
|
||||
throw new MismatchedTokenException(getTokenNames(), t, ttype, false);
|
||||
}
|
||||
}
|
||||
/*Make sure current lookahead symbol matches the given set
|
||||
* Throw an exception upon mismatch, which is catch by either the
|
||||
* error handler or by the syntactic predicate.
|
||||
*/
|
||||
public virtual void match(AST t, BitSet b)
|
||||
{
|
||||
if (t == null || t == ASTNULL || !b.member(t.Type))
|
||||
{
|
||||
throw new MismatchedTokenException(getTokenNames(), t, b, false);
|
||||
}
|
||||
}
|
||||
protected internal virtual void matchNot(AST t, int ttype)
|
||||
{
|
||||
//System.out.println("match("+ttype+"); cursor is "+t);
|
||||
if (t == null || t == ASTNULL || t.Type == ttype)
|
||||
{
|
||||
throw new MismatchedTokenException(getTokenNames(), t, ttype, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// @deprecated as of 2.7.2. This method calls System.exit() and writes
|
||||
/// directly to stderr, which is usually not appropriate when
|
||||
/// a parser is embedded into a larger application. Since the method is
|
||||
/// <code>static</code>, it cannot be overridden to avoid these problems.
|
||||
/// ANTLR no longer uses this method internally or in generated code.
|
||||
/// </summary>
|
||||
///
|
||||
[Obsolete("De-activated since version 2.7.2.6 as it cannot be overidden.", true)]
|
||||
public static void panic()
|
||||
{
|
||||
Console.Error.WriteLine("TreeWalker: panic");
|
||||
System.Environment.Exit(1);
|
||||
}
|
||||
/*Parser error-reporting function can be overridden in subclass */
|
||||
public virtual void reportError(RecognitionException ex)
|
||||
{
|
||||
Console.Error.WriteLine(ex.ToString());
|
||||
}
|
||||
/*Parser error-reporting function can be overridden in subclass */
|
||||
public virtual void reportError(string s)
|
||||
{
|
||||
Console.Error.WriteLine("error: " + s);
|
||||
}
|
||||
/*Parser warning-reporting function can be overridden in subclass */
|
||||
public virtual void reportWarning(string s)
|
||||
{
|
||||
Console.Error.WriteLine("warning: " + s);
|
||||
}
|
||||
/*Specify an object with support code (shared by
|
||||
* Parser and TreeParser. Normally, the programmer
|
||||
* does not play with this, using setASTNodeType instead.
|
||||
*/
|
||||
public virtual void setASTFactory(ASTFactory f)
|
||||
{
|
||||
astFactory = f;
|
||||
}
|
||||
|
||||
/*Specify the type of node to create during tree building */
|
||||
public virtual void setASTNodeType(string nodeType)
|
||||
{
|
||||
setASTNodeClass(nodeType);
|
||||
}
|
||||
|
||||
/*Specify the type of node to create during tree building */
|
||||
public virtual void setASTNodeClass(string nodeType)
|
||||
{
|
||||
astFactory.setASTNodeType(nodeType);
|
||||
}
|
||||
|
||||
public virtual void traceIndent()
|
||||
{
|
||||
for (int i = 0; i < traceDepth; i++)
|
||||
Console.Out.Write(" ");
|
||||
}
|
||||
public virtual void traceIn(string rname, AST t)
|
||||
{
|
||||
traceDepth += 1;
|
||||
traceIndent();
|
||||
Console.Out.WriteLine("> " + rname + "(" + ((t != null) ? t.ToString() : "null") + ")" + ((inputState.guessing > 0) ? " [guessing]" : ""));
|
||||
}
|
||||
public virtual void traceOut(string rname, AST t)
|
||||
{
|
||||
traceIndent();
|
||||
Console.Out.WriteLine("< " + rname + "(" + ((t != null) ? t.ToString() : "null") + ")" + ((inputState.guessing > 0) ? " [guessing]" : ""));
|
||||
traceDepth--;
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/Spring/Spring.Core/antlr/TreeParserSharedInputState.cs
Normal file
37
src/Spring/Spring.Core/antlr/TreeParserSharedInputState.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace antlr
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*This object contains the data associated with an
|
||||
* input AST. Multiple parsers
|
||||
* share a single TreeParserSharedInputState to parse
|
||||
* the same tree or to have the parser walk multiple
|
||||
* trees.
|
||||
*/
|
||||
|
||||
public class TreeParserSharedInputState
|
||||
{
|
||||
/*Are we guessing (guessing>0)? */
|
||||
public int guessing = 0;
|
||||
|
||||
public virtual void reset()
|
||||
{
|
||||
guessing = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
89
src/Spring/Spring.Core/antlr/collections/AST.cs
Normal file
89
src/Spring/Spring.Core/antlr/collections/AST.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using IEnumerator = System.Collections.IEnumerator;
|
||||
|
||||
using IToken = antlr.IToken;
|
||||
|
||||
namespace antlr.collections
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// Minimal AST node interface used by ANTLR AST generation and tree-walker.
|
||||
/// </summary>
|
||||
public interface AST : ICloneable
|
||||
{
|
||||
/// <summary>
|
||||
/// Add a (rightmost) child to this node
|
||||
/// </summary>
|
||||
/// <param name="c"></param>
|
||||
void addChild(AST c);
|
||||
bool Equals(AST t);
|
||||
bool EqualsList(AST t);
|
||||
bool EqualsListPartial(AST t);
|
||||
bool EqualsTree(AST t);
|
||||
bool EqualsTreePartial(AST t);
|
||||
IEnumerator findAll(AST tree);
|
||||
IEnumerator findAllPartial(AST subtree);
|
||||
/// <summary>
|
||||
/// Get the first child of this node; null if no children
|
||||
/// </summary>
|
||||
AST getFirstChild();
|
||||
/// <summary>
|
||||
/// Get the next sibling in line after this one
|
||||
/// </summary>
|
||||
AST getNextSibling();
|
||||
/// <summary>
|
||||
/// Get the token text for this node
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string getText();
|
||||
/// <summary>
|
||||
/// Get the token type for this node
|
||||
/// </summary>
|
||||
int Type { get; set;}
|
||||
/// <summary>
|
||||
/// Get number of children of this node; if leaf, returns 0
|
||||
/// </summary>
|
||||
/// <returns>Number of children</returns>
|
||||
int getNumberOfChildren();
|
||||
void initialize(int t, string txt);
|
||||
void initialize(AST t);
|
||||
void initialize(IToken t);
|
||||
/// <summary>
|
||||
/// Set the first child of a node.
|
||||
/// </summary>
|
||||
/// <param name="c"></param>
|
||||
void setFirstChild(AST c);
|
||||
/// <summary>
|
||||
/// Set the next sibling after this one.
|
||||
/// </summary>
|
||||
/// <param name="n"></param>
|
||||
void setNextSibling(AST n);
|
||||
/// <summary>
|
||||
/// Set the token text for this node
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
void setText(string text);
|
||||
/// <summary>
|
||||
/// Set the token type for this node
|
||||
/// </summary>
|
||||
/// <param name="ttype"></param>
|
||||
void setType(int ttype);
|
||||
string ToString();
|
||||
string ToStringList();
|
||||
string ToStringTree();
|
||||
}
|
||||
}
|
||||
42
src/Spring/Spring.Core/antlr/collections/impl/ASTArray.cs
Normal file
42
src/Spring/Spring.Core/antlr/collections/impl/ASTArray.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using AST = antlr.collections.AST;
|
||||
|
||||
namespace antlr.collections.impl
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*ASTArray is a class that allows ANTLR to
|
||||
* generate code that can create and initialize an array
|
||||
* in one expression, like:
|
||||
* (new ASTArray(3)).add(x).add(y).add(z)
|
||||
*/
|
||||
public class ASTArray
|
||||
{
|
||||
public int size = 0;
|
||||
public AST[] array;
|
||||
|
||||
|
||||
public ASTArray(int capacity)
|
||||
{
|
||||
array = new AST[capacity];
|
||||
}
|
||||
public virtual ASTArray add(AST node)
|
||||
{
|
||||
array[size++] = node;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
539
src/Spring/Spring.Core/antlr/collections/impl/BitSet.cs
Normal file
539
src/Spring/Spring.Core/antlr/collections/impl/BitSet.cs
Normal file
@@ -0,0 +1,539 @@
|
||||
using System;
|
||||
using ArrayList = System.Collections.ArrayList;
|
||||
|
||||
//using CharFormatter = antlr.CharFormatter;
|
||||
|
||||
namespace antlr.collections.impl
|
||||
{
|
||||
/*ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
// With many thanks to Eric V. Smith from the ANTLR list.
|
||||
//
|
||||
|
||||
/*A BitSet to replace java.util.BitSet.
|
||||
* Primary differences are that most set operators return new sets
|
||||
* as opposed to oring and anding "in place". Further, a number of
|
||||
* operations were added. I cannot contain a BitSet because there
|
||||
* is no way to access the internal bits (which I need for speed)
|
||||
* and, because it is final, I cannot subclass to add functionality.
|
||||
* Consider defining set degree. Without access to the bits, I must
|
||||
* call a method n times to test the ith bit...ack!
|
||||
*
|
||||
* Also seems like or() from util is wrong when size of incoming set is bigger
|
||||
* than this.bits.length.
|
||||
*
|
||||
* @author Terence Parr
|
||||
* @author <br><a href="mailto:pete@yamuna.demon.co.uk">Pete Wells</a>
|
||||
*/
|
||||
|
||||
public class BitSet : ICloneable
|
||||
{
|
||||
protected internal const int BITS = 64; // number of bits / long
|
||||
protected internal const int NIBBLE = 4;
|
||||
protected internal const int LOG_BITS = 6; // 2^6 == 64
|
||||
|
||||
/*We will often need to do a mod operator (i mod nbits). Its
|
||||
* turns out that, for powers of two, this mod operation is
|
||||
* same as (i & (nbits-1)). Since mod is slow, we use a
|
||||
* precomputed mod mask to do the mod instead.
|
||||
*/
|
||||
protected internal static readonly int MOD_MASK = BITS - 1;
|
||||
|
||||
/*The actual data bits */
|
||||
protected internal long[] dataBits;
|
||||
|
||||
/*Construct a bitset of size one word (64 bits) */
|
||||
public BitSet() : this(BITS)
|
||||
{
|
||||
}
|
||||
|
||||
/*Construction from a static array of longs */
|
||||
public BitSet(long[] bits_)
|
||||
{
|
||||
dataBits = bits_;
|
||||
}
|
||||
|
||||
/*Construct a bitset given the size
|
||||
* @param nbits The size of the bitset in bits
|
||||
*/
|
||||
public BitSet(int nbits)
|
||||
{
|
||||
dataBits = new long[((nbits - 1) >> LOG_BITS) + 1];
|
||||
}
|
||||
|
||||
/*or this element into this set (grow as necessary to accommodate) */
|
||||
public virtual void add(int el)
|
||||
{
|
||||
int n = wordNumber(el);
|
||||
if (n >= dataBits.Length)
|
||||
{
|
||||
growToInclude(el);
|
||||
}
|
||||
dataBits[n] |= bitMask(el);
|
||||
}
|
||||
|
||||
public virtual BitSet and(BitSet a)
|
||||
{
|
||||
BitSet s = (BitSet) this.Clone();
|
||||
s.andInPlace(a);
|
||||
return s;
|
||||
}
|
||||
|
||||
public virtual void andInPlace(BitSet a)
|
||||
{
|
||||
int min = (int) (Math.Min(dataBits.Length, a.dataBits.Length));
|
||||
for (int i = min - 1; i >= 0; i--)
|
||||
{
|
||||
dataBits[i] &= a.dataBits[i];
|
||||
}
|
||||
// clear all bits in this not present in a (if this bigger than a).
|
||||
for (int i = min; i < dataBits.Length; i++)
|
||||
{
|
||||
dataBits[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static long bitMask(int bitNumber)
|
||||
{
|
||||
int bitPosition = bitNumber & MOD_MASK; // bitNumber mod BITS
|
||||
return 1L << bitPosition;
|
||||
}
|
||||
|
||||
public virtual void clear()
|
||||
{
|
||||
for (int i = dataBits.Length - 1; i >= 0; i--)
|
||||
{
|
||||
dataBits[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void clear(int el)
|
||||
{
|
||||
int n = wordNumber(el);
|
||||
if (n >= dataBits.Length)
|
||||
{
|
||||
// grow as necessary to accommodate
|
||||
growToInclude(el);
|
||||
}
|
||||
dataBits[n] &= ~ bitMask(el);
|
||||
}
|
||||
|
||||
public virtual object Clone()
|
||||
{
|
||||
BitSet s;
|
||||
try
|
||||
{
|
||||
s = new BitSet();
|
||||
s.dataBits = new long[dataBits.Length];
|
||||
Array.Copy(dataBits, 0, s.dataBits, 0, dataBits.Length);
|
||||
}
|
||||
catch //(System.Exception e)
|
||||
{
|
||||
throw new System.ApplicationException();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public virtual int degree()
|
||||
{
|
||||
int deg = 0;
|
||||
for (int i = dataBits.Length - 1; i >= 0; i--)
|
||||
{
|
||||
long word = dataBits[i];
|
||||
if (word != 0L)
|
||||
{
|
||||
for (int bit = BITS - 1; bit >= 0; bit--)
|
||||
{
|
||||
if ((word & (1L << bit)) != 0)
|
||||
{
|
||||
deg++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return deg;
|
||||
}
|
||||
|
||||
override public int GetHashCode()
|
||||
{
|
||||
return dataBits.GetHashCode();
|
||||
}
|
||||
|
||||
/*code "inherited" from java.util.BitSet */
|
||||
override public bool Equals(object obj)
|
||||
{
|
||||
if ((obj != null) && (obj is BitSet))
|
||||
{
|
||||
BitSet bset = (BitSet) obj;
|
||||
|
||||
int n = (int) (System.Math.Min(dataBits.Length, bset.dataBits.Length));
|
||||
for (int i = n; i-- > 0; )
|
||||
{
|
||||
if (dataBits[i] != bset.dataBits[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (dataBits.Length > n)
|
||||
{
|
||||
for (int i = (int) (dataBits.Length); i-- > n; )
|
||||
{
|
||||
if (dataBits[i] != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (bset.dataBits.Length > n)
|
||||
{
|
||||
for (int i = (int) (bset.dataBits.Length); i-- > n; )
|
||||
{
|
||||
if (bset.dataBits[i] != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Grows the set to a larger number of bits.
|
||||
* @param bit element that must fit in set
|
||||
*/
|
||||
public virtual void growToInclude(int bit)
|
||||
{
|
||||
int newSize = (int) (System.Math.Max(dataBits.Length << 1, numWordsToHold(bit)));
|
||||
long[] newbits = new long[newSize];
|
||||
Array.Copy(dataBits, 0, newbits, 0, dataBits.Length);
|
||||
dataBits = newbits;
|
||||
}
|
||||
|
||||
public virtual bool member(int el)
|
||||
{
|
||||
int n = wordNumber(el);
|
||||
if (n >= dataBits.Length)
|
||||
return false;
|
||||
return (dataBits[n] & bitMask(el)) != 0;
|
||||
}
|
||||
|
||||
public virtual bool nil()
|
||||
{
|
||||
for (int i = dataBits.Length - 1; i >= 0; i--)
|
||||
{
|
||||
if (dataBits[i] != 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual BitSet not()
|
||||
{
|
||||
BitSet s = (BitSet) this.Clone();
|
||||
s.notInPlace();
|
||||
return s;
|
||||
}
|
||||
|
||||
public virtual void notInPlace()
|
||||
{
|
||||
for (int i = dataBits.Length - 1; i >= 0; i--)
|
||||
{
|
||||
dataBits[i] = ~ dataBits[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*complement bits in the range 0..maxBit. */
|
||||
public virtual void notInPlace(int maxBit)
|
||||
{
|
||||
notInPlace(0, maxBit);
|
||||
}
|
||||
|
||||
/*complement bits in the range minBit..maxBit.*/
|
||||
public virtual void notInPlace(int minBit, int maxBit)
|
||||
{
|
||||
// make sure that we have room for maxBit
|
||||
growToInclude(maxBit);
|
||||
for (int i = minBit; i <= maxBit; i++)
|
||||
{
|
||||
int n = wordNumber(i);
|
||||
dataBits[n] ^= bitMask(i);
|
||||
}
|
||||
}
|
||||
|
||||
private int numWordsToHold(int el)
|
||||
{
|
||||
return (el >> LOG_BITS) + 1;
|
||||
}
|
||||
|
||||
public static BitSet of(int el)
|
||||
{
|
||||
BitSet s = new BitSet(el + 1);
|
||||
s.add(el);
|
||||
return s;
|
||||
}
|
||||
|
||||
/*return this | a in a new set */
|
||||
public virtual BitSet or(BitSet a)
|
||||
{
|
||||
BitSet s = (BitSet) this.Clone();
|
||||
s.orInPlace(a);
|
||||
return s;
|
||||
}
|
||||
|
||||
public virtual void orInPlace(BitSet a)
|
||||
{
|
||||
// If this is smaller than a, grow this first
|
||||
if (a.dataBits.Length > dataBits.Length)
|
||||
{
|
||||
setSize((int) (a.dataBits.Length));
|
||||
}
|
||||
int min = (int) (System.Math.Min(dataBits.Length, a.dataBits.Length));
|
||||
for (int i = min - 1; i >= 0; i--)
|
||||
{
|
||||
dataBits[i] |= a.dataBits[i];
|
||||
}
|
||||
}
|
||||
|
||||
// remove this element from this set
|
||||
public virtual void remove(int el)
|
||||
{
|
||||
int n = wordNumber(el);
|
||||
if (n >= dataBits.Length)
|
||||
{
|
||||
growToInclude(el);
|
||||
}
|
||||
dataBits[n] &= ~ bitMask(el);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the size of a set.
|
||||
* @param nwords how many words the new set should be
|
||||
*/
|
||||
private void setSize(int nwords)
|
||||
{
|
||||
long[] newbits = new long[nwords];
|
||||
int n = (int) (System.Math.Min(nwords, dataBits.Length));
|
||||
Array.Copy(dataBits, 0, newbits, 0, n);
|
||||
dataBits = newbits;
|
||||
}
|
||||
|
||||
public virtual int size()
|
||||
{
|
||||
return dataBits.Length << LOG_BITS; // num words * bits per word
|
||||
}
|
||||
|
||||
/*return how much space is being used by the dataBits array not
|
||||
* how many actually have member bits on.
|
||||
*/
|
||||
public virtual int lengthInLongWords()
|
||||
{
|
||||
return dataBits.Length;
|
||||
}
|
||||
|
||||
/*Is this contained within a? */
|
||||
public virtual bool subset(BitSet a)
|
||||
{
|
||||
if (a == null) //(a == null || !(a is BitSet))
|
||||
return false;
|
||||
return this.and(a).Equals(this);
|
||||
}
|
||||
|
||||
/*Subtract the elements of 'a' from 'this' in-place.
|
||||
* Basically, just turn off all bits of 'this' that are in 'a'.
|
||||
*/
|
||||
public virtual void subtractInPlace(BitSet a)
|
||||
{
|
||||
if (a == null)
|
||||
return ;
|
||||
// for all words of 'a', turn off corresponding bits of 'this'
|
||||
for (int i = 0; i < dataBits.Length && i < a.dataBits.Length; i++)
|
||||
{
|
||||
dataBits[i] &= ~ a.dataBits[i];
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int[] toArray()
|
||||
{
|
||||
int[] elems = new int[degree()];
|
||||
int en = 0;
|
||||
for (int i = 0; i < (dataBits.Length << LOG_BITS); i++)
|
||||
{
|
||||
if (member(i))
|
||||
{
|
||||
elems[en++] = i;
|
||||
}
|
||||
}
|
||||
return elems;
|
||||
}
|
||||
|
||||
public virtual long[] toPackedArray()
|
||||
{
|
||||
return dataBits;
|
||||
}
|
||||
|
||||
override public string ToString()
|
||||
{
|
||||
return ToString(",");
|
||||
}
|
||||
|
||||
/*Transform a bit set into a string by formatting each element as an integer
|
||||
* @separator The string to put in between elements
|
||||
* @return A commma-separated list of values
|
||||
*/
|
||||
public virtual string ToString(string separator)
|
||||
{
|
||||
string str = "";
|
||||
for (int i = 0; i < (dataBits.Length << LOG_BITS); i++)
|
||||
{
|
||||
if (member(i))
|
||||
{
|
||||
if (str.Length > 0)
|
||||
{
|
||||
str += separator;
|
||||
}
|
||||
str = str + i;
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/*Create a string representation where instead of integer elements, the
|
||||
* ith element of vocabulary is displayed instead. Vocabulary is a Vector
|
||||
* of Strings.
|
||||
* @separator The string to put in between elements
|
||||
* @return A commma-separated list of character constants.
|
||||
*/
|
||||
public virtual string ToString(string separator, ArrayList vocabulary)
|
||||
{
|
||||
if (vocabulary == null)
|
||||
{
|
||||
return ToString(separator);
|
||||
}
|
||||
string str = "";
|
||||
for (int i = 0; i < (dataBits.Length << LOG_BITS); i++)
|
||||
{
|
||||
if (member(i))
|
||||
{
|
||||
if (str.Length > 0)
|
||||
{
|
||||
str += separator;
|
||||
}
|
||||
if (i >= vocabulary.Count)
|
||||
{
|
||||
str += "<bad element " + i + ">";
|
||||
}
|
||||
else if (vocabulary[i] == null)
|
||||
{
|
||||
str += "<" + i + ">";
|
||||
}
|
||||
else
|
||||
{
|
||||
str += (string) vocabulary[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump a comma-separated list of the words making up the bit set.
|
||||
* Split each 64 bit number into two more manageable 32 bit numbers.
|
||||
* This generates a comma-separated list of C++-like unsigned long constants.
|
||||
*/
|
||||
public virtual string toStringOfHalfWords()
|
||||
{
|
||||
string s = new string("".ToCharArray());
|
||||
for (int i = 0; i < dataBits.Length; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
s += ", ";
|
||||
long tmp = dataBits[i];
|
||||
tmp &= 0xFFFFFFFFL;
|
||||
s += (tmp + "UL");
|
||||
s += ", ";
|
||||
tmp = SupportClass.URShift(dataBits[i], 32);
|
||||
tmp &= 0xFFFFFFFFL;
|
||||
s += (tmp + "UL");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump a comma-separated list of the words making up the bit set.
|
||||
* This generates a comma-separated list of Java-like long int constants.
|
||||
*/
|
||||
public virtual string toStringOfWords()
|
||||
{
|
||||
string s = new string("".ToCharArray());
|
||||
for (int i = 0; i < dataBits.Length; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
s += ", ";
|
||||
s += (dataBits[i] + "L");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/*Print out the bit set but collapse char ranges. */
|
||||
/* public virtual string toStringWithRanges(string separator, CharFormatter formatter)
|
||||
{
|
||||
string str = "";
|
||||
int[] elems = this.toArray();
|
||||
if (elems.Length == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
// look for ranges
|
||||
int i = 0;
|
||||
while (i < elems.Length)
|
||||
{
|
||||
int lastInRange;
|
||||
lastInRange = 0;
|
||||
for (int j = i + 1; j < elems.Length; j++)
|
||||
{
|
||||
if (elems[j] != elems[j - 1] + 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
lastInRange = j;
|
||||
}
|
||||
// found a range
|
||||
if (str.Length > 0)
|
||||
{
|
||||
str += separator;
|
||||
}
|
||||
if (lastInRange - i >= 2)
|
||||
{
|
||||
str += formatter.literalChar(elems[i]);
|
||||
str += "..";
|
||||
str += formatter.literalChar(elems[lastInRange]);
|
||||
i = lastInRange; // skip past end of range for next range
|
||||
}
|
||||
else
|
||||
{
|
||||
// no range, just print current char and move on
|
||||
str += formatter.literalChar(elems[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
*/
|
||||
private static int wordNumber(int bit)
|
||||
{
|
||||
return bit >> LOG_BITS; // bit / BITS
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/Spring/Spring.Core/antlr/debug/ANTLREventArgs.cs
Normal file
37
src/Spring/Spring.Core/antlr/debug/ANTLREventArgs.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public abstract class ANTLREventArgs : EventArgs
|
||||
{
|
||||
public ANTLREventArgs()
|
||||
{
|
||||
}
|
||||
public ANTLREventArgs(int type)
|
||||
{
|
||||
this.Type = type;
|
||||
}
|
||||
|
||||
public virtual int Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.type_;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.type_ = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal void setValues(int type)
|
||||
{
|
||||
this.Type = type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event type.
|
||||
/// </summary>
|
||||
private int type_;
|
||||
}
|
||||
}
|
||||
322
src/Spring/Spring.Core/antlr/debug/DebuggingCharScanner.cs
Normal file
322
src/Spring/Spring.Core/antlr/debug/DebuggingCharScanner.cs
Normal file
@@ -0,0 +1,322 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
using System.Threading;
|
||||
using antlr;
|
||||
|
||||
using BitSet = antlr.collections.impl.BitSet;
|
||||
|
||||
public abstract class DebuggingCharScanner : CharScanner, DebuggingParser
|
||||
{
|
||||
private void InitBlock()
|
||||
{
|
||||
eventSupport = new ScannerEventSupport(this);
|
||||
}
|
||||
public virtual void setDebugMode(bool mode)
|
||||
{
|
||||
_notDebugMode = !mode;
|
||||
}
|
||||
|
||||
private ScannerEventSupport eventSupport;
|
||||
private bool _notDebugMode = false;
|
||||
protected internal string[] ruleNames;
|
||||
protected internal string[] semPredNames;
|
||||
|
||||
|
||||
public DebuggingCharScanner(InputBuffer cb) : base(cb)
|
||||
{
|
||||
InitBlock();
|
||||
}
|
||||
public DebuggingCharScanner(LexerSharedInputState state) : base(state)
|
||||
{
|
||||
InitBlock();
|
||||
}
|
||||
public virtual void addMessageListener(MessageListener l)
|
||||
{
|
||||
eventSupport.addMessageListener(l);
|
||||
}
|
||||
public virtual void addNewLineListener(NewLineListener l)
|
||||
{
|
||||
eventSupport.addNewLineListener(l);
|
||||
}
|
||||
public virtual void addParserListener(ParserListener l)
|
||||
{
|
||||
eventSupport.addParserListener(l);
|
||||
}
|
||||
public virtual void addParserMatchListener(ParserMatchListener l)
|
||||
{
|
||||
eventSupport.addParserMatchListener(l);
|
||||
}
|
||||
public virtual void addParserTokenListener(ParserTokenListener l)
|
||||
{
|
||||
eventSupport.addParserTokenListener(l);
|
||||
}
|
||||
public virtual void addSemanticPredicateListener(SemanticPredicateListener l)
|
||||
{
|
||||
eventSupport.addSemanticPredicateListener(l);
|
||||
}
|
||||
public virtual void addSyntacticPredicateListener(SyntacticPredicateListener l)
|
||||
{
|
||||
eventSupport.addSyntacticPredicateListener(l);
|
||||
}
|
||||
public virtual void addTraceListener(TraceListener l)
|
||||
{
|
||||
eventSupport.addTraceListener(l);
|
||||
}
|
||||
public override void consume()
|
||||
{
|
||||
int la_1 = - 99;
|
||||
try
|
||||
{
|
||||
la_1 = LA(1);
|
||||
}
|
||||
catch (CharStreamException)
|
||||
{
|
||||
}
|
||||
base.consume();
|
||||
eventSupport.fireConsume(la_1);
|
||||
}
|
||||
protected internal virtual void fireEnterRule(int num, int data)
|
||||
{
|
||||
if (isDebugMode())
|
||||
eventSupport.fireEnterRule(num, inputState.guessing, data);
|
||||
}
|
||||
protected internal virtual void fireExitRule(int num, int ttype)
|
||||
{
|
||||
if (isDebugMode())
|
||||
eventSupport.fireExitRule(num, inputState.guessing, ttype);
|
||||
}
|
||||
protected internal virtual bool fireSemanticPredicateEvaluated(int type, int num, bool condition)
|
||||
{
|
||||
if (isDebugMode())
|
||||
return eventSupport.fireSemanticPredicateEvaluated(type, num, condition, inputState.guessing);
|
||||
else
|
||||
return condition;
|
||||
}
|
||||
protected internal virtual void fireSyntacticPredicateFailed()
|
||||
{
|
||||
if (isDebugMode())
|
||||
eventSupport.fireSyntacticPredicateFailed(inputState.guessing);
|
||||
}
|
||||
protected internal virtual void fireSyntacticPredicateStarted()
|
||||
{
|
||||
if (isDebugMode())
|
||||
eventSupport.fireSyntacticPredicateStarted(inputState.guessing);
|
||||
}
|
||||
protected internal virtual void fireSyntacticPredicateSucceeded()
|
||||
{
|
||||
if (isDebugMode())
|
||||
eventSupport.fireSyntacticPredicateSucceeded(inputState.guessing);
|
||||
}
|
||||
public virtual string getRuleName(int num)
|
||||
{
|
||||
return ruleNames[num];
|
||||
}
|
||||
public virtual string getSemPredName(int num)
|
||||
{
|
||||
return semPredNames[num];
|
||||
}
|
||||
public virtual void goToSleep()
|
||||
{
|
||||
lock(this)
|
||||
{
|
||||
try
|
||||
{
|
||||
Monitor.Wait(this);
|
||||
}
|
||||
catch (System.Threading.ThreadInterruptedException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
public virtual bool isDebugMode()
|
||||
{
|
||||
return !_notDebugMode;
|
||||
}
|
||||
public override char LA(int i)
|
||||
{
|
||||
char la = base.LA(i);
|
||||
eventSupport.fireLA(i, la);
|
||||
return la;
|
||||
}
|
||||
protected internal override IToken makeToken(int t)
|
||||
{
|
||||
// do something with char buffer???
|
||||
// try {
|
||||
// IToken tok = (Token)tokenObjectClass.newInstance();
|
||||
// tok.setType(t);
|
||||
// // tok.setText(getText()); done in generated lexer now
|
||||
// tok.setLine(line);
|
||||
// return tok;
|
||||
// }
|
||||
// catch (InstantiationException ie) {
|
||||
// panic("can't instantiate a Token");
|
||||
// }
|
||||
// catch (IllegalAccessException iae) {
|
||||
// panic("Token class is not accessible");
|
||||
// }
|
||||
return base.makeToken(t);
|
||||
}
|
||||
public override void match(int c)
|
||||
{
|
||||
char la_1 = LA(1);
|
||||
try
|
||||
{
|
||||
base.match(c);
|
||||
eventSupport.fireMatch(Convert.ToChar(c), inputState.guessing);
|
||||
}
|
||||
catch (MismatchedCharException e)
|
||||
{
|
||||
if (inputState.guessing == 0)
|
||||
eventSupport.fireMismatch(la_1, Convert.ToChar(c), inputState.guessing);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
public override void match(BitSet b)
|
||||
{
|
||||
string text = this.text.ToString();
|
||||
char la_1 = LA(1);
|
||||
try
|
||||
{
|
||||
base.match(b);
|
||||
eventSupport.fireMatch(la_1, b, text, inputState.guessing);
|
||||
}
|
||||
catch (MismatchedCharException e)
|
||||
{
|
||||
if (inputState.guessing == 0)
|
||||
eventSupport.fireMismatch(la_1, b, text, inputState.guessing);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
public override void match(string s)
|
||||
{
|
||||
System.Text.StringBuilder la_s = new System.Text.StringBuilder("");
|
||||
int len = s.Length;
|
||||
// peek at the next len worth of characters
|
||||
try
|
||||
{
|
||||
for (int i = 1; i <= len; i++)
|
||||
{
|
||||
la_s.Append(base.LA(i));
|
||||
}
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
base.match(s);
|
||||
eventSupport.fireMatch(s, inputState.guessing);
|
||||
}
|
||||
catch (MismatchedCharException e)
|
||||
{
|
||||
if (inputState.guessing == 0)
|
||||
eventSupport.fireMismatch(la_s.ToString(), s, inputState.guessing);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
public override void matchNot(int c)
|
||||
{
|
||||
char la_1 = LA(1);
|
||||
try
|
||||
{
|
||||
base.matchNot(c);
|
||||
eventSupport.fireMatchNot(la_1, Convert.ToChar(c), inputState.guessing);
|
||||
}
|
||||
catch (MismatchedCharException e)
|
||||
{
|
||||
if (inputState.guessing == 0)
|
||||
eventSupport.fireMismatchNot(la_1, Convert.ToChar(c), inputState.guessing);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
public override void matchRange(int c1, int c2)
|
||||
{
|
||||
char la_1 = LA(1);
|
||||
try
|
||||
{
|
||||
base.matchRange(c1, c2);
|
||||
eventSupport.fireMatch(la_1, "" + c1 + c2, inputState.guessing);
|
||||
}
|
||||
catch (MismatchedCharException e)
|
||||
{
|
||||
if (inputState.guessing == 0)
|
||||
eventSupport.fireMismatch(la_1, "" + c1 + c2, inputState.guessing);
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
public override void newline()
|
||||
{
|
||||
base.newline();
|
||||
eventSupport.fireNewLine(getLine());
|
||||
}
|
||||
public virtual void removeMessageListener(MessageListener l)
|
||||
{
|
||||
eventSupport.removeMessageListener(l);
|
||||
}
|
||||
public virtual void removeNewLineListener(NewLineListener l)
|
||||
{
|
||||
eventSupport.removeNewLineListener(l);
|
||||
}
|
||||
public virtual void removeParserListener(ParserListener l)
|
||||
{
|
||||
eventSupport.removeParserListener(l);
|
||||
}
|
||||
public virtual void removeParserMatchListener(ParserMatchListener l)
|
||||
{
|
||||
eventSupport.removeParserMatchListener(l);
|
||||
}
|
||||
public virtual void removeParserTokenListener(ParserTokenListener l)
|
||||
{
|
||||
eventSupport.removeParserTokenListener(l);
|
||||
}
|
||||
public virtual void removeSemanticPredicateListener(SemanticPredicateListener l)
|
||||
{
|
||||
eventSupport.removeSemanticPredicateListener(l);
|
||||
}
|
||||
public virtual void removeSyntacticPredicateListener(SyntacticPredicateListener l)
|
||||
{
|
||||
eventSupport.removeSyntacticPredicateListener(l);
|
||||
}
|
||||
public virtual void removeTraceListener(TraceListener l)
|
||||
{
|
||||
eventSupport.removeTraceListener(l);
|
||||
}
|
||||
/// <summary>Report exception errors caught in nextToken()
|
||||
/// </summary>
|
||||
public virtual void reportError(MismatchedCharException e)
|
||||
{
|
||||
eventSupport.fireReportError(e);
|
||||
base.reportError(e);
|
||||
}
|
||||
/// <summary>Parser error-reporting function can be overridden in subclass
|
||||
/// </summary>
|
||||
public override void reportError(string s)
|
||||
{
|
||||
eventSupport.fireReportError(s);
|
||||
base.reportError(s);
|
||||
}
|
||||
/// <summary>Parser warning-reporting function can be overridden in subclass
|
||||
/// </summary>
|
||||
public override void reportWarning(string s)
|
||||
{
|
||||
eventSupport.fireReportWarning(s);
|
||||
base.reportWarning(s);
|
||||
}
|
||||
public virtual void setupDebugging()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void wakeUp()
|
||||
{
|
||||
lock(this)
|
||||
{
|
||||
Monitor.Pulse(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
82
src/Spring/Spring.Core/antlr/debug/DebuggingInputBuffer.cs
Normal file
82
src/Spring/Spring.Core/antlr/debug/DebuggingInputBuffer.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
using ArrayList = System.Collections.ArrayList;
|
||||
|
||||
public class DebuggingInputBuffer : InputBuffer
|
||||
{
|
||||
public virtual ArrayList InputBufferListeners
|
||||
{
|
||||
get { return inputBufferEventSupport.InputBufferListeners; }
|
||||
}
|
||||
public virtual bool DebugMode
|
||||
{
|
||||
set { debugMode = value; }
|
||||
}
|
||||
|
||||
private InputBuffer buffer;
|
||||
private InputBufferEventSupport inputBufferEventSupport;
|
||||
private bool debugMode = true;
|
||||
|
||||
|
||||
public DebuggingInputBuffer(InputBuffer buffer)
|
||||
{
|
||||
this.buffer = buffer;
|
||||
inputBufferEventSupport = new InputBufferEventSupport(this);
|
||||
}
|
||||
public virtual void addInputBufferListener(InputBufferListener l)
|
||||
{
|
||||
inputBufferEventSupport.addInputBufferListener(l);
|
||||
}
|
||||
public override char consume()
|
||||
{
|
||||
char la = ' ';
|
||||
try
|
||||
{
|
||||
la = buffer.LA(1);
|
||||
}
|
||||
catch (CharStreamException)
|
||||
{
|
||||
} // vaporize it...
|
||||
buffer.consume();
|
||||
if (debugMode)
|
||||
inputBufferEventSupport.fireConsume(la);
|
||||
return la;
|
||||
}
|
||||
public override void fill(int a)
|
||||
{
|
||||
buffer.fill(a);
|
||||
}
|
||||
public virtual bool isDebugMode()
|
||||
{
|
||||
return debugMode;
|
||||
}
|
||||
public override bool isMarked()
|
||||
{
|
||||
return buffer.isMarked();
|
||||
}
|
||||
public override char LA(int i)
|
||||
{
|
||||
char la = buffer.LA(i);
|
||||
if (debugMode)
|
||||
inputBufferEventSupport.fireLA(la, i);
|
||||
return la;
|
||||
}
|
||||
public override int mark()
|
||||
{
|
||||
int m = buffer.mark();
|
||||
inputBufferEventSupport.fireMark(m);
|
||||
return m;
|
||||
}
|
||||
public virtual void removeInputBufferListener(InputBufferListener l)
|
||||
{
|
||||
if (inputBufferEventSupport != null)
|
||||
inputBufferEventSupport.removeInputBufferListener(l);
|
||||
}
|
||||
public override void rewind(int mark)
|
||||
{
|
||||
buffer.rewind(mark);
|
||||
inputBufferEventSupport.fireRewind(mark);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/Spring/Spring.Core/antlr/debug/DebuggingParser.cs
Normal file
12
src/Spring/Spring.Core/antlr/debug/DebuggingParser.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary> This type was created in VisualAge.
|
||||
/// </summary>
|
||||
public interface DebuggingParser
|
||||
{
|
||||
string getRuleName(int n);
|
||||
string getSemPredName(int n);
|
||||
}
|
||||
}
|
||||
31
src/Spring/Spring.Core/antlr/debug/GuessingEventArgs.cs
Normal file
31
src/Spring/Spring.Core/antlr/debug/GuessingEventArgs.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public abstract class GuessingEventArgs : ANTLREventArgs
|
||||
{
|
||||
public GuessingEventArgs()
|
||||
{
|
||||
}
|
||||
public GuessingEventArgs(int type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual int Guessing
|
||||
{
|
||||
get { return guessing_; }
|
||||
set { this.guessing_ = value; }
|
||||
}
|
||||
|
||||
private int guessing_;
|
||||
|
||||
|
||||
/// <summary>This should NOT be called from anyone other than ParserEventSupport!
|
||||
/// </summary>
|
||||
public virtual void setValues(int type, int guessing)
|
||||
{
|
||||
setValues(type);
|
||||
this.Guessing = guessing;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface ICharScannerDebugSubject : IDebugSubject
|
||||
{
|
||||
event NewLineEventHandler HitNewLine;
|
||||
event MatchEventHandler MatchedChar;
|
||||
event MatchEventHandler MatchedNotChar;
|
||||
event MatchEventHandler MisMatchedChar;
|
||||
event MatchEventHandler MisMatchedNotChar;
|
||||
event TokenEventHandler ConsumedChar;
|
||||
event TokenEventHandler CharLA;
|
||||
}
|
||||
}
|
||||
23
src/Spring/Spring.Core/antlr/debug/IDebugSubject.cs
Normal file
23
src/Spring/Spring.Core/antlr/debug/IDebugSubject.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
//using EventHandlerList = System.ComponentModel.EventHandlerList;
|
||||
|
||||
public interface IDebugSubject
|
||||
{
|
||||
/* EventHandlerList Events
|
||||
{
|
||||
get;
|
||||
}
|
||||
*/
|
||||
event TraceEventHandler EnterRule;
|
||||
event TraceEventHandler ExitRule;
|
||||
event TraceEventHandler Done;
|
||||
event MessageEventHandler ErrorReported;
|
||||
event MessageEventHandler WarningReported;
|
||||
event SemanticPredicateEventHandler SemPredEvaluated;
|
||||
event SyntacticPredicateEventHandler SynPredStarted;
|
||||
event SyntacticPredicateEventHandler SynPredFailed;
|
||||
event SyntacticPredicateEventHandler SynPredSucceeded;
|
||||
}
|
||||
}
|
||||
14
src/Spring/Spring.Core/antlr/debug/IParserDebugSubject.cs
Normal file
14
src/Spring/Spring.Core/antlr/debug/IParserDebugSubject.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface IParserDebugSubject : IDebugSubject
|
||||
{
|
||||
event MatchEventHandler MatchedToken;
|
||||
event MatchEventHandler MatchedNotToken;
|
||||
event MatchEventHandler MisMatchedToken;
|
||||
event MatchEventHandler MisMatchedNotToken;
|
||||
event TokenEventHandler ConsumedToken;
|
||||
event TokenEventHandler TokenLA;
|
||||
}
|
||||
}
|
||||
50
src/Spring/Spring.Core/antlr/debug/InputBufferEventArgs.cs
Normal file
50
src/Spring/Spring.Core/antlr/debug/InputBufferEventArgs.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public class InputBufferEventArgs : ANTLREventArgs
|
||||
{
|
||||
public InputBufferEventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
public InputBufferEventArgs(int type, char c, int lookaheadAmount)
|
||||
{
|
||||
setValues(type, c, lookaheadAmount);
|
||||
}
|
||||
|
||||
public virtual char Char
|
||||
{
|
||||
get { return this.c_; }
|
||||
set { this.c_ = value; }
|
||||
}
|
||||
public virtual int LookaheadAmount
|
||||
{
|
||||
get { return this.lookaheadAmount_; }
|
||||
set { this.lookaheadAmount_ = value; }
|
||||
}
|
||||
|
||||
internal char c_;
|
||||
internal int lookaheadAmount_; // amount of lookahead
|
||||
|
||||
public const int CONSUME = 0;
|
||||
public const int LA = 1;
|
||||
public const int MARK = 2;
|
||||
public const int REWIND = 3;
|
||||
|
||||
|
||||
/// <summary>This should NOT be called from anyone other than ParserEventSupport!
|
||||
/// </summary>
|
||||
internal void setValues(int type, char c, int la)
|
||||
{
|
||||
setValues(type);
|
||||
this.Char = c;
|
||||
this.LookaheadAmount = la;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "CharBufferEvent [" + (Type == CONSUME?"CONSUME, ":"LA, ") + Char + "," + LookaheadAmount + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
124
src/Spring/Spring.Core/antlr/debug/InputBufferEventSupport.cs
Normal file
124
src/Spring/Spring.Core/antlr/debug/InputBufferEventSupport.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
using ArrayList = System.Collections.ArrayList;
|
||||
|
||||
public class InputBufferEventSupport
|
||||
{
|
||||
public virtual ArrayList InputBufferListeners
|
||||
{
|
||||
get
|
||||
{
|
||||
return inputBufferListeners;
|
||||
}
|
||||
|
||||
}
|
||||
private object source;
|
||||
private ArrayList inputBufferListeners;
|
||||
private InputBufferEventArgs inputBufferEvent;
|
||||
protected internal const int CONSUME = 0;
|
||||
protected internal const int LA = 1;
|
||||
protected internal const int MARK = 2;
|
||||
protected internal const int REWIND = 3;
|
||||
|
||||
|
||||
public InputBufferEventSupport(object source)
|
||||
{
|
||||
inputBufferEvent = new InputBufferEventArgs();
|
||||
this.source = source;
|
||||
}
|
||||
public virtual void addInputBufferListener(InputBufferListener l)
|
||||
{
|
||||
if (inputBufferListeners == null)
|
||||
inputBufferListeners = new ArrayList();
|
||||
inputBufferListeners.Add(l);
|
||||
}
|
||||
public virtual void fireConsume(char c)
|
||||
{
|
||||
inputBufferEvent.setValues(InputBufferEventArgs.CONSUME, c, 0);
|
||||
fireEvents(CONSUME, inputBufferListeners);
|
||||
}
|
||||
public virtual void fireEvent(int type, Listener l)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case CONSUME:
|
||||
((InputBufferListener) l).inputBufferConsume(source, inputBufferEvent); break;
|
||||
|
||||
case LA:
|
||||
((InputBufferListener) l).inputBufferLA(source, inputBufferEvent); break;
|
||||
|
||||
case MARK:
|
||||
((InputBufferListener) l).inputBufferMark(source, inputBufferEvent); break;
|
||||
|
||||
case REWIND:
|
||||
((InputBufferListener) l).inputBufferRewind(source, inputBufferEvent); break;
|
||||
|
||||
default:
|
||||
throw new System.ArgumentException("bad type " + type + " for fireEvent()");
|
||||
|
||||
}
|
||||
}
|
||||
public virtual void fireEvents(int type, ArrayList listeners)
|
||||
{
|
||||
ArrayList targets = null;
|
||||
Listener l = null;
|
||||
|
||||
lock(this)
|
||||
{
|
||||
if (listeners == null)
|
||||
return ;
|
||||
targets = (ArrayList) listeners.Clone();
|
||||
}
|
||||
|
||||
if (targets != null)
|
||||
for (int i = 0; i < targets.Count; i++)
|
||||
{
|
||||
l = (Listener) targets[i];
|
||||
fireEvent(type, l);
|
||||
}
|
||||
}
|
||||
public virtual void fireLA(char c, int la)
|
||||
{
|
||||
inputBufferEvent.setValues(InputBufferEventArgs.LA, c, la);
|
||||
fireEvents(LA, inputBufferListeners);
|
||||
}
|
||||
public virtual void fireMark(int pos)
|
||||
{
|
||||
inputBufferEvent.setValues(InputBufferEventArgs.MARK, ' ', pos);
|
||||
fireEvents(MARK, inputBufferListeners);
|
||||
}
|
||||
public virtual void fireRewind(int pos)
|
||||
{
|
||||
inputBufferEvent.setValues(InputBufferEventArgs.REWIND, ' ', pos);
|
||||
fireEvents(REWIND, inputBufferListeners);
|
||||
}
|
||||
protected internal virtual void refresh(ArrayList listeners)
|
||||
{
|
||||
ArrayList v;
|
||||
lock(listeners)
|
||||
{
|
||||
v = (ArrayList) listeners.Clone();
|
||||
}
|
||||
if (v != null)
|
||||
for (int i = 0; i < v.Count; i++)
|
||||
((Listener) v[i]).refresh();
|
||||
}
|
||||
public virtual void refreshListeners()
|
||||
{
|
||||
refresh(inputBufferListeners);
|
||||
}
|
||||
public virtual void removeInputBufferListener(InputBufferListener l)
|
||||
{
|
||||
if (inputBufferListeners != null)
|
||||
{
|
||||
ArrayList temp_arraylist;
|
||||
object temp_object;
|
||||
temp_arraylist = inputBufferListeners;
|
||||
temp_object = l;
|
||||
temp_arraylist.Contains(temp_object);
|
||||
temp_arraylist.Remove(temp_object);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/Spring/Spring.Core/antlr/debug/InputBufferListener.cs
Normal file
12
src/Spring/Spring.Core/antlr/debug/InputBufferListener.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface InputBufferListener : Listener
|
||||
{
|
||||
void inputBufferConsume (object source, InputBufferEventArgs e);
|
||||
void inputBufferLA (object source, InputBufferEventArgs e);
|
||||
void inputBufferMark (object source, InputBufferEventArgs e);
|
||||
void inputBufferRewind (object source, InputBufferEventArgs e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an abstract base for implementing <see cref="InputBufferListener"/> subclasses.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <param>
|
||||
/// This abstract class is provided to make it easier to create <see cref="InputBufferListener"/>s.
|
||||
/// You should extend this base class rather than creating your own.
|
||||
/// </param>
|
||||
/// </remarks>
|
||||
public abstract class InputBufferListenerBase : InputBufferListener
|
||||
{
|
||||
/// <summary>
|
||||
/// Handle the "Done" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void doneParsing(object source, TraceEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "CharConsumed" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void inputBufferConsume(object source, InputBufferEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "CharLA" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void inputBufferLA(object source, InputBufferEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "Mark" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void inputBufferMark(object source, InputBufferEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "Rewind" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void inputBufferRewind(object source, InputBufferEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void refresh()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
36
src/Spring/Spring.Core/antlr/debug/InputBufferReporter.cs
Normal file
36
src/Spring/Spring.Core/antlr/debug/InputBufferReporter.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public class InputBufferReporter : InputBufferListenerBase, InputBufferListener
|
||||
{
|
||||
public virtual void inputBufferChanged(object source, InputBufferEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(e);
|
||||
}
|
||||
|
||||
/// <summary> charBufferConsume method comment.
|
||||
/// </summary>
|
||||
public override void inputBufferConsume(object source, InputBufferEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(e);
|
||||
}
|
||||
|
||||
/// <summary> charBufferLA method comment.
|
||||
/// </summary>
|
||||
public override void inputBufferLA(object source, InputBufferEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(e);
|
||||
}
|
||||
|
||||
public override void inputBufferMark(object source, InputBufferEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(e);
|
||||
}
|
||||
|
||||
public override void inputBufferRewind(object source, InputBufferEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
299
src/Spring/Spring.Core/antlr/debug/LLkDebuggingParser.cs
Normal file
299
src/Spring/Spring.Core/antlr/debug/LLkDebuggingParser.cs
Normal file
@@ -0,0 +1,299 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
using System.Threading;
|
||||
using antlr.collections.impl;
|
||||
|
||||
public class LLkDebuggingParser : LLkParser, DebuggingParser
|
||||
{
|
||||
private void InitBlock()
|
||||
{
|
||||
parserEventSupport = new ParserEventSupport(this);
|
||||
}
|
||||
public override void setDebugMode(bool mode)
|
||||
{
|
||||
_notDebugMode = !mode;
|
||||
}
|
||||
protected internal ParserEventSupport parserEventSupport;
|
||||
|
||||
private bool _notDebugMode = false;
|
||||
protected internal string[] ruleNames;
|
||||
protected internal string[] semPredNames;
|
||||
|
||||
|
||||
public LLkDebuggingParser(int k_):base(k_)
|
||||
{
|
||||
InitBlock();
|
||||
}
|
||||
public LLkDebuggingParser(ParserSharedInputState state, int k_):base(state, k_)
|
||||
{
|
||||
InitBlock();
|
||||
}
|
||||
public LLkDebuggingParser(TokenBuffer tokenBuf, int k_):base(tokenBuf, k_)
|
||||
{
|
||||
InitBlock();
|
||||
}
|
||||
public LLkDebuggingParser(TokenStream lexer, int k_):base(lexer, k_)
|
||||
{
|
||||
InitBlock();
|
||||
}
|
||||
public override void addMessageListener(MessageListener l)
|
||||
{
|
||||
parserEventSupport.addMessageListener(l);
|
||||
}
|
||||
public override void addParserListener(ParserListener l)
|
||||
{
|
||||
parserEventSupport.addParserListener(l);
|
||||
}
|
||||
public override void addParserMatchListener(ParserMatchListener l)
|
||||
{
|
||||
parserEventSupport.addParserMatchListener(l);
|
||||
}
|
||||
public override void addParserTokenListener(ParserTokenListener l)
|
||||
{
|
||||
parserEventSupport.addParserTokenListener(l);
|
||||
}
|
||||
public override void addSemanticPredicateListener(SemanticPredicateListener l)
|
||||
{
|
||||
parserEventSupport.addSemanticPredicateListener(l);
|
||||
}
|
||||
public override void addSyntacticPredicateListener(SyntacticPredicateListener l)
|
||||
{
|
||||
parserEventSupport.addSyntacticPredicateListener(l);
|
||||
}
|
||||
public override void addTraceListener(TraceListener l)
|
||||
{
|
||||
parserEventSupport.addTraceListener(l);
|
||||
}
|
||||
/// <summary>Get another token object from the token stream
|
||||
/// </summary>
|
||||
public override void consume()
|
||||
{
|
||||
int la_1 = - 99;
|
||||
la_1 = LA(1);
|
||||
base.consume();
|
||||
parserEventSupport.fireConsume(la_1);
|
||||
}
|
||||
protected internal virtual void fireEnterRule(int num, int data)
|
||||
{
|
||||
if (isDebugMode())
|
||||
parserEventSupport.fireEnterRule(num, inputState.guessing, data);
|
||||
}
|
||||
protected internal virtual void fireExitRule(int num, int data)
|
||||
{
|
||||
if (isDebugMode())
|
||||
parserEventSupport.fireExitRule(num, inputState.guessing, data);
|
||||
}
|
||||
protected internal virtual bool fireSemanticPredicateEvaluated(int type, int num, bool condition)
|
||||
{
|
||||
if (isDebugMode())
|
||||
return parserEventSupport.fireSemanticPredicateEvaluated(type, num, condition, inputState.guessing);
|
||||
else
|
||||
return condition;
|
||||
}
|
||||
protected internal virtual void fireSyntacticPredicateFailed()
|
||||
{
|
||||
if (isDebugMode())
|
||||
parserEventSupport.fireSyntacticPredicateFailed(inputState.guessing);
|
||||
}
|
||||
protected internal virtual void fireSyntacticPredicateStarted()
|
||||
{
|
||||
if (isDebugMode())
|
||||
parserEventSupport.fireSyntacticPredicateStarted(inputState.guessing);
|
||||
}
|
||||
protected internal virtual void fireSyntacticPredicateSucceeded()
|
||||
{
|
||||
if (isDebugMode())
|
||||
parserEventSupport.fireSyntacticPredicateSucceeded(inputState.guessing);
|
||||
}
|
||||
public virtual string getRuleName(int num)
|
||||
{
|
||||
return ruleNames[num];
|
||||
}
|
||||
public virtual string getSemPredName(int num)
|
||||
{
|
||||
return semPredNames[num];
|
||||
}
|
||||
|
||||
public virtual void goToSleep()
|
||||
{
|
||||
lock(this)
|
||||
{
|
||||
try
|
||||
{
|
||||
Monitor.Wait(this);
|
||||
}
|
||||
catch (System.Threading.ThreadInterruptedException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
public override bool isDebugMode()
|
||||
{
|
||||
return !_notDebugMode;
|
||||
}
|
||||
public virtual bool isGuessing()
|
||||
{
|
||||
return inputState.guessing > 0;
|
||||
}
|
||||
/// <summary>Return the token type of the ith token of lookahead where i=1
|
||||
/// is the current token being examined by the parser (i.e., it
|
||||
/// has not been matched yet).
|
||||
/// </summary>
|
||||
public override int LA(int i)
|
||||
{
|
||||
int la = base.LA(i);
|
||||
parserEventSupport.fireLA(i, la);
|
||||
return la;
|
||||
}
|
||||
/// <summary>Make sure current lookahead symbol matches token type <tt>t</tt>.
|
||||
/// Throw an exception upon mismatch, which is catch by either the
|
||||
/// error handler or by the syntactic predicate.
|
||||
/// </summary>
|
||||
public override void match(int t)
|
||||
{
|
||||
string text = LT(1).getText();
|
||||
int la_1 = LA(1);
|
||||
try
|
||||
{
|
||||
base.match(t);
|
||||
parserEventSupport.fireMatch(t, text, inputState.guessing);
|
||||
}
|
||||
catch (MismatchedTokenException e)
|
||||
{
|
||||
if (inputState.guessing == 0)
|
||||
parserEventSupport.fireMismatch(la_1, t, text, inputState.guessing);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
/// <summary>Make sure current lookahead symbol matches the given set
|
||||
/// Throw an exception upon mismatch, which is catch by either the
|
||||
/// error handler or by the syntactic predicate.
|
||||
/// </summary>
|
||||
public override void match(BitSet b)
|
||||
{
|
||||
string text = LT(1).getText();
|
||||
int la_1 = LA(1);
|
||||
try
|
||||
{
|
||||
base.match(b);
|
||||
parserEventSupport.fireMatch(la_1, b, text, inputState.guessing);
|
||||
}
|
||||
catch (MismatchedTokenException e)
|
||||
{
|
||||
if (inputState.guessing == 0)
|
||||
parserEventSupport.fireMismatch(la_1, b, text, inputState.guessing);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
public override void matchNot(int t)
|
||||
{
|
||||
string text = LT(1).getText();
|
||||
int la_1 = LA(1);
|
||||
try
|
||||
{
|
||||
base.matchNot(t);
|
||||
parserEventSupport.fireMatchNot(la_1, t, text, inputState.guessing);
|
||||
}
|
||||
catch (MismatchedTokenException e)
|
||||
{
|
||||
if (inputState.guessing == 0)
|
||||
parserEventSupport.fireMismatchNot(la_1, t, text, inputState.guessing);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
public override void removeMessageListener(MessageListener l)
|
||||
{
|
||||
parserEventSupport.removeMessageListener(l);
|
||||
}
|
||||
public override void removeParserListener(ParserListener l)
|
||||
{
|
||||
parserEventSupport.removeParserListener(l);
|
||||
}
|
||||
public override void removeParserMatchListener(ParserMatchListener l)
|
||||
{
|
||||
parserEventSupport.removeParserMatchListener(l);
|
||||
}
|
||||
public override void removeParserTokenListener(ParserTokenListener l)
|
||||
{
|
||||
parserEventSupport.removeParserTokenListener(l);
|
||||
}
|
||||
public override void removeSemanticPredicateListener(SemanticPredicateListener l)
|
||||
{
|
||||
parserEventSupport.removeSemanticPredicateListener(l);
|
||||
}
|
||||
public override void removeSyntacticPredicateListener(SyntacticPredicateListener l)
|
||||
{
|
||||
parserEventSupport.removeSyntacticPredicateListener(l);
|
||||
}
|
||||
public override void removeTraceListener(TraceListener l)
|
||||
{
|
||||
parserEventSupport.removeTraceListener(l);
|
||||
}
|
||||
/// <summary>Parser error-reporting function can be overridden in subclass
|
||||
/// </summary>
|
||||
public override void reportError(RecognitionException ex)
|
||||
{
|
||||
parserEventSupport.fireReportError(ex);
|
||||
base.reportError(ex);
|
||||
}
|
||||
/// <summary>Parser error-reporting function can be overridden in subclass
|
||||
/// </summary>
|
||||
public override void reportError(string s)
|
||||
{
|
||||
parserEventSupport.fireReportError(s);
|
||||
base.reportError(s);
|
||||
}
|
||||
/// <summary>Parser warning-reporting function can be overridden in subclass
|
||||
/// </summary>
|
||||
public override void reportWarning(string s)
|
||||
{
|
||||
parserEventSupport.fireReportWarning(s);
|
||||
base.reportWarning(s);
|
||||
}
|
||||
public virtual void setupDebugging(TokenBuffer tokenBuf)
|
||||
{
|
||||
setupDebugging(null, tokenBuf);
|
||||
}
|
||||
public virtual void setupDebugging(TokenStream lexer)
|
||||
{
|
||||
setupDebugging(lexer, null);
|
||||
}
|
||||
/// <summary>User can override to do their own debugging
|
||||
/// </summary>
|
||||
protected internal virtual void setupDebugging(TokenStream lexer, TokenBuffer tokenBuf)
|
||||
{
|
||||
setDebugMode(true);
|
||||
// default parser debug setup is ParseView
|
||||
try
|
||||
{
|
||||
// try
|
||||
// {
|
||||
// System.Type.GetType("javax.swing.JButton");
|
||||
// }
|
||||
// catch (System.Exception)
|
||||
// {
|
||||
// System.Console.Error.WriteLine("Swing is required to use ParseView, but is not present in your CLASSPATH");
|
||||
// System.Environment.Exit(1);
|
||||
// }
|
||||
System.Type c = System.Type.GetType("antlr.parseview.ParseView");
|
||||
System.Reflection.ConstructorInfo constructor = c.GetConstructor(new System.Type[]{typeof(LLkDebuggingParser), typeof(TokenStream), typeof(TokenBuffer)});
|
||||
constructor.Invoke(new object[]{this, lexer, tokenBuf});
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
System.Console.Error.WriteLine("Error initializing ParseView: " + e);
|
||||
System.Console.Error.WriteLine("Please report this to Scott Stanchfield, thetick@magelang.com");
|
||||
System.Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void wakeUp()
|
||||
{
|
||||
lock(this)
|
||||
{
|
||||
Monitor.Pulse(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
src/Spring/Spring.Core/antlr/debug/Listener.cs
Normal file
11
src/Spring/Spring.Core/antlr/debug/Listener.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
|
||||
public interface Listener
|
||||
{
|
||||
void doneParsing (object source, TraceEventArgs e);
|
||||
void refresh ();
|
||||
}
|
||||
}
|
||||
41
src/Spring/Spring.Core/antlr/debug/MessageEventArgs.cs
Normal file
41
src/Spring/Spring.Core/antlr/debug/MessageEventArgs.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public class MessageEventArgs : ANTLREventArgs
|
||||
{
|
||||
public MessageEventArgs()
|
||||
{
|
||||
}
|
||||
public MessageEventArgs(int type, string text)
|
||||
{
|
||||
setValues(type, text);
|
||||
}
|
||||
|
||||
public virtual string Text
|
||||
{
|
||||
get { return text_; }
|
||||
set { this.text_ = value; }
|
||||
|
||||
}
|
||||
|
||||
private string text_;
|
||||
|
||||
public static int WARNING = 0;
|
||||
public static int ERROR = 1;
|
||||
|
||||
|
||||
/// <summary>This should NOT be called from anyone other than ParserEventSupport!
|
||||
/// </summary>
|
||||
internal void setValues(int type, string text)
|
||||
{
|
||||
setValues(type);
|
||||
this.Text = text;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "ParserMessageEvent [" + (Type == WARNING?"warning,":"error,") + Text + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/Spring/Spring.Core/antlr/debug/MessageListener.cs
Normal file
10
src/Spring/Spring.Core/antlr/debug/MessageListener.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface MessageListener : Listener
|
||||
{
|
||||
void reportError (object source, MessageEventArgs e);
|
||||
void reportWarning (object source, MessageEventArgs e);
|
||||
}
|
||||
}
|
||||
47
src/Spring/Spring.Core/antlr/debug/MessageListenerBase.cs
Normal file
47
src/Spring/Spring.Core/antlr/debug/MessageListenerBase.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an abstract base for implementing <see cref="MessageListener"/> subclasses.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <param>
|
||||
/// This abstract class is provided to make it easier to create <see cref="MessageListener"/>s.
|
||||
/// You should extend this base class rather than creating your own.
|
||||
/// </param>
|
||||
/// </remarks>
|
||||
public class MessageListenerBase : MessageListener
|
||||
{
|
||||
/// <summary>
|
||||
/// Handle the "Done" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void doneParsing(object source, TraceEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void refresh()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "ReportError" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void reportError(object source, MessageEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "ReportWarning" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void reportWarning(object source, MessageEventArgs e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/Spring/Spring.Core/antlr/debug/NewLineEventArgs.cs
Normal file
31
src/Spring/Spring.Core/antlr/debug/NewLineEventArgs.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public class NewLineEventArgs : ANTLREventArgs
|
||||
{
|
||||
public NewLineEventArgs()
|
||||
{
|
||||
}
|
||||
public NewLineEventArgs(int line)
|
||||
{
|
||||
Line = line;
|
||||
}
|
||||
|
||||
public virtual int Line
|
||||
{
|
||||
get { return this.line_; }
|
||||
set { this.line_ = value; }
|
||||
}
|
||||
|
||||
private int line_;
|
||||
|
||||
|
||||
/// <summary>This should NOT be called from anyone other than ParserEventSupport!
|
||||
/// </summary>
|
||||
public override string ToString()
|
||||
{
|
||||
return "NewLineEvent [" + line_ + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
9
src/Spring/Spring.Core/antlr/debug/NewLineListener.cs
Normal file
9
src/Spring/Spring.Core/antlr/debug/NewLineListener.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface NewLineListener : Listener
|
||||
{
|
||||
void hitNewLine(object source, NewLineEventArgs e);
|
||||
}
|
||||
}
|
||||
162
src/Spring/Spring.Core/antlr/debug/ParseTreeDebugParser.cs
Normal file
162
src/Spring/Spring.Core/antlr/debug/ParseTreeDebugParser.cs
Normal file
@@ -0,0 +1,162 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
|
||||
/* ANTLR Translator Generator
|
||||
* Project led by Terence Parr at http://www.jGuru.com
|
||||
* Software rights: http://www.antlr.org/license.html
|
||||
*/
|
||||
|
||||
//
|
||||
// ANTLR C# Code Generator by Micheal Jordan
|
||||
// Kunle Odutola : kunle UNDERSCORE odutola AT hotmail DOT com
|
||||
// Anthony Oguntimehin
|
||||
//
|
||||
|
||||
using System;
|
||||
using Stack = System.Collections.Stack;
|
||||
using antlr;
|
||||
using BitSet = antlr.collections.impl.BitSet;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the behaviour required (i.e. parser modifications)
|
||||
/// specifically to support parse tree debugging and derivation.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Override the standard matching and rule entry/exit routines
|
||||
/// to build parse trees. This class is useful for 2.7.3 where
|
||||
/// you can specify a superclass like
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// class TinyCParser extends Parser(ParseTreeDebugParser);
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public class ParseTreeDebugParser : LLkParser
|
||||
{
|
||||
/// <summary>
|
||||
/// Each new rule invocation must have it's own subtree. Tokens are
|
||||
/// added to the current root so we must have a stack of subtree roots.
|
||||
/// </summary>
|
||||
protected Stack currentParseTreeRoot = new Stack();
|
||||
|
||||
/// <summary>
|
||||
/// Track most recently created parse subtree so that when parsing
|
||||
/// is finished, we can get to the root.
|
||||
/// </summary>
|
||||
protected ParseTreeRule mostRecentParseTreeRoot = null;
|
||||
|
||||
/// <summary>
|
||||
/// For every rule replacement with a production, we bump up count.
|
||||
/// </summary>
|
||||
protected int numberOfDerivationSteps = 1; // n replacements plus step 0
|
||||
|
||||
public ParseTreeDebugParser(int k_) : base(k_)
|
||||
{
|
||||
}
|
||||
|
||||
public ParseTreeDebugParser(ParserSharedInputState state, int k_) : base(state, k_)
|
||||
{
|
||||
}
|
||||
|
||||
public ParseTreeDebugParser(TokenBuffer tokenBuf, int k_) : base(tokenBuf, k_)
|
||||
{
|
||||
}
|
||||
|
||||
public ParseTreeDebugParser(TokenStream lexer, int k_) : base(lexer,k_)
|
||||
{
|
||||
}
|
||||
|
||||
public ParseTree getParseTree()
|
||||
{
|
||||
return mostRecentParseTreeRoot;
|
||||
}
|
||||
|
||||
public int getNumberOfDerivationSteps()
|
||||
{
|
||||
return numberOfDerivationSteps;
|
||||
}
|
||||
|
||||
public override void match(int i) // throws MismatchedTokenException, TokenStreamException
|
||||
{
|
||||
addCurrentTokenToParseTree();
|
||||
base.match(i);
|
||||
}
|
||||
|
||||
public override void match(BitSet bitSet) // throws MismatchedTokenException, TokenStreamException
|
||||
{
|
||||
addCurrentTokenToParseTree();
|
||||
base.match(bitSet);
|
||||
}
|
||||
|
||||
public override void matchNot(int i) // throws MismatchedTokenException, TokenStreamException
|
||||
{
|
||||
addCurrentTokenToParseTree();
|
||||
base.matchNot(i);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds LT(1) to the current parse subtree.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Note that the match() routines add the node before checking for
|
||||
/// correct match. This means that, upon mismatched token, there
|
||||
/// will a token node in the tree corresponding to where that token
|
||||
/// was expected. For no viable alternative errors, no node will
|
||||
/// be in the tree as nothing was matched() (the lookahead failed
|
||||
/// to predict an alternative).
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
protected void addCurrentTokenToParseTree() // throws TokenStreamException
|
||||
{
|
||||
if (inputState.guessing > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ParseTreeRule root = (ParseTreeRule) currentParseTreeRoot.Peek();
|
||||
ParseTreeToken tokenNode = null;
|
||||
if ( LA(1) == Token.EOF_TYPE )
|
||||
{
|
||||
tokenNode = new ParseTreeToken(new antlr.CommonToken("EOF"));
|
||||
}
|
||||
else
|
||||
{
|
||||
tokenNode = new ParseTreeToken(LT(1));
|
||||
}
|
||||
root.addChild(tokenNode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a rule node, add to current tree, and make it current root
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
public override void traceIn(string s) // throws TokenStreamException
|
||||
{
|
||||
if (inputState.guessing > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ParseTreeRule subRoot = new ParseTreeRule(s);
|
||||
if ( currentParseTreeRoot.Count > 0 )
|
||||
{
|
||||
ParseTreeRule oldRoot = (ParseTreeRule) currentParseTreeRoot.Peek();
|
||||
oldRoot.addChild(subRoot);
|
||||
}
|
||||
currentParseTreeRoot.Push(subRoot);
|
||||
numberOfDerivationSteps++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pop current root; back to adding to old root
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
public override void traceOut(string s) // throws TokenStreamException
|
||||
{
|
||||
if (inputState.guessing > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
mostRecentParseTreeRoot = (ParseTreeRule) currentParseTreeRoot.Pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
14
src/Spring/Spring.Core/antlr/debug/ParserController.cs
Normal file
14
src/Spring/Spring.Core/antlr/debug/ParserController.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface ParserController : ParserListener
|
||||
{
|
||||
ParserEventSupport ParserEventSupport
|
||||
{
|
||||
set;
|
||||
}
|
||||
|
||||
void checkBreak();
|
||||
}
|
||||
}
|
||||
490
src/Spring/Spring.Core/antlr/debug/ParserEventSupport.cs
Normal file
490
src/Spring/Spring.Core/antlr/debug/ParserEventSupport.cs
Normal file
@@ -0,0 +1,490 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Hashtable = System.Collections.Hashtable;
|
||||
using DictionaryEntry = System.Collections.DictionaryEntry;
|
||||
using ArrayList = System.Collections.ArrayList;
|
||||
|
||||
using antlr.collections.impl;
|
||||
|
||||
|
||||
public delegate void MessageEventHandler(object sender, MessageEventArgs e);
|
||||
public delegate void NewLineEventHandler(object sender, NewLineEventArgs e);
|
||||
public delegate void MatchEventHandler(object sender, MatchEventArgs e);
|
||||
public delegate void TokenEventHandler(object sender, TokenEventArgs e);
|
||||
public delegate void SemanticPredicateEventHandler(object sender, SemanticPredicateEventArgs e);
|
||||
public delegate void SyntacticPredicateEventHandler(object sender, SyntacticPredicateEventArgs e);
|
||||
public delegate void TraceEventHandler(object sender, TraceEventArgs e);
|
||||
|
||||
/// <summary>A class to assist in firing parser events
|
||||
/// NOTE: I intentionally _did_not_ synchronize the event firing and
|
||||
/// add/remove listener methods. This is because the add/remove should
|
||||
/// _only_ be called by the parser at its start/end, and the _same_thread_
|
||||
/// should be performing the parsing. This should help performance a tad...
|
||||
/// </summary>
|
||||
public class ParserEventSupport
|
||||
{
|
||||
private object source;
|
||||
private Hashtable listeners;
|
||||
|
||||
private MatchEventArgs matchEvent;
|
||||
private MessageEventArgs messageEvent;
|
||||
private TokenEventArgs tokenEvent;
|
||||
private SemanticPredicateEventArgs semPredEvent;
|
||||
private SyntacticPredicateEventArgs synPredEvent;
|
||||
private TraceEventArgs traceEvent;
|
||||
private NewLineEventArgs newLineEvent;
|
||||
|
||||
private ParserController controller;
|
||||
|
||||
private int ruleDepth = 0;
|
||||
|
||||
|
||||
public ParserEventSupport(object source)
|
||||
{
|
||||
matchEvent = new MatchEventArgs();
|
||||
messageEvent = new MessageEventArgs();
|
||||
tokenEvent = new TokenEventArgs();
|
||||
traceEvent = new TraceEventArgs();
|
||||
semPredEvent = new SemanticPredicateEventArgs();
|
||||
synPredEvent = new SyntacticPredicateEventArgs();
|
||||
newLineEvent = new NewLineEventArgs();
|
||||
listeners = new Hashtable();
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public virtual void checkController()
|
||||
{
|
||||
if (controller != null)
|
||||
controller.checkBreak();
|
||||
}
|
||||
|
||||
public virtual void addDoneListener(Listener l)
|
||||
{
|
||||
((Parser)source).Done += new TraceEventHandler(l.doneParsing);
|
||||
listeners[l] = l;
|
||||
}
|
||||
public virtual void addMessageListener(MessageListener l)
|
||||
{
|
||||
((Parser)source).ErrorReported += new MessageEventHandler(l.reportError);
|
||||
((Parser)source).WarningReported += new MessageEventHandler(l.reportWarning);
|
||||
//messageListeners.Add(l);
|
||||
addDoneListener(l);
|
||||
}
|
||||
public virtual void addParserListener(ParserListener l)
|
||||
{
|
||||
if (l is ParserController)
|
||||
{
|
||||
((ParserController) l).ParserEventSupport = this;
|
||||
controller = (ParserController) l;
|
||||
}
|
||||
addParserMatchListener(l);
|
||||
addParserTokenListener(l);
|
||||
|
||||
addMessageListener(l);
|
||||
addTraceListener(l);
|
||||
addSemanticPredicateListener(l);
|
||||
addSyntacticPredicateListener(l);
|
||||
}
|
||||
public virtual void addParserMatchListener(ParserMatchListener l)
|
||||
{
|
||||
((Parser)source).MatchedToken += new MatchEventHandler(l.parserMatch);
|
||||
((Parser)source).MatchedNotToken += new MatchEventHandler(l.parserMatchNot);
|
||||
((Parser)source).MisMatchedToken += new MatchEventHandler(l.parserMismatch);
|
||||
((Parser)source).MisMatchedNotToken += new MatchEventHandler(l.parserMismatchNot);
|
||||
//matchListeners.Add(l);
|
||||
addDoneListener(l);
|
||||
}
|
||||
public virtual void addParserTokenListener(ParserTokenListener l)
|
||||
{
|
||||
((Parser)source).ConsumedToken += new TokenEventHandler(l.parserConsume);
|
||||
((Parser)source).TokenLA += new TokenEventHandler(l.parserLA);
|
||||
//tokenListeners.Add(l);
|
||||
addDoneListener(l);
|
||||
}
|
||||
public virtual void addSemanticPredicateListener(SemanticPredicateListener l)
|
||||
{
|
||||
((Parser)source).SemPredEvaluated += new SemanticPredicateEventHandler(l.semanticPredicateEvaluated);
|
||||
//semPredListeners.Add(l);
|
||||
addDoneListener(l);
|
||||
}
|
||||
public virtual void addSyntacticPredicateListener(SyntacticPredicateListener l)
|
||||
{
|
||||
((Parser)source).SynPredStarted += new SyntacticPredicateEventHandler(l.syntacticPredicateStarted);
|
||||
((Parser)source).SynPredFailed += new SyntacticPredicateEventHandler(l.syntacticPredicateFailed);
|
||||
((Parser)source).SynPredSucceeded += new SyntacticPredicateEventHandler(l.syntacticPredicateSucceeded);
|
||||
//synPredListeners.Add(l);
|
||||
addDoneListener(l);
|
||||
}
|
||||
public virtual void addTraceListener(TraceListener l)
|
||||
{
|
||||
((Parser)source).EnterRule += new TraceEventHandler(l.enterRule);
|
||||
((Parser)source).ExitRule += new TraceEventHandler(l.exitRule);
|
||||
//traceListeners.Add(l);
|
||||
addDoneListener(l);
|
||||
}
|
||||
public virtual void fireConsume(int c)
|
||||
{
|
||||
TokenEventHandler eventDelegate = (TokenEventHandler)((Parser)source).Events[Parser.LAEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
tokenEvent.setValues(TokenEventArgs.CONSUME, 1, c);
|
||||
eventDelegate(source, tokenEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireDoneParsing()
|
||||
{
|
||||
TraceEventHandler eventDelegate = (TraceEventHandler)((Parser)source).Events[Parser.DoneEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
traceEvent.setValues(TraceEventArgs.DONE_PARSING, 0, 0, 0);
|
||||
eventDelegate(source, traceEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireEnterRule(int ruleNum, int guessing, int data)
|
||||
{
|
||||
ruleDepth++;
|
||||
TraceEventHandler eventDelegate = (TraceEventHandler)((Parser)source).Events[Parser.EnterRuleEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
traceEvent.setValues(TraceEventArgs.ENTER, ruleNum, guessing, data);
|
||||
eventDelegate(source, traceEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireExitRule(int ruleNum, int guessing, int data)
|
||||
{
|
||||
TraceEventHandler eventDelegate = (TraceEventHandler)((Parser)source).Events[Parser.ExitRuleEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
traceEvent.setValues(TraceEventArgs.EXIT, ruleNum, guessing, data);
|
||||
eventDelegate(source, traceEvent);
|
||||
}
|
||||
checkController();
|
||||
|
||||
ruleDepth--;
|
||||
if (ruleDepth == 0)
|
||||
fireDoneParsing();
|
||||
|
||||
}
|
||||
public virtual void fireLA(int k, int la)
|
||||
{
|
||||
TokenEventHandler eventDelegate = (TokenEventHandler)((Parser)source).Events[Parser.LAEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
tokenEvent.setValues(TokenEventArgs.LA, k, la);
|
||||
eventDelegate(source, tokenEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatch(char c, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR, c, c, null, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatch(char c, BitSet b, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR_BITSET, c, b, null, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatch(char c, string target, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR_RANGE, c, target, null, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatch(int c, BitSet b, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.BITSET, c, b, text, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatch(int n, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.TOKEN, n, n, text, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatch(string s, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.STRING, 0, s, null, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatchNot(char c, char n, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MatchNotEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR, c, n, null, guessing, true, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatchNot(int c, int n, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MatchNotEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.TOKEN, c, n, text, guessing, true, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatch(char c, char n, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MisMatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR, c, n, null, guessing, false, false);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatch(char c, BitSet b, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MisMatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR_BITSET, c, b, null, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatch(char c, string target, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MisMatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR_RANGE, c, target, null, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatch(int i, int n, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MisMatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.TOKEN, i, n, text, guessing, false, false);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatch(int i, BitSet b, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MisMatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.BITSET, i, b, text, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatch(string s, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MisMatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.STRING, 0, text, s, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatchNot(char v, char c, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MisMatchNotEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR, v, c, null, guessing, true, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatchNot(int i, int n, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((Parser)source).Events[Parser.MisMatchNotEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.TOKEN, i, n, text, guessing, true, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireReportError(System.Exception e)
|
||||
{
|
||||
MessageEventHandler eventDelegate = (MessageEventHandler)((Parser)source).Events[Parser.ReportErrorEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
messageEvent.setValues(MessageEventArgs.ERROR, e.ToString());
|
||||
eventDelegate(source, messageEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireReportError(string s)
|
||||
{
|
||||
MessageEventHandler eventDelegate = (MessageEventHandler)((Parser)source).Events[Parser.ReportErrorEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
messageEvent.setValues(MessageEventArgs.ERROR, s);
|
||||
eventDelegate(source, messageEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireReportWarning(string s)
|
||||
{
|
||||
MessageEventHandler eventDelegate = (MessageEventHandler)((Parser)source).Events[Parser.ReportWarningEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
messageEvent.setValues(MessageEventArgs.WARNING, s);
|
||||
eventDelegate(source, messageEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual bool fireSemanticPredicateEvaluated(int type, int condition, bool result, int guessing)
|
||||
{
|
||||
SemanticPredicateEventHandler eventDelegate = (SemanticPredicateEventHandler)((Parser)source).Events[Parser.SemPredEvaluatedEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
semPredEvent.setValues(type, condition, result, guessing);
|
||||
eventDelegate(source, semPredEvent);
|
||||
}
|
||||
checkController();
|
||||
|
||||
return result;
|
||||
}
|
||||
public virtual void fireSyntacticPredicateFailed(int guessing)
|
||||
{
|
||||
SyntacticPredicateEventHandler eventDelegate = (SyntacticPredicateEventHandler)((Parser)source).Events[Parser.SynPredFailedEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
synPredEvent.setValues(0, guessing);
|
||||
eventDelegate(source, synPredEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireSyntacticPredicateStarted(int guessing)
|
||||
{
|
||||
SyntacticPredicateEventHandler eventDelegate = (SyntacticPredicateEventHandler)((Parser)source).Events[Parser.SynPredStartedEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
synPredEvent.setValues(0, guessing);
|
||||
eventDelegate(source, synPredEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireSyntacticPredicateSucceeded(int guessing)
|
||||
{
|
||||
SyntacticPredicateEventHandler eventDelegate = (SyntacticPredicateEventHandler)((Parser)source).Events[Parser.SynPredSucceededEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
synPredEvent.setValues(0, guessing);
|
||||
eventDelegate(source, synPredEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void refreshListeners()
|
||||
{
|
||||
Hashtable clonedTable;
|
||||
|
||||
lock(listeners.SyncRoot)
|
||||
{
|
||||
clonedTable = (Hashtable)listeners.Clone();
|
||||
}
|
||||
foreach (DictionaryEntry entry in clonedTable)
|
||||
{
|
||||
if (entry.Value != null)
|
||||
{
|
||||
((Listener) entry.Value).refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
public virtual void removeDoneListener(Listener l)
|
||||
{
|
||||
((Parser)source).Done -= new TraceEventHandler(l.doneParsing);
|
||||
listeners.Remove(l);
|
||||
}
|
||||
public virtual void removeMessageListener(MessageListener l)
|
||||
{
|
||||
((Parser)source).ErrorReported -= new MessageEventHandler(l.reportError);
|
||||
((Parser)source).WarningReported -= new MessageEventHandler(l.reportWarning);
|
||||
//messageListeners.Remove(l);
|
||||
removeDoneListener(l);
|
||||
}
|
||||
public virtual void removeParserListener(ParserListener l)
|
||||
{
|
||||
removeParserMatchListener(l);
|
||||
removeMessageListener(l);
|
||||
removeParserTokenListener(l);
|
||||
removeTraceListener(l);
|
||||
removeSemanticPredicateListener(l);
|
||||
removeSyntacticPredicateListener(l);
|
||||
}
|
||||
public virtual void removeParserMatchListener(ParserMatchListener l)
|
||||
{
|
||||
((Parser)source).MatchedToken -= new MatchEventHandler(l.parserMatch);
|
||||
((Parser)source).MatchedNotToken -= new MatchEventHandler(l.parserMatchNot);
|
||||
((Parser)source).MisMatchedToken -= new MatchEventHandler(l.parserMismatch);
|
||||
((Parser)source).MisMatchedNotToken -= new MatchEventHandler(l.parserMismatchNot);
|
||||
//matchListeners.Remove(l);
|
||||
removeDoneListener(l);
|
||||
}
|
||||
public virtual void removeParserTokenListener(ParserTokenListener l)
|
||||
{
|
||||
((Parser)source).ConsumedToken -= new TokenEventHandler(l.parserConsume);
|
||||
((Parser)source).TokenLA -= new TokenEventHandler(l.parserLA);
|
||||
//tokenListeners.Remove(l);
|
||||
removeDoneListener(l);
|
||||
}
|
||||
public virtual void removeSemanticPredicateListener(SemanticPredicateListener l)
|
||||
{
|
||||
((Parser)source).SemPredEvaluated -= new SemanticPredicateEventHandler(l.semanticPredicateEvaluated);
|
||||
//semPredListeners.Remove(l);
|
||||
removeDoneListener(l);
|
||||
}
|
||||
public virtual void removeSyntacticPredicateListener(SyntacticPredicateListener l)
|
||||
{
|
||||
((Parser)source).SynPredStarted -= new SyntacticPredicateEventHandler(l.syntacticPredicateStarted);
|
||||
((Parser)source).SynPredFailed -= new SyntacticPredicateEventHandler(l.syntacticPredicateFailed);
|
||||
((Parser)source).SynPredSucceeded -= new SyntacticPredicateEventHandler(l.syntacticPredicateSucceeded);
|
||||
//synPredListeners.Remove(l);
|
||||
removeDoneListener(l);
|
||||
}
|
||||
public virtual void removeTraceListener(TraceListener l)
|
||||
{
|
||||
((Parser)source).EnterRule -= new TraceEventHandler(l.enterRule);
|
||||
((Parser)source).ExitRule -= new TraceEventHandler(l.exitRule);
|
||||
//traceListeners.Remove(l);
|
||||
removeDoneListener(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/Spring/Spring.Core/antlr/debug/ParserListener.cs
Normal file
8
src/Spring/Spring.Core/antlr/debug/ParserListener.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface ParserListener : SemanticPredicateListener, ParserMatchListener, MessageListener, ParserTokenListener, TraceListener, SyntacticPredicateListener
|
||||
{
|
||||
}
|
||||
}
|
||||
155
src/Spring/Spring.Core/antlr/debug/ParserListenerBase.cs
Normal file
155
src/Spring/Spring.Core/antlr/debug/ParserListenerBase.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an abstract base for implementing <see cref="ParserListener"/> subclasses.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <param>
|
||||
/// This abstract class is provided to make it easier to create <see cref="ParserListener"/>s.
|
||||
/// You should extend this base class rather than creating your own.
|
||||
/// </param>
|
||||
/// </remarks>
|
||||
public class ParserListenerBase : ParserListener
|
||||
{
|
||||
/// <summary>
|
||||
/// Handle the "Done" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void doneParsing(object source, TraceEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "EnterRule" event
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void enterRule(object source, TraceEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "ExitRule" event
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void exitRule(object source, TraceEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "Consume" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void parserConsume(object source, TokenEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "ParserLA" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void parserLA(object source, TokenEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "Match" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void parserMatch(object source, MatchEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "MatchNot" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void parserMatchNot(object source, MatchEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "MisMatch" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void parserMismatch(object source, MatchEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "MisMatchNot" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void parserMismatchNot(object source, MatchEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "ReportError" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void reportError(object source, MessageEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "ReportWarning" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void reportWarning(object source, MessageEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "SemPreEvaluated" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void semanticPredicateEvaluated(object source, SemanticPredicateEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "SynPredFailed" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void syntacticPredicateFailed(object source, SyntacticPredicateEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "SynPredStarted" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void syntacticPredicateStarted(object source, SyntacticPredicateEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "SynPredSucceeded" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void syntacticPredicateSucceeded(object source, SyntacticPredicateEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void refresh()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
93
src/Spring/Spring.Core/antlr/debug/ParserMatchEventArgs.cs
Normal file
93
src/Spring/Spring.Core/antlr/debug/ParserMatchEventArgs.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public class MatchEventArgs : GuessingEventArgs
|
||||
{
|
||||
public MatchEventArgs()
|
||||
{
|
||||
}
|
||||
public MatchEventArgs(int type, int val, object target, string text, int guessing, bool inverse, bool matched)
|
||||
{
|
||||
setValues(type, val, target, text, guessing, inverse, matched);
|
||||
}
|
||||
|
||||
public virtual object Target
|
||||
{
|
||||
get { return this.target_; }
|
||||
set { this.target_ = value; }
|
||||
}
|
||||
|
||||
public virtual string Text
|
||||
{
|
||||
get { return this.text_; }
|
||||
set { this.text_ = value; }
|
||||
}
|
||||
|
||||
public virtual int Value
|
||||
{
|
||||
get { return this.val_; }
|
||||
set { this.val_ = value; }
|
||||
}
|
||||
|
||||
internal bool Inverse
|
||||
{
|
||||
set { this.inverse_ = value; }
|
||||
}
|
||||
|
||||
internal bool Matched
|
||||
{
|
||||
set { this.matched_ = value; }
|
||||
}
|
||||
|
||||
// NOTE: for a mismatch on type STRING, the "text" is used as the lookahead
|
||||
// value. Normally "value" is this
|
||||
public enum ParserMatchEnums
|
||||
{
|
||||
TOKEN = 0,
|
||||
BITSET = 1,
|
||||
CHAR = 2,
|
||||
CHAR_BITSET = 3,
|
||||
STRING = 4,
|
||||
CHAR_RANGE = 5,
|
||||
}
|
||||
public static int TOKEN = 0;
|
||||
public static int BITSET = 1;
|
||||
public static int CHAR = 2;
|
||||
public static int CHAR_BITSET = 3;
|
||||
public static int STRING = 4;
|
||||
public static int CHAR_RANGE = 5;
|
||||
|
||||
private bool inverse_;
|
||||
private bool matched_;
|
||||
private object target_;
|
||||
private int val_;
|
||||
private string text_;
|
||||
|
||||
|
||||
public virtual bool isInverse()
|
||||
{
|
||||
return inverse_;
|
||||
}
|
||||
public virtual bool isMatched()
|
||||
{
|
||||
return matched_;
|
||||
}
|
||||
/// <summary>This should NOT be called from anyone other than ParserEventSupport!
|
||||
/// </summary>
|
||||
internal void setValues(int type, int val, object target, string text, int guessing, bool inverse, bool matched)
|
||||
{
|
||||
base.setValues(type, guessing);
|
||||
this.Value = val;
|
||||
this.Target = target;
|
||||
this.Inverse = inverse;
|
||||
this.Matched = matched;
|
||||
this.Text = text;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "ParserMatchEvent [" + (isMatched()?"ok,":"bad,") + (isInverse()?"NOT ":"") + (Type == TOKEN?"token,":"bitset,") + Value + "," + Target + "," + Guessing + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/Spring/Spring.Core/antlr/debug/ParserMatchListener.cs
Normal file
12
src/Spring/Spring.Core/antlr/debug/ParserMatchListener.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface ParserMatchListener : Listener
|
||||
{
|
||||
void parserMatch (object source, MatchEventArgs e);
|
||||
void parserMatchNot (object source, MatchEventArgs e);
|
||||
void parserMismatch (object source, MatchEventArgs e);
|
||||
void parserMismatchNot (object source, MatchEventArgs e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an abstract base for implementing <see cref="ParserMatchListener"/> subclasses.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <param>
|
||||
/// This abstract class is provided to make it easier to create <see cref="ParserMatchListener"/>s.
|
||||
/// You should extend this base class rather than creating your own.
|
||||
/// </param>
|
||||
/// </remarks>
|
||||
public abstract class ParserMatchListenerBase : ParserMatchListener
|
||||
{
|
||||
/// <summary>
|
||||
/// Handle the "Done" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void doneParsing(object source, TraceEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "Match" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void parserMatch(object source, MatchEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "MatchNot" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void parserMatchNot(object source, MatchEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "MisMatch" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void parserMismatch(object source, MatchEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "MisMatchNot" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void parserMismatchNot(object source, MatchEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void refresh()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
56
src/Spring/Spring.Core/antlr/debug/ParserReporter.cs
Normal file
56
src/Spring/Spring.Core/antlr/debug/ParserReporter.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public class ParserReporter : Tracer, ParserListener
|
||||
{
|
||||
public virtual void parserConsume(object source, TokenEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(indentString + e);
|
||||
}
|
||||
public virtual void parserLA(object source, TokenEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(indentString + e);
|
||||
}
|
||||
public virtual void parserMatch(object source, MatchEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(indentString + e);
|
||||
}
|
||||
public virtual void parserMatchNot(object source, MatchEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(indentString + e);
|
||||
}
|
||||
public virtual void parserMismatch(object source, MatchEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(indentString + e);
|
||||
}
|
||||
public virtual void parserMismatchNot(object source, MatchEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(indentString + e);
|
||||
}
|
||||
public virtual void reportError(object source, MessageEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(indentString + e);
|
||||
}
|
||||
public virtual void reportWarning(object source, MessageEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(indentString + e);
|
||||
}
|
||||
public virtual void semanticPredicateEvaluated(object source, SemanticPredicateEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(indentString + e);
|
||||
}
|
||||
public virtual void syntacticPredicateFailed(object source, SyntacticPredicateEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(indentString + e);
|
||||
}
|
||||
public virtual void syntacticPredicateStarted(object source, SyntacticPredicateEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(indentString + e);
|
||||
}
|
||||
public virtual void syntacticPredicateSucceeded(object source, SyntacticPredicateEventArgs e)
|
||||
{
|
||||
System.Console.Out.WriteLine(indentString + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
51
src/Spring/Spring.Core/antlr/debug/ParserTokenEventArgs.cs
Normal file
51
src/Spring/Spring.Core/antlr/debug/ParserTokenEventArgs.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public class TokenEventArgs : ANTLREventArgs
|
||||
{
|
||||
public TokenEventArgs()
|
||||
{
|
||||
}
|
||||
public TokenEventArgs(int type, int amount, int val)
|
||||
{
|
||||
setValues(type, amount, val);
|
||||
}
|
||||
|
||||
public virtual int Amount
|
||||
{
|
||||
get { return amount; }
|
||||
set { this.amount = value; }
|
||||
}
|
||||
|
||||
public virtual int Value
|
||||
{
|
||||
get { return this.value_; }
|
||||
set { this.value_ = value; }
|
||||
}
|
||||
|
||||
private int value_;
|
||||
private int amount;
|
||||
|
||||
public static int LA = 0;
|
||||
public static int CONSUME = 1;
|
||||
|
||||
|
||||
/// <summary>This should NOT be called from anyone other than ParserEventSupport!
|
||||
/// </summary>
|
||||
internal void setValues(int type, int amount, int val)
|
||||
{
|
||||
base.setValues(type);
|
||||
this.Amount = amount;
|
||||
this.Value = val;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (Type == LA)
|
||||
return "ParserTokenEvent [LA," + Amount + "," + Value + "]";
|
||||
else
|
||||
return "ParserTokenEvent [consume,1," + Value + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/Spring/Spring.Core/antlr/debug/ParserTokenListener.cs
Normal file
10
src/Spring/Spring.Core/antlr/debug/ParserTokenListener.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface ParserTokenListener : Listener
|
||||
{
|
||||
void parserConsume (object source, TokenEventArgs e);
|
||||
void parserLA (object source, TokenEventArgs e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an abstract base for implementing <see cref="ParserTokenListener"/> subclasses.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <param>
|
||||
/// This abstract class is provided to make it easier to create <see cref="ParserTokenListener"/>s.
|
||||
/// You should extend this base class rather than creating your own.
|
||||
/// </param>
|
||||
/// </remarks>
|
||||
public abstract class ParserTokenListenerBase : ParserTokenListener
|
||||
{
|
||||
/// <summary>
|
||||
/// Handle the "Done" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void doneParsing(object source, TraceEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void refresh()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "Consume" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void parserConsume(object source, TokenEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the "ParserLA" event.
|
||||
/// </summary>
|
||||
/// <param name="source">Event source object</param>
|
||||
/// <param name="e">Event data object</param>
|
||||
public virtual void parserLA(object source, TokenEventArgs e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
484
src/Spring/Spring.Core/antlr/debug/ScannerEventSupport.cs
Normal file
484
src/Spring/Spring.Core/antlr/debug/ScannerEventSupport.cs
Normal file
@@ -0,0 +1,484 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Hashtable = System.Collections.Hashtable;
|
||||
using ArrayList = System.Collections.ArrayList;
|
||||
|
||||
using antlr.collections.impl;
|
||||
|
||||
|
||||
/// <summary>A class to assist in firing parser events
|
||||
/// NOTE: I intentionally _did_not_ synchronize the event firing and
|
||||
/// add/remove listener methods. This is because the add/remove should
|
||||
/// _only_ be called by the parser at its start/end, and the _same_thread_
|
||||
/// should be performing the parsing. This should help performance a tad...
|
||||
/// </summary>
|
||||
public class ScannerEventSupport
|
||||
{
|
||||
private object source;
|
||||
private Hashtable listeners;
|
||||
private MatchEventArgs matchEvent;
|
||||
private MessageEventArgs messageEvent;
|
||||
private TokenEventArgs tokenEvent;
|
||||
private SemanticPredicateEventArgs semPredEvent;
|
||||
private SyntacticPredicateEventArgs synPredEvent;
|
||||
private TraceEventArgs traceEvent;
|
||||
private NewLineEventArgs newLineEvent;
|
||||
//private ParserController controller;
|
||||
|
||||
private int ruleDepth = 0;
|
||||
|
||||
|
||||
public ScannerEventSupport(object source)
|
||||
{
|
||||
matchEvent = new MatchEventArgs();
|
||||
messageEvent = new MessageEventArgs();
|
||||
tokenEvent = new TokenEventArgs();
|
||||
traceEvent = new TraceEventArgs();
|
||||
semPredEvent = new SemanticPredicateEventArgs();
|
||||
synPredEvent = new SyntacticPredicateEventArgs();
|
||||
newLineEvent = new NewLineEventArgs();
|
||||
listeners = new Hashtable();
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public virtual void checkController()
|
||||
{
|
||||
//if (controller != null)
|
||||
// controller.checkBreak();
|
||||
}
|
||||
|
||||
public virtual void addDoneListener(Listener l)
|
||||
{
|
||||
((CharScanner)source).Done += new TraceEventHandler(l.doneParsing);
|
||||
listeners[l] = l;
|
||||
}
|
||||
public virtual void addMessageListener(MessageListener l)
|
||||
{
|
||||
((CharScanner)source).ErrorReported += new MessageEventHandler(l.reportError);
|
||||
((CharScanner)source).WarningReported += new MessageEventHandler(l.reportWarning);
|
||||
addDoneListener(l);
|
||||
}
|
||||
public virtual void addNewLineListener(NewLineListener l)
|
||||
{
|
||||
((CharScanner)source).HitNewLine += new NewLineEventHandler(l.hitNewLine);
|
||||
addDoneListener(l);
|
||||
}
|
||||
public virtual void addParserListener(ParserListener l)
|
||||
{
|
||||
if (l is ParserController)
|
||||
{
|
||||
//((ParserController) l).ParserEventSupport = this;
|
||||
//controller = (ParserController) l;
|
||||
}
|
||||
addParserMatchListener(l);
|
||||
addParserTokenListener(l);
|
||||
|
||||
addMessageListener(l);
|
||||
addTraceListener(l);
|
||||
addSemanticPredicateListener(l);
|
||||
addSyntacticPredicateListener(l);
|
||||
}
|
||||
public virtual void addParserMatchListener(ParserMatchListener l)
|
||||
{
|
||||
((CharScanner)source).MatchedChar += new MatchEventHandler(l.parserMatch);
|
||||
((CharScanner)source).MatchedNotChar += new MatchEventHandler(l.parserMatchNot);
|
||||
((CharScanner)source).MisMatchedChar += new MatchEventHandler(l.parserMismatch);
|
||||
((CharScanner)source).MisMatchedNotChar += new MatchEventHandler(l.parserMismatchNot);
|
||||
addDoneListener(l);
|
||||
}
|
||||
public virtual void addParserTokenListener(ParserTokenListener l)
|
||||
{
|
||||
((CharScanner)source).ConsumedChar += new TokenEventHandler(l.parserConsume);
|
||||
((CharScanner)source).CharLA += new TokenEventHandler(l.parserLA);
|
||||
addDoneListener(l);
|
||||
}
|
||||
public virtual void addSemanticPredicateListener(SemanticPredicateListener l)
|
||||
{
|
||||
((CharScanner)source).SemPredEvaluated += new SemanticPredicateEventHandler(l.semanticPredicateEvaluated);
|
||||
addDoneListener(l);
|
||||
}
|
||||
public virtual void addSyntacticPredicateListener(SyntacticPredicateListener l)
|
||||
{
|
||||
((CharScanner)source).SynPredStarted += new SyntacticPredicateEventHandler(l.syntacticPredicateStarted);
|
||||
((CharScanner)source).SynPredFailed += new SyntacticPredicateEventHandler(l.syntacticPredicateFailed);
|
||||
((CharScanner)source).SynPredSucceeded += new SyntacticPredicateEventHandler(l.syntacticPredicateSucceeded);
|
||||
addDoneListener(l);
|
||||
}
|
||||
public virtual void addTraceListener(TraceListener l)
|
||||
{
|
||||
((CharScanner)source).EnterRule += new TraceEventHandler(l.enterRule);
|
||||
((CharScanner)source).ExitRule += new TraceEventHandler(l.exitRule);
|
||||
addDoneListener(l);
|
||||
}
|
||||
public virtual void fireConsume(int c)
|
||||
{
|
||||
TokenEventHandler eventDelegate = (TokenEventHandler)((CharScanner)source).Events[Parser.LAEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
tokenEvent.setValues(TokenEventArgs.CONSUME, 1, c);
|
||||
eventDelegate(source, tokenEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireDoneParsing()
|
||||
{
|
||||
TraceEventHandler eventDelegate = (TraceEventHandler)((CharScanner)source).Events[Parser.DoneEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
traceEvent.setValues(TraceEventArgs.DONE_PARSING, 0, 0, 0);
|
||||
eventDelegate(source, traceEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireEnterRule(int ruleNum, int guessing, int data)
|
||||
{
|
||||
ruleDepth++;
|
||||
TraceEventHandler eventDelegate = (TraceEventHandler)((CharScanner)source).Events[Parser.EnterRuleEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
traceEvent.setValues(TraceEventArgs.ENTER, ruleNum, guessing, data);
|
||||
eventDelegate(source, traceEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireExitRule(int ruleNum, int guessing, int data)
|
||||
{
|
||||
TraceEventHandler eventDelegate = (TraceEventHandler)((CharScanner)source).Events[Parser.ExitRuleEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
traceEvent.setValues(TraceEventArgs.EXIT, ruleNum, guessing, data);
|
||||
eventDelegate(source, traceEvent);
|
||||
}
|
||||
checkController();
|
||||
|
||||
ruleDepth--;
|
||||
if (ruleDepth == 0)
|
||||
fireDoneParsing();
|
||||
|
||||
}
|
||||
public virtual void fireLA(int k, int la)
|
||||
{
|
||||
TokenEventHandler eventDelegate = (TokenEventHandler)((CharScanner)source).Events[Parser.LAEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
tokenEvent.setValues(TokenEventArgs.LA, k, la);
|
||||
eventDelegate(source, tokenEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatch(char c, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR, c, c, null, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatch(char c, BitSet b, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR_BITSET, c, b, null, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatch(char c, string target, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR_RANGE, c, target, null, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatch(int c, BitSet b, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.BITSET, c, b, text, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatch(int n, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.TOKEN, n, n, text, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatch(string s, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.STRING, 0, s, null, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatchNot(char c, char n, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MatchNotEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR, c, n, null, guessing, true, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMatchNot(int c, int n, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MatchNotEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.TOKEN, c, n, text, guessing, true, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatch(char c, char n, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MisMatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR, c, n, null, guessing, false, false);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatch(char c, BitSet b, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MisMatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR_BITSET, c, b, null, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatch(char c, string target, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MisMatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR_RANGE, c, target, null, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatch(int i, int n, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MisMatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.TOKEN, i, n, text, guessing, false, false);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatch(int i, BitSet b, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MisMatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.BITSET, i, b, text, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatch(string s, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MisMatchEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.STRING, 0, text, s, guessing, false, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatchNot(char v, char c, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MisMatchNotEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.CHAR, v, c, null, guessing, true, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireMismatchNot(int i, int n, string text, int guessing)
|
||||
{
|
||||
MatchEventHandler eventDelegate = (MatchEventHandler)((CharScanner)source).Events[Parser.MisMatchNotEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
matchEvent.setValues(MatchEventArgs.TOKEN, i, n, text, guessing, true, true);
|
||||
eventDelegate(source, matchEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireNewLine(int line)
|
||||
{
|
||||
NewLineEventHandler eventDelegate = (NewLineEventHandler)((CharScanner)source).Events[Parser.NewLineEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
newLineEvent.Line = line;
|
||||
eventDelegate(source, newLineEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireReportError(System.Exception e)
|
||||
{
|
||||
MessageEventHandler eventDelegate = (MessageEventHandler)((CharScanner)source).Events[Parser.ReportErrorEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
messageEvent.setValues(MessageEventArgs.ERROR, e.ToString());
|
||||
eventDelegate(source, messageEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireReportError(string s)
|
||||
{
|
||||
MessageEventHandler eventDelegate = (MessageEventHandler)((CharScanner)source).Events[Parser.ReportErrorEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
messageEvent.setValues(MessageEventArgs.ERROR, s);
|
||||
eventDelegate(source, messageEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireReportWarning(string s)
|
||||
{
|
||||
MessageEventHandler eventDelegate = (MessageEventHandler)((CharScanner)source).Events[Parser.ReportWarningEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
messageEvent.setValues(MessageEventArgs.WARNING, s);
|
||||
eventDelegate(source, messageEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual bool fireSemanticPredicateEvaluated(int type, int condition, bool result, int guessing)
|
||||
{
|
||||
SemanticPredicateEventHandler eventDelegate = (SemanticPredicateEventHandler)((CharScanner)source).Events[Parser.SemPredEvaluatedEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
semPredEvent.setValues(type, condition, result, guessing);
|
||||
eventDelegate(source, semPredEvent);
|
||||
}
|
||||
checkController();
|
||||
|
||||
return result;
|
||||
}
|
||||
public virtual void fireSyntacticPredicateFailed(int guessing)
|
||||
{
|
||||
SyntacticPredicateEventHandler eventDelegate = (SyntacticPredicateEventHandler)((CharScanner)source).Events[Parser.SynPredFailedEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
synPredEvent.setValues(0, guessing);
|
||||
eventDelegate(source, synPredEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireSyntacticPredicateStarted(int guessing)
|
||||
{
|
||||
SyntacticPredicateEventHandler eventDelegate = (SyntacticPredicateEventHandler)((CharScanner)source).Events[Parser.SynPredStartedEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
synPredEvent.setValues(0, guessing);
|
||||
eventDelegate(source, synPredEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void fireSyntacticPredicateSucceeded(int guessing)
|
||||
{
|
||||
SyntacticPredicateEventHandler eventDelegate = (SyntacticPredicateEventHandler)((CharScanner)source).Events[Parser.SynPredSucceededEventKey];
|
||||
if (eventDelegate != null)
|
||||
{
|
||||
synPredEvent.setValues(0, guessing);
|
||||
eventDelegate(source, synPredEvent);
|
||||
}
|
||||
checkController();
|
||||
}
|
||||
public virtual void refreshListeners()
|
||||
{
|
||||
Hashtable clonedTable;
|
||||
|
||||
lock(listeners.SyncRoot)
|
||||
{
|
||||
clonedTable = (Hashtable)listeners.Clone();
|
||||
}
|
||||
foreach (Listener l in clonedTable)
|
||||
{
|
||||
l.refresh();
|
||||
}
|
||||
}
|
||||
public virtual void removeDoneListener(Listener l)
|
||||
{
|
||||
((CharScanner)source).Done -= new TraceEventHandler(l.doneParsing);
|
||||
listeners.Remove(l);
|
||||
}
|
||||
public virtual void removeMessageListener(MessageListener l)
|
||||
{
|
||||
((CharScanner)source).ErrorReported -= new MessageEventHandler(l.reportError);
|
||||
((CharScanner)source).WarningReported -= new MessageEventHandler(l.reportWarning);
|
||||
removeDoneListener(l);
|
||||
}
|
||||
public virtual void removeNewLineListener(NewLineListener l)
|
||||
{
|
||||
((CharScanner)source).HitNewLine -= new NewLineEventHandler(l.hitNewLine);
|
||||
removeDoneListener(l);
|
||||
}
|
||||
public virtual void removeParserListener(ParserListener l)
|
||||
{
|
||||
removeParserMatchListener(l);
|
||||
removeMessageListener(l);
|
||||
removeParserTokenListener(l);
|
||||
removeTraceListener(l);
|
||||
removeSemanticPredicateListener(l);
|
||||
removeSyntacticPredicateListener(l);
|
||||
}
|
||||
public virtual void removeParserMatchListener(ParserMatchListener l)
|
||||
{
|
||||
((CharScanner)source).MatchedChar -= new MatchEventHandler(l.parserMatch);
|
||||
((CharScanner)source).MatchedNotChar -= new MatchEventHandler(l.parserMatchNot);
|
||||
((CharScanner)source).MisMatchedChar -= new MatchEventHandler(l.parserMismatch);
|
||||
((CharScanner)source).MisMatchedNotChar -= new MatchEventHandler(l.parserMismatchNot);
|
||||
removeDoneListener(l);
|
||||
}
|
||||
public virtual void removeParserTokenListener(ParserTokenListener l)
|
||||
{
|
||||
((CharScanner)source).ConsumedChar -= new TokenEventHandler(l.parserConsume);
|
||||
((CharScanner)source).CharLA -= new TokenEventHandler(l.parserLA);
|
||||
removeDoneListener(l);
|
||||
}
|
||||
public virtual void removeSemanticPredicateListener(SemanticPredicateListener l)
|
||||
{
|
||||
((CharScanner)source).SemPredEvaluated -= new SemanticPredicateEventHandler(l.semanticPredicateEvaluated);
|
||||
removeDoneListener(l);
|
||||
}
|
||||
public virtual void removeSyntacticPredicateListener(SyntacticPredicateListener l)
|
||||
{
|
||||
((CharScanner)source).SynPredStarted -= new SyntacticPredicateEventHandler(l.syntacticPredicateStarted);
|
||||
((CharScanner)source).SynPredFailed -= new SyntacticPredicateEventHandler(l.syntacticPredicateFailed);
|
||||
((CharScanner)source).SynPredSucceeded -= new SyntacticPredicateEventHandler(l.syntacticPredicateSucceeded);
|
||||
removeDoneListener(l);
|
||||
}
|
||||
public virtual void removeTraceListener(TraceListener l)
|
||||
{
|
||||
((CharScanner)source).EnterRule -= new TraceEventHandler(l.enterRule);
|
||||
((CharScanner)source).ExitRule -= new TraceEventHandler(l.exitRule);
|
||||
removeDoneListener(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public class SemanticPredicateEventArgs : GuessingEventArgs
|
||||
{
|
||||
public SemanticPredicateEventArgs()
|
||||
{
|
||||
}
|
||||
public SemanticPredicateEventArgs(int type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual int Condition
|
||||
{
|
||||
get { return this.condition_; }
|
||||
set { this.condition_ = value; }
|
||||
}
|
||||
|
||||
public virtual bool Result
|
||||
{
|
||||
get { return this.result_; }
|
||||
set { this.result_ = value; }
|
||||
}
|
||||
|
||||
public const int VALIDATING = 0;
|
||||
public const int PREDICTING = 1;
|
||||
|
||||
private int condition_;
|
||||
private bool result_;
|
||||
|
||||
|
||||
/// <summary>This should NOT be called from anyone other than ParserEventSupport!
|
||||
/// </summary>
|
||||
internal void setValues(int type, int condition, bool result, int guessing)
|
||||
{
|
||||
base.setValues(type, guessing);
|
||||
this.Condition = condition;
|
||||
this.Result = result;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "SemanticPredicateEvent [" + Condition + "," + Result + "," + Guessing + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace antlr.debug
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface SemanticPredicateListener : Listener
|
||||
{
|
||||
void semanticPredicateEvaluated(object source, SemanticPredicateEventArgs e);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user