! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: peg peg.ebnf smalltalk.ast sequences sequences.deep strings math.parser kernel arrays byte-arrays math assocs ; IN: testing EBNF: parse-smalltalk WhitespaceCharacter = (" " | "\t" | "\n" | "\r" ) Letter = [A-Za-z] OptionalWhiteSpace = (WhitespaceCharacter)* Whitespace = (WhitespaceCharacter)+ Identifier = Letter* UnaryMessageSelector = Identifier Keyword = Identifier:i ":" BinarySelectorChar = "~" | "!" | "@" | "%" | "&" | "*" | "-" | "+" | "=" | "|" | "\" | "<" | ">" | "," | "?" | "/" BinaryMessageSelector = BinarySelectorChar+ Operand = "(" Expression ")" | Identifier UnaryMessage = UnaryMessageSelector UnaryMessageOperand = UnaryMessageSend | Operand UnaryMessageSend = UnaryMessageOperand:receiver OptionalWhiteSpace UnaryMessageSelector:selector !(":") BinaryMessage = BinaryMessageSelector OptionalWhiteSpace BinaryMessageOperand BinaryMessageOperand = BinaryMessageSend | UnaryMessageSend | Operand BinaryMessageSend-1 = BinaryMessageOperand:lhs OptionalWhiteSpace BinaryMessageSelector:selector OptionalWhiteSpace UnaryMessageOperand:rhs BinaryMessageSend = (BinaryMessageSend:lhs OptionalWhiteSpace BinaryMessageSelector:selector OptionalWhiteSpace UnaryMessageOperand:rhs) | BinaryMessageSend-1 KeywordMessageSegment = Keyword:k OptionalWhiteSpace BinaryMessageOperand:arg KeywordMessageSend = BinaryMessageOperand:receiver OptionalWhiteSpace KeywordMessageSegment:h (OptionalWhiteSpace KeywordMessageSegment:s)*:t Expression = KeywordMessageSend | BinaryMessageSend | UnaryMessageSend | Operand End = !(.) Program = Expression End ;EBNF "(a x + b) x" parse-smalltalk