Sha256: c2de14e05f1fcab72cde40ee7dc37921d6699382529772b7e6313edf9634e509
Contents?: true
Size: 1.76 KB
Versions: 6
Compression:
Stored size: 1.76 KB
Contents
class Code class Parser class Function < Parslet::Parser rule(:call) { ::Code::Parser::Call.new } rule(:code) { ::Code::Parser::Code.new } rule(:name) { ::Code::Parser::Name.new } rule(:opening_parenthesis) { str("(") } rule(:closing_parenthesis) { str(")") } rule(:equal) { str("=") } rule(:right_caret) { str(">") } rule(:opening_curly_bracket) { str("{") } rule(:closing_curly_bracket) { str("}") } rule(:comma) { str(",") } rule(:colon) { str(":") } rule(:asterisk) { str("*") } rule(:ampersand) { str("&") } rule(:space) { str(" ") } rule(:newline) { str("\n") } rule(:whitespace) { (space | newline).repeat(1) } rule(:whitespace?) { whitespace.maybe } rule(:keyword_argument) do name >> whitespace? >> colon >> (whitespace? >> code.as(:default)).maybe end rule(:regular_argument) do ampersand.as(:block).maybe >> (asterisk >> asterisk).as(:keyword_splat).maybe >> asterisk.as(:splat).maybe >> name >> (whitespace? >> equal >> whitespace? >> code.as(:default)).maybe end rule(:argument) do keyword_argument.as(:keyword) | regular_argument.as(:regular) end rule(:arguments) do argument.repeat(1, 1) >> (whitespace? >> comma >> whitespace? >> argument).repeat end rule(:function) do ( opening_parenthesis >> whitespace? >> arguments.as(:arguments).maybe >> whitespace? >> closing_parenthesis >> whitespace? >> equal >> right_caret >> whitespace? >> opening_curly_bracket >> code.as(:body) >> closing_curly_bracket ).as(:function) | call end root(:function) end end end
Version data entries
6 entries across 6 versions & 2 rubygems