Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d3c5dc06624e
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 284d3fd77517
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Sep 6, 2014

  1. Add 0d123 base 10 syntax

    elia committed Sep 6, 2014

    Unverified

    The committer email address is not verified.
    Copy the full SHA
    8fecb7f View commit details
  2. Unverified

    The committer email address is not verified.
    Copy the full SHA
    284d3fd View commit details
Showing with 12 additions and 9 deletions.
  1. +12 −9 lib/opal/parser/lexer.rb
21 changes: 12 additions & 9 deletions lib/opal/parser/lexer.rb
Original file line number Diff line number Diff line change
@@ -176,21 +176,24 @@ def new_op_asgn(value)
def process_numeric
@lex_state = :expr_end

if scan(/0[bB](0|1|_)+/)
self.yylval = scanner.matched.to_i(2)
return :tINTEGER
elsif scan(/0[oO]?([0-7]|_)+/)
self.yylval = scanner.matched.to_i(8)
return :tINTEGER
elsif scan(/[\d_]+\.[\d_]+\b|[\d_]+(\.[\d_]+)?[eE][-+]?[\d_]+\b/)
if scan(/[\d_]+\.[\d_]+\b|[\d_]+(\.[\d_]+)?[eE][-+]?[\d_]+\b/) # FLOATS
self.yylval = scanner.matched.gsub(/_/, '').to_f
return :tFLOAT
elsif scan(/[\d_]+\b/)
elsif scan(/([^0][\d_]*|0)\b/) # BASE 10
self.yylval = scanner.matched.gsub(/_/, '').to_i
return :tINTEGER
elsif scan(/0[xX](\d|[a-f]|[A-F]|_)+/)
elsif scan(/0[bB](0|1|_)+/) # BASE 2
self.yylval = scanner.matched.to_i(2)
return :tINTEGER
elsif scan(/0[xX](\d|[a-f]|[A-F]|_)+/) # BASE 16
self.yylval = scanner.matched.to_i(16)
return :tINTEGER
elsif scan(/0[oO]?([0-7]|_)+/) # BASE 8
self.yylval = scanner.matched.to_i(8)
return :tINTEGER
elsif scan(/0[dD]([0-9]|_)+/) # BASE 10
self.yylval = scanner.matched.gsub(/_/, '').to_i
return :tINTEGER
else
raise "Lexing error on numeric type: `#{scanner.peek 5}`"
end