This repository was archived by the owner on May 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Whoa there!
You have triggered an abuse detection mechanism.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
Showing
6 changed files
with
198 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using JetBrains.Annotations; | ||
using PDDL.Model.Pddl12; | ||
using PDDL.Parser.Pddl12; | ||
using Sprache; | ||
|
||
namespace PDDL.Parser | ||
{ | ||
/// <summary> | ||
/// Class PDDL12Parser. This class cannot be inherited. | ||
/// </summary> | ||
public sealed class PDDL12Parser | ||
{ | ||
/// <summary> | ||
/// Parses the specified definition. | ||
/// </summary> | ||
/// <param name="definition">The definition.</param> | ||
/// <returns>IReadOnlyList<IDefinition>.</returns> | ||
/// <exception cref="PDDLSyntaxException">A syntax error or internal parser error occurred. </exception> | ||
public IReadOnlyList<IDefinition> Parse(string definition) | ||
{ | ||
// strip all comments | ||
definition = RemoveAllComments(definition); | ||
|
||
// run the actual parsers | ||
try | ||
{ | ||
var enumeration = DefineGrammar.MultiDefineDefinition.Parse(definition); | ||
return enumeration.ToList(); | ||
} | ||
catch (ParseException e) | ||
{ | ||
throw new PDDLSyntaxException(e.Message, e); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Removes all comments. | ||
/// </summary> | ||
/// <param name="source">The source.</param> | ||
/// <returns>System.String.</returns> | ||
private static string RemoveAllComments(string source) | ||
{ | ||
using (var reader = new StringReader(source)) | ||
{ | ||
return RemoveAllComments(reader); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Removes all comments. | ||
/// </summary> | ||
/// <param name="reader">The reader.</param> | ||
/// <returns>System.String.</returns> | ||
private static string RemoveAllComments([NotNull] StringReader reader) | ||
{ | ||
var sb = new StringBuilder(); | ||
|
||
string line; | ||
while (null != (line = reader.ReadLine())) | ||
{ | ||
// check for semicolons and, if none found, simply register the line | ||
var index = line.IndexOf(';'); | ||
if (index < 0) | ||
{ | ||
sb.AppendLine(line); | ||
continue; | ||
} | ||
|
||
// if a semicolon was found, read until there and replace it with a single whitespace | ||
// (as per language description) | ||
sb.Append(line.Substring(0, index)); | ||
sb.AppendLine(" "); | ||
} | ||
|
||
return sb.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Runtime.Serialization; | ||
|
||
namespace PDDL.Parser | ||
{ | ||
/// <summary> | ||
/// Class PDDLParserException. | ||
/// </summary> | ||
[Serializable] | ||
public class PDDLParserException : Exception | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PDDLParserException"/> class. | ||
/// </summary> | ||
public PDDLParserException() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PDDLParserException" /> class with a specified error message. | ||
/// </summary> | ||
/// <param name="message">The message that describes the error.</param> | ||
public PDDLParserException(string message) : base(message) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PDDLParserException"/> class. | ||
/// </summary> | ||
/// <param name="message">The message.</param> | ||
/// <param name="inner">The inner.</param> | ||
public PDDLParserException(string message, Exception inner) : base(message, inner) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PDDLParserException" /> class with serialized data. | ||
/// </summary> | ||
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param> | ||
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination.</param> | ||
protected PDDLParserException( | ||
SerializationInfo info, | ||
StreamingContext context) : base(info, context) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Runtime.Serialization; | ||
|
||
namespace PDDL.Parser | ||
{ | ||
/// <summary> | ||
/// Class PDDLSyntaxException. | ||
/// </summary> | ||
[Serializable] | ||
public class PDDLSyntaxException : PDDLParserException | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PDDLSyntaxException"/> class. | ||
/// </summary> | ||
public PDDLSyntaxException() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PDDLSyntaxException" /> class with a specified error message. | ||
/// </summary> | ||
/// <param name="message">The message that describes the error.</param> | ||
public PDDLSyntaxException(string message) : base(message) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PDDLSyntaxException"/> class. | ||
/// </summary> | ||
/// <param name="message">The message.</param> | ||
/// <param name="inner">The inner.</param> | ||
public PDDLSyntaxException(string message, Exception inner) : base(message, inner) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PDDLSyntaxException" /> class with serialized data. | ||
/// </summary> | ||
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param> | ||
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination.</param> | ||
protected PDDLSyntaxException( | ||
SerializationInfo info, | ||
StreamingContext context) : base(info, context) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters