class BuildTool::Cfg::Parser < BuildTool::Cfg::Lexer token APPEND token BUILD_PREFIX token BUILD_SYSTEM token END token ENVIRONMENT token EXTERNAL token FILE token GIT token GIT_SVN token HOST token INHERITANCE token INPLACE token INSTALL_PREFIX token LOCAL_PATH token LOG_DIRECTORY token MODULE token OPTION token PATH token PREPEND token PROTOCOL token REMOTE token REMOTE_PATH token REPOSITORY token SERVER token SET token SSH_KEY token STRING token TEMPLATE token TOKEN token TRACK_BRANCH token USE token USER token VAR token VCS rule main : statements { result = ConfigurationFileList.new( val[0] ); } ; # ### SOME HELPER # identifier : STRING { result = val[0]; } | TOKEN { result = val[0]; } ; inheritance : INHERITANCE { result = :INHERITANCE; } ; # ### TOP LEVEL STATEMENTS # statements : /* empty */ | statement statements { result = val.flatten; } ; statement : LOG_DIRECTORY STRING { result = LogDirectoryNode.new( val[1] ); } | build_system_declaration { result = val[0]; } | environment_declaration { result = val[0]; } | vcs_declaration { result = val[0]; } | module_declaration { result = val[0]; } | repository_declaration { result = val[0]; } | server_declaration { result = val[0]; } | ssh_key_declaration { result = val[0]; } ; vcs_declaration : git_declaration { result = val[0]; } | git_svn_declaration { result = val[0]; } ; # ### BUILD SYSTEM DECLARATION # build_system_declaration : BUILD_SYSTEM identifier build_system_statements END { result = BuildSystemDeclarationNode.new( val[1,2] ); } ; build_system_statements : /* empty */ | build_system_statement build_system_statements { result = val.flatten; } ; build_system_statement : OPTION identifier STRING { result = BuildSystemOptionNode.new( val[1,2] ); } | INPLACE { result = BuildSystemInplaceNode.new(); } ; # ### ENVIRONMENT CONFIGURATION # environment_declaration : ENVIRONMENT identifier environment_statements END { result = EnvironmentDeclarationNode.new( val[1..-1] ); } | ENVIRONMENT identifier inheritance identifier environment_statements END { result = EnvironmentDeclarationNode.new( val[1..-1] ); } ; environment_statements : /* empty */ | environment_statement environment_statements { result = val.flatten; } ; environment_statement : VAR TOKEN SET STRING { result = EnvironmentVariableNode.new( val[1..-1] ); } | VAR TOKEN PREPEND STRING { result = EnvironmentVariableNode.new( val[1..-1] ); } | VAR TOKEN APPEND STRING { result = EnvironmentVariableNode.new( val[1..-1] ); } ; # ### GIT CONFIGURATION # git_declaration : VCS GIT git_statements END { result = GitDeclarationNode.new( val[2] ); } ; git_statements : /* empty */ | git_statement git_statements { result = val.flatten; } ; git_statement : REMOTE STRING git_remote_values END { result = GitRemoteNode.new( [ val[1], GitRemoteValueList.new( val[2] ) ] ); } | TRACK_BRANCH STRING { result = GitTrackBranchNode.new( val[1] ); } | EXTERNAL STRING { result = GitSvnExternalNode.new( val[1] ); } ; git_remote_values : /* empty */ | git_remote_value git_remote_values { result = val.flatten; } ; git_remote_value : server_declaration { result = val[0]; } | USE SERVER identifier { result = UseServerNode.new( val[2] ); } ; # ### GIT-SVN CONFIGURATION # git_svn_declaration : VCS GIT_SVN git_svn_statements END { result = GitSvnDeclarationNode.new( val[2] ); } ; git_svn_statements : /* empty */ | git_svn_statement git_svn_statements { result = val.flatten; } ; git_svn_statement : git_statement ; # ### MODULE DECLARATION # module_declaration : MODULE identifier module_statements END { result = ModuleDeclarationNode.new( val[1..-1] ); } | MODULE identifier inheritance identifier module_statements END { result = ModuleDeclarationNode.new( val[1..-1] ); } ; module_statements : /* EMPTY */ | module_statement module_statements { result = val.flatten; } ; module_statement : USE BUILD_SYSTEM identifier { result = UseBuildSystemNode.new( val[2] ); } | USE ENVIRONMENT identifier { result = UseEnvironmentNode.new( val[2] ); } | USE REPOSITORY identifier { result = UseRepositoryNode.new( val[2] ); } | USE VCS identifier { result = UseVcsNode.new( val[2] ); } | build_system_declaration { result = val[0]; } | vcs_declaration { result = val[0]; } | repository_declaration { result = val[0]; } | environment_declaration { result = val[0]; } | INSTALL_PREFIX STRING { result = ModuleInstallPrefixNode.new( val[1] ); } | BUILD_PREFIX STRING { result = ModuleBuildPrefixNode.new( val[1] ); } | REMOTE_PATH STRING { result = ModuleRemotePathNode.new( val[1] ); } | LOCAL_PATH STRING { result = ModuleLocalPathNode.new( val[1] ); } | TEMPLATE { result = ModuleTemplateNode.new(); } ; # ### REPOSITORY DECLARATION # repository_declaration : REPOSITORY identifier repository_statements END { result = RepositoryDeclarationNode.new( val[1..-1] ); } ; repository_statements : /* empty */ | repository_statement repository_statements { result = val.flatten(); } ; repository_statement : SERVER identifier { result = RepositoryServerNode.new( val[1] ); } | PATH STRING { result = RepositoryPathNode.new( val[1] ); } | USER identifier { result = RepositoryUserNode.new( val[1] ); } | USE SSH_KEY identifier { result = UseSshKeyNode.new( val[2] ); } | ssh_key_declaration { result = val[0]; } ; # ### SERVER DECLARATION # server_declaration : SERVER identifier server_statements END { result = ServerDeclarationNode.new( [ val[1], ServerStatementList.new( val[2] ) ] ); } ; server_statements : /* empty */ | server_statement server_statements { result = val.flatten; } ; server_statement : HOST STRING { result = ServerHostNode.new( val[1] ); } | PROTOCOL STRING { result = ServerProtocolNode.new( val[1] ); } | PATH STRING { result = ServerPathNode.new( val[1] ); } ; # ### SSH KEY # ssh_key_declaration : SSH_KEY identifier ssh_key_statements END { result = SshKeyDeclarationNode.new( val[1..-1] ); } ; ssh_key_statements : /* empty */ | ssh_key_statement ssh_key_statements { result = val.flatten; } ; ssh_key_statement : FILE STRING { result = SshKeyFileNode.new( val[1] ); } ; end # class BuildTool::Cfg::GitParser ---- header ---- # ### HEADER # require 'build-tool/cfg/lexer' require 'build-tool/cfg/node' require 'build-tool/cfg/visitor' ---- inner ---- # ### INNER # attr_accessor :configuration def initialize( configuration = Configuration.new) super() @configuration = configuration end def parse_string( string, file = "" ) tree = super visitor = Cfg::ConfigurationFileVisitor.new( configuration ) conf = tree.accept( visitor ) return configuration end ---- footer ---- # ### FOOTER #