class

TopDown::Parser::ParseletLiteral

Inherits Reference < Object

This type is used for documentation purpose only. It represents an element to parse inside macro.

Could be one of the following:

  • a CharLiteral, to parse exactly one Char
  • a StringLiteral, to parse an exact String
  • a RegexLiteral, to parse the given pattern, returns the matched String. ($~, $0, $1, ... could be used after)
  • a RangeLiteral(Char, Char), to parse any Char between the range
  • a SymbolLiteral, to parse an entire syntax, returns the result of the syntax, see Parser.syntax
  • an one-value ArrayLiteral, to parse a token, returns the value of matched token
  • a Call:
    • |: to parse a union, see Parser.union.
    • any, to parse any Char except EOF.
    • [any], to parse any token except EOF.
    • not(parselet), to parse any char, except if parselet matches.
parse('๐Ÿ’Ž')
parse("foo")
parse(/\d+/, &.to_i)
parse(/"(([^"\\]|\\.)*)"/) { $1 }
parse(:expression)
parse(["+="])

parse("foo" | :value | '๐Ÿ’Ž')
# equivalent to:
union do
 parse("foo")
 parse(:value)
 parse('๐Ÿ’Ž')
end

parse(any)        # any char except '\0'
parse([any])      # any token except EOF
parse(not('\n'))  # any char except '\n' & EOF
parse(not(["+"])) # any token except "+" & EOF
parse(not("foo")) # any char or fail on "foo".

See Parser.parse.