Created
January 27, 2015 04:59
-
-
Save primaryobjects/6f39bf5497b7f52cf17a to your computer and use it in GitHub Desktop.
PEGjs grammar for parsing a PDDL STRIPS domain problem.
This file contains hidden or 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
/* | |
pegjs grammar for parsing a PDDL STRIPS domain problem. Example problem: | |
(define (problem random-pbl1) | |
(:domain random-domain) | |
(:init | |
(S B B) (S C B) (S A C) | |
(R B B) (R C B)) | |
(:goal (and (S A A)))) | |
*/ | |
program = result:problem { return result; } | |
problem = space* delimiter* "define" space* delimiter* "problem" space* name:word delimiter* space* domain:domain space* states:state* | |
{ return { name: name.join('').replace(/[,:? ]/g, ''), domain: domain, states: states }; } | |
domain = ":domain" space* name:word delimiter* | |
{ return name.join('').replace(/[,:? ]/g, ''); } | |
state = space* delimiter* ":" name:word space* delimiter* actions:logic* | |
{ return { name: name.join('').replace(/[,:? ]/g, ''), actions: actions }; } | |
logic = operation:logicOp* delimiter* action:word space* params:parameter* delimiter* | |
{ return { operation: operation.join('').replace(/[,:? ]/g, ''), action: action.join('').replace(/[,:? ]/g, ''), parameters: params }; } | |
boolean = "#t" / "#f" | |
integer = [1-9] [0-9]* | |
string = "\"" ("\\" . / [^"])* "\"" | |
word = word:([a-zA-Z0-9\-]+) { return word; } | |
symbol = (!delimiter .)+ | |
space = [\n\r\t ] | |
paren = "(" / ")" | |
logicOp = "and" / "not" | |
delimiter = paren / space | |
parameter = param:word space* | |
{ return param.join('').replace(/[,:? ]/g, ''); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment