Sha256: 976c68817cd83e6fea0612d9e9a0f64a7ff3fc6f05122ef410fa478c81f31b4a
Contents?: true
Size: 1.94 KB
Versions: 1
Compression:
Stored size: 1.94 KB
Contents
require 'parslet' module Shift module Parser include Parslet rule(:dot) { str(".") } rule(:comma) { str(",") } rule(:space) { str(" ") } rule(:space?) { space.maybe } rule(:colon) { str(":") } rule(:fwd_slash) { str("/") } rule(:single_quotes) { str("'") } rule(:double_quotes) { str('"') } rule(:lparen) { str("(") } rule(:rparen) { str(")") } rule(:left_square_bracket) { str('[') } rule(:right_square_bracket) { str(']') } rule(:integer) { match('[0-9]').repeat(1) } rule(:floating_point_number) { integer >> dot >> integer } rule(:number) { space? >> (floating_point_number | integer) >> space? } rule(:word) { space? >> match('[\w]').repeat(1) >> space? } rule :single_quoted_string do single_quotes >> ( (str('\\') >> any) | (single_quotes.absent? >> any) ).repeat >> single_quotes end rule :double_quoted_string do double_quotes >> ( (str('\\') >> any) | (double_quotes.absent? >> any) ).repeat >> double_quotes end rule(:string_value) { single_quoted_string | double_quoted_string } rule(:identifier) { match('[A-Za-z]') >> match['[A-Za-z0-9_]'].repeat(0) } rule(:hash_attribute) { string_value | identifier } rule(:hash_value) { identifier >> left_square_bracket >> hash_attribute >> right_square_bracket } rule(:object_value) { identifier >> dot >> identifier } rule(:variables) { space? >> (object_value.as(:object_value) | hash_value.as(:hash_value) | identifier.as(:identifier)) >> space? } rule(:string_valued_expression) { read_statement.as(:read_statement) | string_value.as(:string) | variables } rule(:numeric_value) { number | object_value | hash_value | identifier } rule(:simple_primitives) { space? >> (number | string_value | object_value | hash_value | identifier) >> space? } rule(:parenthesized_primitives) { lparen >> simple_primitives >> rparen } rule(:primitives) { parenthesized_primitives | simple_primitives } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
shift-lang-0.1.1 | lib/shift-lang/parser/token_parser.rb |