Permalink
Browse files

shuffling with a few lessons i learned from watching nathan build tir…

…e swing. gonna prolly redo this with tire swing actually
  • Loading branch information...
1 parent 3227a30 commit 0febd902c511997795bd582932d64c4aeedfe0f0 @atmos committed Oct 15, 2008
View
@@ -6,7 +6,7 @@ require 'spec/rake/spectask'
require 'date'
GEM = "keepalived_dot_conf"
-GEM_VERSION = "0.0.1"
+GEM_VERSION = "0.0.2"
AUTHOR = "Corey Donohoe"
EMAIL = "atmos@atmos.org"
HOMEPAGE = "http://atmos.org"
View
3 TODO
@@ -1,4 +1 @@
TODO:
-Fix LICENSE with your name
-Fix Rakefile with your name and contact info
-Add your code to lib/<%= name %>.rb
@@ -0,0 +1,69 @@
+module KeepAlivedConfigFile
+ grammar Grammar
+ rule file
+ expression* <ConfigFile>
+ end
+
+ rule expression
+ vrrps / real_servers / virtual_servers / assignment / comment / blank_line
+ end
+
+ rule vrrps
+ space_no_newline* "vrrp_sync_group" space_no_newline+ block_param:variable space* "{" space* block_contents:file space* "}" space* comment* <VrrpSyncGroupNode> /
+ space_no_newline* "vrrp_instance" space_no_newline+ block_param:variable space_no_newline+ "{" space* block_contents:file space* "}" space* comment* <VrrpInstanceNode>
+ end
+
+ rule real_servers
+ space_no_newline* "real_server" space_no_newline+ ip:variable space_no_newline+ port:variable space* "{" space* block_contents:file space* "}" space* comment* <RealServerNode>
+ end
+
+ rule virtual_servers
+ space_no_newline* "virtual_server" space_no_newline+ ip:variable space_no_newline+ port:variable space* "{" space* block_contents:file space* "}" space* comment* <VirtualServerNode>
+ end
+
+ rule assignment
+ varname:variable space+ "{" space* block_contents:file space* "}" space* comment* <ScopedBlockNode> /
+ varname:variable space_no_newline+ varvalue1:variable space_no_newline* varvalue2:variable space* comment* <TwoElementAssignmentNode> /
+ varname:variable space_no_newline+ varvalue:variable space* comment* <AssignmentNode> /
+ varname:variable space* comment* <DefinitionNode>
+ # varname:variable space "=" space varvalue:number space comment* <AssignmentOperation> /
+ # varname:variable space "=" space "[" space list:array_list space "]" space comment* <ArrayListOperation>
+ end
+
+ rule variable
+ space_no_newline* [A-Za-z0-9_\-\./]+ <VariableNode>
+ end
+
+ rule string
+ ([A-Za-z_-])+ <StringLiteral>
+ end
+
+ rule array_element
+ quoted_string / number
+ end
+
+ rule comment
+ space_no_newline* [!\#] [^\n]* "\n" space* <CommentNode>
+ end
+
+ rule blank_line
+ "\n" <DummyNode>
+ end
+
+ rule non_space_char
+ ![ \n] .
+ end
+
+ rule space_no_newline
+ [ \t]
+ end
+
+ rule space
+ space_no_newline / "\n"
+ end
+
+ rule number
+ [0-9]+ <NumberNode>
+ end
+ end
+end
@@ -0,0 +1,103 @@
+module KeepAlivedConfigFile
+ module Grammar
+ class ConfigFile < ::Treetop::Runtime::SyntaxNode
+ def eval(env={})
+ elements.each do |e|
+ begin
+ result = e.eval(env)
+ if result.kind_of?(String)
+ pp result if env.nil?
+ env[result] = nil
+ else
+ env.merge(result)
+ end
+ rescue => exception
+ # pp e
+ puts exception.backtrace
+ pp "ZOMFG #{exception.message}"
+ end
+ end
+ env
+ end
+ end
+
+ class CommentNode < ::Treetop::Runtime::SyntaxNode
+ def eval(env={}); env end
+ end
+
+ class VrrpSyncGroupNode < ::Treetop::Runtime::SyntaxNode
+ def eval(env={})
+ env[:vrrp_groups] ||= [ ]
+ group = ::KeepAlivedConfigFile::AST::VrrpSyncGroup.new(block_param.eval(env), block_contents.eval({}))
+ env[:vrrp_groups].push(group)
+ env
+ end
+ end
+
+ class VrrpInstanceNode < ::Treetop::Runtime::SyntaxNode
+ def eval(env={})
+ node = ::KeepAlivedConfigFile::AST::VrrpInstance.new(block_param.eval(env), block_contents.eval({}))
+ env[:vrrp_instances] ||= [ ]
+ env[:vrrp_instances].push(node)
+ env
+ end
+ end
+
+ class RealServerNode < ::Treetop::Runtime::SyntaxNode
+ def eval(env={})
+ rs = ::KeepAlivedConfigFile::AST::RealServer.new(ip.eval(env), port.eval(env), block_contents.eval({}))
+ env[:real_servers] ||= [ ]
+ env[:real_servers].push(rs)
+ env
+ end
+ end
+
+ class VirtualServerNode < ::Treetop::Runtime::SyntaxNode
+ def eval(env={})
+ vs = ::KeepAlivedConfigFile::AST::VirtualServer.new(ip.eval(env), port.eval(env), block_contents.eval({}))
+ env[:virtual_servers] ||= [ ]
+ env[:virtual_servers].push(vs)
+ env
+ end
+ end
+
+ class DefinitionNode < ::Treetop::Runtime::SyntaxNode
+ def eval(env={})
+ env[varname.text_value.to_sym] = true
+ env
+ end
+ end
+ class TwoElementAssignmentNode < ::Treetop::Runtime::SyntaxNode
+ def eval(env={})
+ env[varname.text_value.to_sym] = [varvalue1.eval(env), varvalue2.eval(env)]
+ env
+ end
+ end
+
+ class AssignmentNode < ::Treetop::Runtime::SyntaxNode
+ def eval(env={})
+ env[varname.text_value.to_sym] = varvalue.eval(env)
+ env
+ end
+ end
+
+ class VariableNode < ::Treetop::Runtime::SyntaxNode
+ def eval(env={})
+ text_value
+ end
+ end
+
+ class NumberNode < ::Treetop::Runtime::SyntaxNode
+ def eval(env={})
+ text_value.to_i
+ end
+ end
+
+ class ScopedBlockNode < ::Treetop::Runtime::SyntaxNode
+ def eval(env={})
+ env[varname.text_value.to_sym] = block_contents.eval({})
+ env
+ end
+ end
+ end
+end
@@ -1,67 +0,0 @@
-grammar KeepAlivedConfigFileYouShouldntUse
- rule file
- expression* <ConfigFile>
- end
-
- rule expression
- vrrps / real_servers / virtual_servers / assignment / comment / blank_line
- end
-
- rule vrrps
- space_no_newline* "vrrp_sync_group" space_no_newline+ block_param:variable space* "{" space* block_contents:file space* "}" space* comment* <VrrpSyncGroupNode> /
- space_no_newline* "vrrp_instance" space_no_newline+ block_param:variable space_no_newline+ "{" space* block_contents:file space* "}" space* comment* <VrrpInstanceNode>
- end
-
- rule real_servers
- space_no_newline* "real_server" space_no_newline+ ip:variable space_no_newline+ port:variable space* "{" space* block_contents:file space* "}" space* comment* <RealServerNode>
- end
-
- rule virtual_servers
- space_no_newline* "virtual_server" space_no_newline+ ip:variable space_no_newline+ port:variable space* "{" space* block_contents:file space* "}" space* comment* <VirtualServerNode>
- end
-
- rule assignment
- varname:variable space+ "{" space* block_contents:file space* "}" space* comment* <ScopedBlockNode> /
- varname:variable space_no_newline+ varvalue1:variable space_no_newline* varvalue2:variable space* comment* <TwoElementAssignmentNode> /
- varname:variable space_no_newline+ varvalue:variable space* comment* <AssignmentNode> /
- varname:variable space* comment* <DefinitionNode>
-# varname:variable space "=" space varvalue:number space comment* <AssignmentOperation> /
-# varname:variable space "=" space "[" space list:array_list space "]" space comment* <ArrayListOperation>
- end
-
- rule variable
- space_no_newline* [A-Za-z0-9_\-\./]+ <VariableNode>
- end
-
- rule string
- ([A-Za-z_-])+ <StringLiteral>
- end
-
- rule array_element
- quoted_string / number
- end
-
- rule comment
- space_no_newline* [!\#] [^\n]* "\n" space* <CommentNode>
- end
-
- rule blank_line
- "\n" <DummyNode>
- end
-
- rule non_space_char
- ![ \n] .
- end
-
- rule space_no_newline
- [ \t]
- end
-
- rule space
- space_no_newline / "\n"
- end
-
- rule number
- [0-9]+ <NumberNode>
- end
-end
@@ -1,101 +0,0 @@
-module KeepAlivedConfigFileYouShouldntUse
- class ConfigFile < ::Treetop::Runtime::SyntaxNode
- def eval(env={})
- elements.each do |e|
- begin
- result = e.eval(env)
- if result.kind_of?(String)
- pp result if env.nil?
- env[result] = nil
- else
- env.merge(result)
- end
- rescue => exception
- # pp e
- puts exception.backtrace
- pp "ZOMFG #{exception.message}"
- end
- end
- env
- end
- end
-
- class CommentNode < ::Treetop::Runtime::SyntaxNode
- def eval(env={}); env end
- end
-
- class VrrpSyncGroupNode < ::Treetop::Runtime::SyntaxNode
- def eval(env={})
- env[:vrrp_groups] ||= [ ]
- group = ::KeepAlivedConfigFile::AST::VrrpSyncGroup.new(block_param.eval(env), block_contents.eval({}))
- env[:vrrp_groups].push(group)
- env
- end
- end
-
- class VrrpInstanceNode < ::Treetop::Runtime::SyntaxNode
- def eval(env={})
- node = ::KeepAlivedConfigFile::AST::VrrpInstance.new(block_param.eval(env), block_contents.eval({}))
- env[:vrrp_instances] ||= [ ]
- env[:vrrp_instances].push(node)
- env
- end
- end
-
- class RealServerNode < ::Treetop::Runtime::SyntaxNode
- def eval(env={})
- rs = ::KeepAlivedConfigFile::AST::RealServer.new(ip.eval(env), port.eval(env), block_contents.eval({}))
- env[:real_servers] ||= [ ]
- env[:real_servers].push(rs)
- env
- end
- end
-
- class VirtualServerNode < ::Treetop::Runtime::SyntaxNode
- def eval(env={})
- vs = ::KeepAlivedConfigFile::AST::VirtualServer.new(ip.eval(env), port.eval(env), block_contents.eval({}))
- env[:virtual_servers] ||= [ ]
- env[:virtual_servers].push(vs)
- env
- end
- end
-
- class DefinitionNode < ::Treetop::Runtime::SyntaxNode
- def eval(env={})
- env[varname.text_value.to_sym] = true
- env
- end
- end
- class TwoElementAssignmentNode < ::Treetop::Runtime::SyntaxNode
- def eval(env={})
- env[varname.text_value.to_sym] = [varvalue1.eval(env), varvalue2.eval(env)]
- env
- end
- end
-
- class AssignmentNode < ::Treetop::Runtime::SyntaxNode
- def eval(env={})
- env[varname.text_value.to_sym] = varvalue.eval(env)
- env
- end
- end
-
- class VariableNode < ::Treetop::Runtime::SyntaxNode
- def eval(env={})
- text_value
- end
- end
-
- class NumberNode < ::Treetop::Runtime::SyntaxNode
- def eval(env={})
- text_value.to_i
- end
- end
-
- class ScopedBlockNode < ::Treetop::Runtime::SyntaxNode
- def eval(env={})
- env[varname.text_value.to_sym] = block_contents.eval({})
- env
- end
- end
-end
@@ -1,12 +1,12 @@
require 'rubygems'
require 'treetop'
require File.dirname(__FILE__) + '/keepalived/ast'
-Treetop.load File.dirname(__FILE__) + '/keepalived/keepalived_config_file_you_shouldnt_use'
-require File.dirname(__FILE__) + '/keepalived/keepalived_config_file_you_shouldnt_use_node_classes'
+Treetop.load File.dirname(__FILE__) + '/keepalived/grammar'
+require File.dirname(__FILE__) + '/keepalived/grammar_node_classes'
-module KeepAlived
+module KeepAlivedConfigFile
class Parser < Treetop::Runtime::CompiledParser
- include KeepAlivedConfigFileYouShouldntUse
+ include KeepAlivedConfigFile::Grammar
end
end
Oops, something went wrong.

0 comments on commit 0febd90

Please sign in to comment.