Skip to content
Commits on Mar 14, 2014
  1. @blambeau
  2. @blambeau
  3. @blambeau

    Remove Match#method_missing, add Match#capture(name)

    blambeau committed
    Match#method_missing is unsafe as illustrated in Github issue #41.
    In particular, it makes composing a grammar with aribitrary gems
    unsafe when the latter make core extensions, leads to unexpected
    results with labels matching Kernel methods (e.g. `p`), and
    prevents the Match class from getting new methods in a backward
    compatible way. This commit therefore removes it.
    A convenient method is provided to get a single capture by label
    name. Calling string operators must now be done via Match#to_str.
  4. @blambeau

    Show why Match#method_missing is unsafe with a test.

    blambeau committed
    The added test case shows that Kernel::p is actually called in place
    of Match#method_missing when 'p' is used as a label or rule name.
    As any gem might contribute private methods to Object, using Citrus
    labels (or even rule names, actually) in semantic productions without
    doing so with Match#captures is unsafe.
    Moreover, the addition of any method/helper to the Match class may
    potentially break an existing grammar, so it breaks Citrus's public
    API and should probably increment the MAJOR version number.
Commits on Mar 10, 2014
  1. @blambeau
Commits on Mar 6, 2014
  1. @blambeau
Commits on May 2, 2013
  1. Removed Ruby warnings.

    Tobias Bühlmann committed
Commits on Feb 22, 2012
  1. @blambeau

    Add a GrammarMethods#parse_file method.

    blambeau committed
    While the parse method already accepts Pathname instances and the
    like, some users might prefer making explicit the fact that they
    want to parse from a file. A Pathname instance is automatically
    created if needed.
  2. @blambeau

    Add Match#source as a shortcut for input.source.

    blambeau committed
    This method allows locating the original parsed source during the
    production of semantic values. It is roughly a shortcut for
    `input.source` but is robust to situations where matches would be
    created with strings (such as in the tests).
  3. @blambeau

    Let Input support multiple sources of parsed text.

    blambeau committed
    This commit makes the Input class supporting various text sources,
    such as a String, a Path, a File, etc. The real source passed at
    construction is kept under @source for traceability.
    Common rubyisms are used to recognize those sources. In particular,
    Pathname instances will be recognized through respond_to?(:to_path),
    which is standard in ruby 1.9.x. Files and IO are recognized through
    :read. Strings and StringIO through :to_str.
Commits on Feb 21, 2012
  1. @blambeau

    Keep a master offset in Match instead of slicing.

    blambeau committed
    Instead of successively slicing strings in matches, we keep the
    parsed text under @source, and an offset in the later in @offset.
    Btw, that @offset might be very useful for keeping trace of the
    localisation of the match in the source text (e.g. for subsequent
    semantic passes; semantic error detection for instance).
Commits on Dec 29, 2011
  1. Better definition of super keyword

    Fixes #36.
Commits on Oct 27, 2011
  1. Allow rule names to begin with super*

    Fixes #24
Commits on May 12, 2011
  1. Added lib/citrus/grammars.rb

    Also, moved all example grammars and tests into the main library tree so
    that they may easily be used by client code.
  2. Don't check for space after {

    Fixes #21
Commits on Mar 18, 2011
Commits on Feb 19, 2011
  1. @joachimm

    Remember to update the input position when restoring a memoized rule …

    joachimm committed with
    …from the cache.
    Also update tests to verify this behavior.
Commits on Feb 4, 2011
Commits on Jan 13, 2011
Commits on Jan 11, 2011
  1. Adds self to Match#captures

    A common point of confusion for some Citrus users is that they are not
    able to retrieve a match by calling its own name on itself. This commit
    adds self to the internal @captures Hash in the first position.
    Also, Match#to_a and Match#[] were added for convenience when retrieving
    captures and submatches.
Commits on Jan 7, 2011
  1. Fix test name

Commits on Jan 5, 2011
  1. Use consistent test style for examples

    All example test suites are run with the default Rake test task. This
    ensures that examples are always working with the current version of the
    Also, Citrus.require should raise Citrus::LoadError if it cannot find a
    suitable file to load.
Commits on Jan 4, 2011
  1. Refactored terminal rule

Commits on Jan 3, 2011
Commits on Dec 31, 2010
  1. Fixed memoization bug

    The MemoizingInput's internal pointer was not being advanced properly
    when the cache was hit.
Commits on Dec 29, 2010
  1. Fixed predicate consumption bug

    Input#test should preserve the current pointer position.
Commits on Dec 28, 2010
  1. Removed {+ notation

    Since we can detect if a block is a module block or not using some
    simple heuristics, we shouldn't provide a second notation. If it turns
    out that the detection mechanism doesn't work as well as it should,
    we'll introduce a second notation in the future.
  2. Changed Terminal#rule to Terminal#regexp

    Also added versions of Terminal#== and StringTerminal#== to detect
    equality with regular expressions and strings respectively.
Commits on Dec 25, 2010
  1. Added Rule#elide?

    This restores the former behavior to matches that are the results of a
    Choice rule, which is that they are essentially the same match as is
    returned by the first matching rule of that choice. This largely
    eliminates the need to call Match#first in the value blocks of choices,
    which feels more natural when writing them.
Commits on Dec 22, 2010
  1. Match#captures includes numeric indices for submatches

    This makes it convenient to use `captures[0]` in an extension method,
    for example. It also allows us to refactor both Match#matches and
    Match#first to use Match#captures, ensuring that we're using the same
    match objects regardless of how they're accessed.
    Also in this commit I've removed Match#names, Match#name, and
    Match#has_name?. These methods existed to support Match#find, which has
    also been removed in favor of the more powerful Match#captures.
Commits on Dec 20, 2010
  1. Try to consume the entire input by default

    Instead of defaulting to false, the consume option now defaults to true.
    This is the behavior that many users expect the first time they use
    Citrus because it is the way that Treetop works. It used to be expensive
    to calculate the length of a Match, so we defaulted to false. It is now
    trivial, so it shouldn't slow things down to default to true.
Something went wrong with that request. Please try again.