EmbASP-CSharp
PDDLParser.cs
1 using System;
2 using System.Collections.Generic;
3 using Antlr4.Runtime;
4 using Antlr4.Runtime.Atn;
5 
7 {
8  public class PDDLParser : PDDLGrammarBaseVisitor<object>
9  {
10  private readonly List<string> parameters = new List<string>();
11 
12  private PDDLParser()
13  {
14 
15  }
16 
17  public static PDDLParser Parse(string action)
18  {
19  CommonTokenStream tokens = new CommonTokenStream(new PDDLGrammarLexer(CharStreams.fromstring(action)));
20  PDDLGrammarParser parser = new PDDLGrammarParser(tokens);
21  PDDLParser visitor = new PDDLParser();
22  parser.Interpreter.PredictionMode = PredictionMode.SLL;
23 
24  parser.RemoveErrorListeners();
25 
26  parser.ErrorHandler = new BailErrorStrategy();
27 
28  try
29  {
30  visitor.Visit(parser.output());
31  }
32  catch (SystemException exception)
33  {
34  if (exception.GetBaseException() is RecognitionException)
35  {
36  tokens.Seek(0);
37  parser.AddErrorListener(ConsoleErrorListener<object>.Instance);
38 
39  parser.ErrorHandler = new DefaultErrorStrategy();
40  parser.Interpreter.PredictionMode = PredictionMode.LL;
41 
42  visitor.Visit(parser.output());
43  }
44  }
45 
46  return visitor;
47  }
48 
49  public string[] GetParameters()
50  {
51  return parameters.ToArray();
52  }
53 
54  public override object VisitAtom(PDDLGrammarParser.AtomContext context)
55  {
56  for (int index = 1; index < context.IDENTIFIER().Length; index++)
57  parameters.Add(context.IDENTIFIER()[index].GetText());
58 
59  return null;
60  }
61  }
62 }
it.unical.mat.parsers.pddl.PDDLParser.VisitAtom
override object VisitAtom(PDDLGrammarParser.AtomContext context)
Visit a parse tree produced by PDDLGrammarParser.atom.
Definition: PDDLParser.cs:54
PDDLGrammarParser
Definition: PDDLGrammarParser.cs:35
it.unical.mat.parsers.pddl.PDDLParser
Definition: PDDLParser.cs:8
PDDLGrammarParser.AtomContext
Definition: PDDLGrammarParser.cs:83
it.unical.mat.parsers.pddl
Definition: IPDDLDataCollection.cs:1
PDDLGrammarBaseVisitor
This class provides an empty implementation of IPDDLGrammarVisitor<Result>, which can be extended to ...
Definition: PDDLGrammarBaseVisitor.cs:35