Synopsis - Synopsis/PTree/Atoms.hh

File: Synopsis/PTree/Atoms.hh

     1//
     2// Copyright (C) 2004 Stefan Seefeld
     3// All rights reserved.
     4// Licensed to the public under the terms of the GNU LGPL (>= 2),
     5// see the file COPYING for details.
     6//
     7#ifndef Synopsis_PTree_Atoms_hh_
     8#define Synopsis_PTree_Atoms_hh_
     9
    10#include <Synopsis/PTree/NodesFwd.hh>
    11#include <Synopsis/PTree/Node.hh>
    12
    13namespace Synopsis
    14{
    15namespace PTree
    16{
    17
    18class Literal : public Atom
    19{
    20public:
    21  Literal(Token const &tk) : Atom(tk), my_type(tk.type) {}
    22  virtual void accept(Visitor *visitor) { visitor->visit(this);}
    23  Token::Type type() const { return my_type;}
    24private:
    25  Token::Type my_type;
    26};
    27
    28class CommentedAtom : public Atom
    29{
    30public:
    31  CommentedAtom(Token const &tk, Node *c = 0) : Atom(tk), my_comments(c) {}
    32  CommentedAtom(char const *p, size_t l, Node *c = 0) : Atom(p, l), my_comments(c) {}
    33  virtual void accept(Visitor *visitor) { visitor->visit(this);}
    34
    35  Node *get_comments() { return my_comments;}
    36  void set_comments(Node *c) { my_comments = c;}
    37private:
    38  Node *my_comments;
    39};
    40
    41// class DupLeaf is used by Ptree::Make() and QuoteClass (qMake()).
    42// The string given to the constructors are duplicated.
    43
    44class DupAtom : public CommentedAtom
    45{
    46public:
    47  DupAtom(char const *, size_t);
    48  DupAtom(char const *, size_t, char const *, size_t);
    49  virtual void accept(Visitor *visitor) { visitor->visit(this);}
    50};
    51
    52class Identifier : public CommentedAtom
    53{
    54public:
    55  Identifier(Token const &t) : CommentedAtom(t) {}
    56  Identifier(char const *p, size_t l) : CommentedAtom(p, l) {}
    57  virtual void accept(Visitor *visitor) { visitor->visit(this);}
    58};
    59
    60class Keyword : public CommentedAtom
    61{
    62public:
    63  Keyword(Token const &t) : CommentedAtom(t) {}
    64  Keyword(char const *str, int len) : CommentedAtom(str, len) {}
    65  virtual Token::Type token() const = 0;
    66  virtual void accept(Visitor *visitor) { visitor->visit(this);}
    67};
    68
    69template <Token::Type t>
    70class KeywordT : public Keyword
    71{
    72public:
    73  KeywordT(Token const &tk) : Keyword(tk) {}
    74  KeywordT(char const *ptr, size_t length) : Keyword(ptr, length) {}
    75  virtual Token::Type token() const { return t;}
    76  virtual void accept(Visitor *visitor) { visitor->visit(this);}
    77};
    78
    79class UserKeyword : public Keyword
    80{
    81public:
    82  UserKeyword(Token const &t) : Keyword(t) {}
    83  virtual Token::Type token() const { return my_type;}
    84  virtual void accept(Visitor *visitor) { visitor->visit(this);}
    85private:
    86  Token::Type my_type;
    87};
    88
    89}
    90}
    91
    92#endif

Generated on Thu Apr 16 16:28:03 2009 by
synopsis (version devel)