Class: ImportGrammar Private

Inherits:
Grammar show all
Defined in:
lib/ruby_grammar_builder/grammar.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents a Textmate Grammar that has been imported This exists entirely to override Grammar#[] and should not be normally created

Instance Attribute Summary

Attributes inherited from Grammar

#ending, #name, #repository, #scope_name

Instance Method Summary collapse

Methods inherited from Grammar

#[]=, #auto_version, fromTmLanguage, #generate, import, #import, new_exportable_grammar, #parseTokenSyntax, plugins, register_linter, register_transform, remove_plugin, #run_post_transform_stage, #run_pre_transform_stage, #save_to, #tokenMatching

Constructor Details

#initialize(keys) ⇒ ImportGrammar

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new Grammar

Parameters:

  • keys (Hash)

    The grammar keys

Options Hash (keys):

  • :name (String)

    The name of the grammar

  • :scope_name (String)

    The scope_name of teh grammar, must start with source. or text.

  • :version (String, :auto) — default: :auto

    the version of the grammar, :auto uses the current git commit as the version

  • :patterns (Array) — default: []

    ignored, will be replaced with the initial context

  • :repository (Hash) — default: {}

    ignored, will be replaced by the generated rules

  • all (Object)

    remaining options will be copied to the grammar without change



659
660
661
# File 'lib/ruby_grammar_builder/grammar.rb', line 659

def initialize(keys)
    super(keys)
end

Instance Method Details

#[](key) ⇒ PatternBase, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

patterns that have been imported from a file cannot be be accessed

Access a pattern in the grammar

Parameters:

  • key (Symbol)

    The key the pattern is stored in

Returns:



665
666
667
668
669
# File 'lib/ruby_grammar_builder/grammar.rb', line 665

def [](key)
    raise "#{key} is a not a pattern and cannot be referenced" if @repository[key].is_a? Hash

    @repository[key]
end