<commit_before>dir = File.dirname(__FILE__)
require "#{dir}/../spec_helper"
require "#{dir}/metagrammar_spec_context_helper"

describe "The subset of the metagrammar rooted at the parsing_rule rule" do
  include MetagrammarSpecContextHelper
  
  before do
    @root = :parsing_rule
  end

  it "parses a parse rule with a terminal symbol as its expression" do
    with_both_protometagrammar_and_metagrammar(@root) do |parser|
      result = parse_result_for(parser, "rule foo 'bar' end")
   
      result.should be_an_instance_of(ParsingRule)
      result.nonterminal_symbol.name.should == :foo
      result.parsing_expression.should be_an_instance_of(TerminalSymbol)      
    end
  end
  
  it "parses a parse rule with a complex expression" do
    with_both_protometagrammar_and_metagrammar(@root) do |parser|
      result = parse_result_for(parser, "rule foo 'bar' baz+ (xyzzy / plugh*) !bar end")
   
      result.should be_an_instance_of(ParsingRule)      
    end
  end
end

describe "In the Metagrammar only, the node returned by the parsing_rule rule's successful parsing of a rule with a terminal expression" do
  include MetagrammarSpecContextHelper

  before do
    with_metagrammar(:parsing_rule) do |parser|
      @node = parser.parse("rule foo 'bar' end")
    end
  end

  it "has a Ruby source representation" do
    @node.to_ruby(grammar_node_mock('Foo')).should == "ParsingRule.new(Foo.nonterminal_symbol(:foo), TerminalSymbol.new('bar'))"
  end
  
  it 'can generate the Ruby to add itself to a grammar' do
    @node.add_rule_ruby(grammar_node_mock('Foo')).should == "Foo.add_parsing_rule(ParsingRule.new(Foo.nonterminal_symbol(:foo), TerminalSymbol.new('bar')))"
  end
end<commit_msg>ns - Parsing rule nodes in the Metagrammar can generate the Ruby to add themselves to a grammar<commit_after>dir = File.dirname(__FILE__)
require "#{dir}/../spec_helper"
require "#{dir}/metagrammar_spec_context_helper"

describe "The subset of the metagrammar rooted at the parsing_rule rule" do
  include MetagrammarSpecContextHelper
  
  before do
    @root = :parsing_rule
  end

  it "parses a parse rule with a terminal symbol as its expression" do
    with_both_protometagrammar_and_metagrammar(@root) do |parser|
      result = parse_result_for(parser, "rule foo 'bar' end")
   
      result.should be_an_instance_of(ParsingRule)
      result.nonterminal_symbol.name.should == :foo
      result.parsing_expression.should be_an_instance_of(TerminalSymbol)
    end
  end
  
  it "parses a parse rule with a complex expression" do
    with_both_protometagrammar_and_metagrammar(@root) do |parser|
      result = parse_result_for(parser, "rule foo 'bar' baz+ (xyzzy / plugh*) !bar end")
   
      result.should be_an_instance_of(ParsingRule)
    end
  end
end

describe "In the Metagrammar only, the node returned by the parsing_rule rule's successful parsing of a rule with a terminal expression" do
  include MetagrammarSpecContextHelper

  before do
    with_metagrammar(:parsing_rule) do |parser|
      @node = parser.parse("rule foo 'bar' end")
    end
  end

  it "has a Ruby source representation" do
    @node.to_ruby(grammar_node_mock('Foo')).should == "ParsingRule.new(Foo.nonterminal_symbol(:foo), TerminalSymbol.new('bar'))"
  end
  
  it 'can generate the Ruby to add itself to a grammar' do
    @node.add_rule_ruby(grammar_node_mock('Foo')).should == "Foo.add_parsing_rule(ParsingRule.new(Foo.nonterminal_symbol(:foo), TerminalSymbol.new('bar')))"
  end
end
{'fraction_non_alphanumeric': 0.08999424956871765, 'fraction_numerical': 0.0, 'mean_word_length': 4.36055469953775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '529895', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1092, 'n_words': 309}