sshfs-mapper: updated lexer/parser and demo file.

git-svn-id: https://websvn.glenux.net/svn/Upoc/sshfs-mapper/trunk@1330 eaee96b3-f302-0410-b096-c6cfd47f7835
This commit is contained in:
glenux 2009-04-09 16:47:28 +00:00
parent 3b9d963098
commit 25cf230fe4
2 changed files with 41 additions and 33 deletions

View file

@ -2,31 +2,27 @@
server "daneel.glenux.net" { server "daneel.glenux.net" {
user "glenux"; user "glenux";
port 22; port 22;
automount true; // default automount true;
compress true; // default compress true;
map "Media" { map "Media" {
user "glenux";
remote "/opt/media"; remote "/opt/media";
}; };
map "MediaSafe" { map "MediaSafe" {
user $USER;
remote "/home/media"; remote "/home/media";
}; };
map "Documents" { map "Documents" {
user $USER;
remote "/home/$USER"; remote "/home/$USER";
}; };
map "Extra" { map "Extra" {
user $USER; remote "/opt";
remote "/opt
}; };
map "DocumentsPapa" { map "DocumentsPapa" {
user papa; user "papa";
remote "/home/papa" remote "/home/papa"
}; };

View file

@ -3,49 +3,63 @@ class MapParser
rule rule
commands commands
: commands command SEMICOLON { puts "GOT A COMMAND" } : commands command_blk SEMICOLON { puts "GOT A COMMAND" }
| /* none */ { result = 0 } | /* none */ { puts "no command found" }
command command_blk
: global_blk : global_blk
| server_blk | server_blk
server_blk server_blk
: SERVER SEP STRING SEP OBRACE server_opts EBRACE : SERVER STRING OBRACE server_opts EBRACE { puts "[server #{val[1]}]" }
: SERVER SEP STRING OBRACE server_opts EBRACE
global_blk global_blk
: GLOBAL OBRACE global_opts EBRACE : GLOBAL OBRACE global_opts EBRACE
server_opts server_opts
: server_opts server_opt SEMICOLON : server_opts server_opt SEMICOLON
| /* none */ { result = 0 } | /* none */
server_opt server_opt
: user_opt : user_opt { puts "=> user opt" }
| port_opt | port_opt { puts "=> port opt" }
| automount_opt | automount_opt { puts "=> automount opt" }
| compress_opt | compress_opt { puts "=> compress opt" }
| reconnect_opt | reconnect_opt { puts "=> reconnect opt" }
| server_map_blk { puts "=> server_map blk" }
server_map_blk
: MAP STRING OBRACE server_map_opts EBRACE
server_map_opts
: server_map_opts server_map_opt SEMICOLON
| /* none */
server_map_opt
: remote_opt
| local_opt
| user_opt
| port_opt
| compress_opt
user_opt user_opt
: USER QUOTE STRING QUOTE : USER STRING { puts "* user = #{val[1]}" }
port_opt port_opt
: PORT INTEGER : PORT NUMBER { puts "* port = #{val[1]}" }
automount_opt automount_opt
: AUTOMOUNT boolean { puts ( "AUTOMOUNT => " + val[1] ) } : AUTOMOUNT boolean { puts "* automount = #{@bool_result}" }
compress_opt compress_opt
: COMPRESS boolean { puts ( "COMPRESS => " + val[1] ) } : COMPRESS boolean { puts "* compress = #{@bool_result}" }
reconnect_opt reconnect_opt
: RECONNECT boolean { puts ( "RECONNECT => " + val[1] ) } : RECONNECT boolean { puts ( "* reconnect = #{@bool_result}" ) }
boolean boolean
: BOOL_TRUE { result = true } : BOOL_TRUE { @bool_result = true }
| BOOL_FALSE { result = false } | BOOL_FALSE { @bool_result = false }
end end
@ -61,27 +75,25 @@ require 'strscan'
def parse( str ) def parse( str )
puts "parse start..." puts "parse start..."
tokens = [] tokens = []
scanner = StringScanner.new( str ) scanner = StringScanner.new( str )
puts ( "scanner?" + scanner.string ) puts ( "scanner?" + scanner.string )
until scanner.eos? until scanner.eos?
puts "scanning.. at #{scanner.pos}" puts "scanning.. at #{scanner.pos}"
case case
when m = scanner.scan( /\/\/.*$/ ) when m = scanner.scan( /\/\/.*$/ )
# comments # comments
tokens.push [:SEP, m]
when m = scanner.scan( /(\s+|\n)/ ) when m = scanner.scan( /(\s+|\n)/ )
# whitespace and newlines # whitespace and newlines
tokens.push [:SEP, m]
when m = scanner.scan( /;/ )
tokens.push [:SEMICOLON, m]
when m = scanner.scan( /\d+/ )
tokens.push [:NUMBER, m]
when m = scanner.scan( /\{/ ) when m = scanner.scan( /\{/ )
tokens.push [:OBRACE, m] tokens.push [:OBRACE, m]
when m = scanner.scan( /\}/ ) when m = scanner.scan( /\}/ )
tokens.push [:EBRACE, m] tokens.push [:EBRACE, m]
when m = scanner.scan( /;/ )
tokens.push [:SEMICOLON, m]
when m = scanner.scan( /\d+/ )
tokens.push [:NUMBER, m]
when m = scanner.scan( /user/i ) when m = scanner.scan( /user/i )
tokens.push [:USER, m] tokens.push [:USER, m]
when m = scanner.scan( /automount/i ) when m = scanner.scan( /automount/i )