Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/NHibernate.Test/Hql/Parser/HqlParserFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Antlr.Runtime;
using NHibernate.Hql.Ast.ANTLR;
using NHibernate.Hql.Ast.ANTLR.Tree;
using NUnit.Framework;

namespace NHibernate.Test.Hql.Parser
{
[TestFixture]
public class HqlParserFixture
{
[Test]
public void HandlesPathWithReservedWords()
{
Assert.DoesNotThrow(() => Parse("delete from System.Object"));
Assert.DoesNotThrow(() => Parse("delete from Object.Object.Object.Object"));
}

private static void Parse(string hql)
{
var lex = new HqlLexer(new CaseInsensitiveStringStream(hql));
var tokens = new CommonTokenStream(lex);

var parser = new HqlParser(tokens)
{
TreeAdaptor = new ASTTreeAdaptor(),
ParseErrorHandler = new WarningAsErrorReporter()
}.statement();
}
}
}
29 changes: 29 additions & 0 deletions src/NHibernate.Test/Hql/Parser/WarningAsErrorReporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Antlr.Runtime;
using NHibernate.Hql.Ast.ANTLR;

namespace NHibernate.Test.Hql.Parser
{
public class WarningAsErrorReporter : IParseErrorHandler
{
public void ReportError(RecognitionException e)
{
throw e;
}

public void ReportError(string s)
{
throw new QueryException(s);
}

public void ReportWarning(string s)
{
throw new QueryException(s);
}

public int GetErrorCount() => 0;

public void ThrowQueryException()
{
}
}
}
3 changes: 3 additions & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<Compile Remove="**\NHSpecificTest\NH3121\**" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\NHibernate\Hql\Ast\ANTLR\CaseInsensitiveStringStream.cs">
<Link>Hql\Parser\CaseInsensitiveStringStream.cs</Link>
</Compile>
<Compile Include="..\NHibernate\Util\AsyncReaderWriterLock.cs">
<Link>UtilityTest\AsyncReaderWriterLock.cs</Link>
</Compile>
Expand Down
5 changes: 2 additions & 3 deletions src/NHibernate/Hql/Ast/ANTLR/Hql.g
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,9 @@ constant

path
@init {
// TODO - need to clean up DotIdent - suspect that DotIdent2 supersedes the other one, but need to do the analysis
//HandleDotIdent2();
HandleDotIdents();
}
: identifier ( DOT^ { WeakKeywords(); } identifier )*
: identifier ( DOT^ identifier )*
;

// Wraps the IDENT token from the lexer, in order to provide
Expand Down
21 changes: 21 additions & 0 deletions src/NHibernate/Hql/Ast/ANTLR/HqlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ protected override object RecoverFromMismatchedToken(IIntStream input, int ttype
throw new MismatchedTokenException(ttype, input);
}

public void HandleDotIdents()
{
int i = 2;

while (input.LA(i) == DOT)
{
var next = input.LT(i + 1);
if (next != null)
next.Type = IDENT;
i += 2;
}

if (input.LA(1) == IDENT || input.LA(2) != DOT)
return;

if (IsPossibleId(input.LT(1)))
{
input.LT(1).Type = IDENT;
}
}

public void WeakKeywords()
{
int t = input.LA(1);
Expand Down