Sha256: 09ff6b66ca5aedfd5744d67724a3db9dfc4ad64fb7d80d4dd4e2cca7e5344af5

Contents?: true

Size: 1.31 KB

Versions: 8

Compression:

Stored size: 1.31 KB

Contents

module CEML
grammar Casting
    include Lexer

    rule casting_statement
      ('gather' / 'await' / 'nab') ws roles within_phrase:within_phrase? <CastingStatement>
    end

    rule within_phrase
        ws 'within' ws distance
    end

    rule roles
        role more:(and role)* {
            def list
                [role] + more.elements.map{ |e| e.role }
            end

            def names; list.map{ |r| r.name.to_sym };         end
            def [](x); list.detect{ |r| r.name.to_sym == x }; end
            def min;   list.map(&:min).inject(0, &:+);        end
            def max;   list.map(&:max).inject(0, &:+);        end
        }
    end

    rule qualifier
        id
    end

    rule rolename
        id
    end

    rule role
      (rolename &and / range ws qualifier ws rolename / range ws rolename / qualifier ws rolename / rolename) {
        def name; if respond_to? :rolename then rolename.text_value else text_value end; end
        def min
            return range.min if respond_to? :range
            name =~ /s$/ ? 2 : 1
        end
        def max
            return range.max if respond_to? :range
            name =~ /s$/ ? 10000 : 1
        end
        def qualifiers
            return [qualifier.text_value] if respond_to? :qualifier
            return []
        end
      }
    end

end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ceml-0.5.6 lib/ceml/tt/casting.treetop
ceml-0.5.5 lib/ceml/tt/casting.treetop
ceml-0.5.4 lib/ceml/tt/casting.treetop
ceml-0.5.3 lib/ceml/tt/casting.treetop
ceml-0.5.2 lib/ceml/tt/casting.treetop
ceml-0.5.1 lib/ceml/tt/casting.treetop
ceml-0.5.0 lib/ceml/tt/casting.treetop
ceml-0.4.0 lib/ceml/tt/casting.treetop