SwiftStudies / OysterKit

OysterKit is a framework that provides a native Swift scanning, lexical analysis, and parsing capabilities. In addition it provides a language that can be used to rapidly define the rules used by OysterKit called STLR
BSD 2-Clause "Simplified" License
177 stars 23 forks source link

Bork example errors with preposition #64

Closed wess closed 6 years ago

wess commented 6 years ago

I pulled the Bork repo, as well as my own, and when I run the example: "ATTACK SNAKE WITH SWORD" im getting the following error:

keyNotFound(CodingKeys(stringValue: "noun", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "secondSubject", intValue: nil)], debugDescription: "No value associated with key CodingKeys(stringValue: \"noun\", intValue: nil) (\"noun\").", underlyingError: nil))
// Lexer

@pin verb         = "INVENTORY" | "GO" | "PICKUP" | "DROP" | "ATTACK"
@pin noun         = "NORTH" | "SOUTH" | "KITTEN" | "SNAKE" | "CLUB" | "SWORD"
@pin adjective    = "FLUFFY" | "ANGRY" | "DEAD"
@pin preposition  = "WITH" | "USING"

// Commands
subject = (adjective .whitespace)? noun
command = verb (.whitespace subject (.whitespace preposition .whitespace @token("secondSubject") subject)? )?

Just like your tutorial.

Thanks!

SwiftStudies commented 6 years ago

Hum, I've just fixed up a number of issues in the core of STLR parsing, I'll check to see if this is what was causing the noun issues or if I've introduced a new issue....

Thanks for taking the time to report.

SwiftStudies commented 6 years ago

Eurgh. I see the bug. It has to do with the way overriding of instances of rules is being done meaning that although there is a secondSubject, that secondSubject contains subject which contains noun, and noun isn't being hoisted.

I need to decide if the new way of overriding is wrong, or the grammar should change.

I think it's the former :-/

SwiftStudies commented 6 years ago

The fix was required to the STLR compiler the Bork project uses to build the command parser. I have updated the Bork repository with the newly generated Bork grammar swift file and the OysterKit master branch has the fix to the compiler in it.