27 #ifndef PEGMATITE_PARSER_HPP 28 #define PEGMATITE_PARSER_HPP 65 static const Index npos =
static_cast<Index
>(-1);
69 class iterator :
public std::iterator<std::bidirectional_iterator_tag, char32_t>
99 inline char32_t
operator*()
const {
return (*buffer)[idx]; }
140 return (buffer == other.buffer) && (idx == other.idx);
147 return !(*
this == other);
154 return (idx > other.idx);
161 return (idx < other.idx);
168 return idx-other.idx;
192 const std::string&
name()
const 204 if ((n >= buffer_start) && (n < buffer_end))
206 return buffer[n - buffer_start];
208 return slowCharacterLookup(n);
218 : user_name(name), buffer(0), buffer_start(1), buffer_end(0) {}
224 const std::string user_name;
247 char32_t slowCharacterLookup(Index n);
261 virtual bool fillBuffer(Index start, Index &length, char32_t *&b) = 0;
265 virtual Index
size()
const = 0;
284 const std::vector<char32_t> vector;
291 const std::vector<char32_t> &
getVector() {
return vector; }
351 StreamInput(
const std::string& name, std::istream&,
size_t len);
354 std::istream& stream;
366 const std::string str;
418 if (start > std::distance(begin, end))
424 for (T i=std::advance(begin, start) ; (i !=
end) && (copied < length) ; ++i)
426 b[copied++] =
static_cast<char32_t
>(*i);
434 Index size()
const override {
return std::distance(begin, end); }
494 std::string str()
const;
506 typedef std::function<bool(const InputRange&, void*)> parse_proc;
510 typedef std::function<void (const InputRange&, const std::string&)> ErrorReporter;
516 typedef std::shared_ptr<CharacterExpr> CharacterExprPtr;
535 ExprPtr(
const CharacterExprPtr &e);
590 friend class Context;
614 virtual bool parse_non_term(Context &con)
const = 0;
620 virtual bool parse_term(Context &con)
const = 0;
625 virtual void dump()
const = 0;
674 CharacterExprPtr
operator "" _E(
const char x);
675 CharacterExprPtr
operator "" _E(
const char32_t x);
679 ExprPtr operator "" _S(
const char *x, std::size_t len);
683 ExprPtr operator "" _E(
const char *x, std::size_t len);
687 ExprPtr operator "" _R(
const char *x, std::size_t len);
688 ExprPtr operator-(
const CharacterExprPtr &left,
const CharacterExprPtr &right);
700 return trace_debug(msg, e);
745 ExprPtr regex(
const wchar_t *s);
760 ExprPtr range(char32_t min, char32_t max);
787 ExprPtr debug(std::function<
void()> fn);
798 virtual parse_proc get_parse_proc(
const Rule &)
const = 0;
815 bool parse(
Input &i,
const Rule &g,
const Rule &ws, ErrorReporter &err,
824 template <
class T> T &operator << (T &stream,
const InputRange &ir)
828 stream << static_cast<typename T::char_type>(c);
838 #endif //PEGMATITE_PARSER_HPP
Parser delegate abstract class.
Definition: parser.hh:793
Rule(const Rule &r)
Copying rules is not allowed.
Definition: parser.hh:569
A shared pointer to an expression.
Definition: parser.hh:522
const std::string & filename() const
user-meaningful filename.
Definition: parser.hh:445
Abstract base class for expressions.
Definition: parser.hh:596
int col
column.
Definition: parser.hh:451
Rule(const CharacterExprPtr e)
Constructor for creating rules from character expressions.
Definition: parser.hh:565
Rule class, which represents a rule in a grammar.
Definition: parser.hh:554
ExprPtr(Expr *e)
Construct an expression pointer wrapping an expression.
Definition: parser.hh:527
position into the input.
Definition: parser.hh:439
Input::iterator it
iterator into the input.
Definition: parser.hh:442
ParserPosition()
null constructor.
Definition: parser.hh:454
int line
line.
Definition: parser.hh:448