examples/general/SRL/srl_demo.rb in rley-0.5.08 vs examples/general/SRL/srl_demo.rb in rley-0.5.09

- old
+ new

@@ -1,6 +1,7 @@ require_relative './lib/parser' +require_relative './lib/ast_builder' def print_title(aTitle) puts aTitle puts '=' * aTitle.size end @@ -26,17 +27,17 @@ WORK IN PROGRESS Simple Regex Language parser: - Parses a very limited subset of the language and displays the parse tree Command-line syntax: - ruby #{my_name} "quantifier expression" + ruby #{my_name} "SRL expression" where: - the SRL quantifier expression is enclosed between double quotes (") + the SRL expression is enclosed between double quotes (") Examples: - ruby #{my_name} "exactly 4 times" - ruby #{my_name} "between 2 and 3 times" + ruby #{my_name} "letter from a to f exactly 4 times" + ruby #{my_name} "uppercase letter between 2 and 3 times" END_MSG puts msg exit(1) end puts ARGV[0] @@ -51,7 +52,16 @@ # Generate a concrete syntax parse tree from the parse result cst_ptree = result.parse_tree print_tree('Concrete Syntax Tree (CST)', cst_ptree) + +# Generate a regexp literal representation from the parse result +tree_builder = ASTBuilder +ast_ptree = result.parse_tree(tree_builder) + +# Now output the regexp literal +root = ast_ptree.root +print_title('SRL to Regexp representation:') +puts "#{ARGV[0]} => #{root.to_str}" # Output the expression result # End of file