~ubuntu-branches/ubuntu/wily/aspectc++/wily

« back to all changes in this revision

Viewing changes to Puma/src/parser/Syntax.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2009-06-15 10:17:02 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090615101702-qsr30iptwbxylmo2
Tags: 1.0pre4~svn.20090615-1
* New upstream release.
* don't ignore errors in the postrm script
* avoid spurious creation of empty dir ./usr/sbin/
* improve short descriptions of libpuma-doc and libpuma-dev
* bump Standards-Version to 3.8.1
* bump debhelper compat level to level 7 (latest in stable)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
/** \file
23
23
 *  Basic syntactic analysis component. */
24
24
 
 
25
#include "Puma/Unit.h"
25
26
#include "Puma/Token.h"
26
27
#include "Puma/Builder.h"
27
28
#include "Puma/ErrorSink.h"
149
150
   *  \param n The number of tokens to look-ahead. 
150
151
   *  \return True if the n-th token has one of the given types. */
151
152
  bool look_ahead (int* token_types, unsigned n = 1);
152
 
  /** Look-ahead one core language token. 
 
153
  /** Look-ahead one core language token.
 
154
   *  \param n The number of tokens to look-ahead.
153
155
   *  \return The type of the next core language token. */
154
 
  inline int look_ahead () const;
 
156
  int look_ahead (unsigned n = 1);
155
157
  /** Consume all tokens until the next core language token. */
156
 
  inline bool consume ();
 
158
  bool consume ();
157
159
 
158
160
protected:
159
161
  /** Parse the given grammar rule. Saves the current state of 
258
260
   *  \param tree Tree to accept. 
259
261
   *  \param state The saved state. */
260
262
  bool accept (CTree *tree, State state);
 
263
  /** Accept the given syntax tree node. Returns the given node.
 
264
   *  \param tree Tree to accept. */
 
265
  CTree* accept (CTree *tree);
261
266
 
262
267
  /** Skip all non-core language tokens until the next 
263
268
   *  core-language token is read. 
324
329
}
325
330
 
326
331
 
327
 
inline int Syntax::look_ahead () const {
 
332
inline int Syntax::look_ahead (unsigned n) {
328
333
  Token *token = token_provider->current ();
 
334
  if (n > 1) {
 
335
    State s = token_provider->get_state ();
 
336
    for (unsigned i = 1; i < n; i++) {
 
337
      token_provider->next ();
 
338
      locate_token ();
 
339
    }
 
340
    token = token_provider->current ();
 
341
    token_provider->set_state (s);
 
342
  }
329
343
  return token ? token->type () : 0;
330
344
}
331
345
 
441
455
  builder ().Push (builder ().error ());
442
456
 
443
457
  // if there is no detailed error message generate a standard message
444
 
  if (index == ((ErrorCollector&)builder ().err ()).index ())
 
458
  if (index == ((ErrorCollector&)builder ().err ()).index ()) {
445
459
    builder ().err () << sev_error << token->location () << msg
446
460
      << " near token `" << token->text () << "'" << endMessage;
 
461
    // if the error is located in not a file unit, print the whole unit
 
462
    if (token->unit () && !token->unit ()->isFile ()) {
 
463
      builder ().err () << token->location () << "located in the following non-file unit:\n"
 
464
        << *token->unit() << endMessage;
 
465
    }
 
466
  }
447
467
 
448
468
  skip (skip_tokens, false);
449
469
  return true;