sonic-pi

https://github.com/sonic-pi-net/sonic-pi

C++

Code. Music. Live.

Parslet#infix_expression

Returns a parslet atom that parses infix expressions. Operations are 
specified as a list of <atom, precedence, associativity> tuples, where 
atom is simply the parslet atom that matches an operator, precedence is 
a number and associativity is either :left or :right. 

Higher precedence indicates that the operation should bind tighter than
other operations with lower precedence. In common algebra, '+' has 
lower precedence than '*'. So you would have a precedence of 1 for '+' and
a precedence of 2 for '*'. Only the order relation between these two 
counts, so any number would work. 

Associativity is what decides what interpretation to take for strings that
are ambiguous like '1 + 2 + 3'. If '+' is specified as left associative, 
the expression would be interpreted as '(1 + 2) + 3'. If right 
associativity is chosen, it would be interpreted as '1 + (2 + 3)'. Note 
that the hash trees output reflect that choice as well. 

Example:
  infix_expression(integer, [add_op, 1, :left])
  # would parse things like '1 + 2'

Source | Google | Stack overflow

Edit

git clone [email protected]:sonic-pi-net/sonic-pi.git

cd sonic-pi

open app/server/ruby/vendor/parslet/lib/parslet.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Parslet-infix_expression-for-pr


# Commit to git

git add app/server/ruby/vendor/parslet/lib/parslet.rbgit commit -m "better docs for Parslet#infix_expression"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-Parslet-infix_expression-for-pr

hub pull-request


# Celebrate!