// Public domain // YARD grammar for the Cat languages // by Christopher Diggins // http://www.cat-language.com #ifndef CAT_GRAMMAR_HPP #define CAT_GRAMMAR_HPP namespace cat_grammar { using namespace yard; using namespace text_grammar; // Forward declarations, used for recursive definitions struct FxnType; struct Expr; // AST node labels struct LiteralLabel { static const int id = 0; }; struct QuotationLabel { static const int id = 1; }; struct KindVarLabel { static const int id = 2; }; struct NamedTypeLabel { static const int id = 3; }; struct FxnTypeLabel { static const int id = 4; }; struct CatWordLabel { static const int id = 5; }; struct ExprLabel { static const int id = 6; }; struct DefLabel { static const int id = 7; }; struct ArrowLabel { static const int id = 8; }; struct TypeVectorLabel { static const int id = 9; }; // Character sets struct CatWordSymbolCharSet : CharSet<'~', '`', '!', '@', '#', '$', '%', '^', '&', '*', '_', '+', '-', '=', '\\', ':', ';', '<', '>', '.', '?', '/'> { }; struct CatWordFirstCharSet : CharSetUnion { }; struct CatWordNextCharSet : CharSetUnion { }; // Grammar rules struct LineComment : FinaoIf, UntilPast > > { }; struct FullComment : FinaoIf, UntilPast > > { }; struct Comment : Or { }; struct WS : Star, Comment> > { }; struct StringCharLiteral : Or, AnyChar>, NotChar<'\''> > { }; struct CharLiteral : FinaoIf, Seq > > { }; struct StringLiteral : FinaoIf, Seq, ExpectChar<'\"'> > > { }; struct BinaryDigit : Or, Char<'1'> > { }; struct BinNumber : Seq, Plus, NotAlphaNum, WS> { }; struct HexNumber : Seq, Plus, NotAlphaNum, WS> { }; struct DecNumber : Seq >, Plus, Opt, Star > >, NotAlphaNum, WS> { }; struct Literal : Seq >, WS> { }; struct TypeConstraint : FinaoIf, Seq > { }; struct NamedType : StoreIf, Seq > > { }; struct CatWordFirstChar : CharSetParser { }; struct CatWordNextChar : CharSetParser { }; struct SingleCharCatWord : Or, Char<')'>, Char<','> > { }; struct MultiCharCatWord : Seq > { }; struct CatWord : Store > { }; struct Quotation : StoreIf >, Seq, Star, ExpectChar<']'> > > { }; struct Expr : Store, WS> > { }; struct KindVar : StoreIf, Ident> { }; struct Type : Seq, WS> { }; struct FxnBody : FinaoIf, Seq, WS, ExpectChar<'}'>, WS > > { }; struct Arrow : Store'>, CharSeq<'-', '>'> > > { }; struct TypeVector : Store > { }; struct FxnType : StoreIf, Seq, WS > > { }; struct FxnTypeDecl : FinaoIf, Seq > { }; struct DefineKeyword : Seq >, WS> { }; struct Def : StoreIf, FxnBody> > { }; struct SourceFile : Star > { }; } #endif // CAT_GRAMMAR_HPP