
= REX: Ruby Lex for Racc


== 

  Racc ʻѤ Ruby Ѥλ祹ġ롣


== Ȥ

  rex [options] grammarfile

  -o  --output-file  filename   ϥե̾
  -s  --stub                    ǥХåѤμղ
  -i  --ignorecase              ʸʸ̤ʤ
  -C  --check-only              ʸˡΤ
      --independent             ¸⡼
  -d  --debug                   ǥХåɽ
  -h  --help                    Ȥ
      --version                 Сɽ
      --copyright               ɽ


== ǥեȤνϥե̾

  foo.rex  ˤĤ  foo.rex.rb  Ϥ롣
  ʲΤ褦Ѥ뤳ȤꤷƤ롣

    require 'foo.rex' 


== ϥե빽¤

  Ƭ§ν롣
  §ˤϡʣ᤬ޤޤ롣
  ϡƬɤǻϤޤ롣

  ס

    [Ƭ]
    "class" Foo
    ["option"
      [ץ] ]
    ["inner"
      [᥽å] ]
    ["macro"
      [ޥ̾  ɽ] ]
    "rule"
      [Ⱦ]  ѥ  []
    "end"
    []


=== ϥե뵭

    class Foo
    macro
      BLANK         \s+
      DIGIT         \d+
    rule
      {BLANK}
      {DIGIT}       { [:NUMBER, text.to_i] }
      .             { [text, text] }
    end


== Ƭʾάǽ

  §˵Ҥ줿Ƥϡ٤ƽϥեƬž롣


== ʾάǽ

  §ʹߤ˵Ҥ줿Ƥϡ٤ƽϥեž롣


== §

  § "class" ɤϤޤԤ "end" ɤϤޤ
  ԤޤǤǤ롣
  "class" ɤ³ƽϤ륯饹̾ꤹ롣
  ⥸塼̾ǽȡ⥸塼⥯饹Ȥʤ롣
  Racc::Parser Ѿ饹롣


=== §

    class Foo
    class Bar::Foo


== ץʾάǽ

   "option" ɤǻϤޤ롣

    "ignorecase"  ʸʸ̤ʤ
    "stub"        ǥХåѤμղ
    "independent" ¸⡼ɡRacc Ѿʤ

== 桼ɡʾάǽ

   "inner" ɤǻϤޤ롣
  ƤϡʤΥ饹롣


== ޥʾάǽ

   "macro" ɤǻϤޤ롣
  ֤ɽ̾Ĥ롣
  \ ǥפ뤳ȤǶޤ뤳ȤǤ롣

=== ޥ

    DIGIT         \d+
    IDENT         [a-zA-Z_][a-zA-Z0-9_]*
    BLANK         [\ \t]+
    REMIN         \/\*
    REMOUT        \*\/


== §

   "rule" ɤǻϤޤ롣

  [state]  pattern  [actions]


=== state: Ⱦ֡ʾάǽ

    Ⱦ֤ ":" ֤뼱̻Ҥɽ롣
    ³ѻʸΤȤ¾ŪȾ֤Ȥʤ롣
    ʸΤȤŪȾ֤Ȥʤ롣
    Ⱦ֤νͤӾάͤ nil Ǥ롣


=== pattern: ʸѥ

    ʸꤹ뤿ɽ
    ɽεҤˤϡ̤ǳäޥѤ뤳ȤǤ롣
    ޤɽѤˤϡޥѤ롣


=== actions: ʾάǽ

    ѥŬ礹Ȥϼ¹Ԥ롣
    Ŭڤʥȡ롣
    ȡϡ̤ͤ󡢤ޤ nil Ǥ롣
    ȡ뤿˰ʲǤѤǤ롣

      lineno  Ϲֹ     ( Read Only )
      text    Фʸ ( Read Only )
      state   Ⱦ   ( Read/Write )

     { } ǳä Ruby Υ֥åǤ롣
    ֥åۤήѤ뵡ǽѤƤϤʤ
    ( return, exit, next, break, ... )
    󤬾άȡŬ礷ʸ˴Ƽ˿ʤࡣ


=== §

        {REMIN}                 { state = :REM ; [:REM_IN, text] }
  :REM  {REMOUT}                { state = nil ; [:REM_OUT, text] }
  :REM  (.+)(?={REMOUT})        { [:COMMENT, text] }
        {BLANK}
        -?{DIGIT}               { [:NUMBER, text.to_i] }
        {WORD}                  { [:word, text] }
        .                       { [text, text] }


== ȡʾάǽ

  ƹԤˤ "#"  ޤǤȤˤʤ롣


== 饹λȤ

=== scan_setup()

    ʤμ¹Գϻ˽뤿Υ٥ȡ
    ƻѤ롣

=== scan_str( str )

    줿ʸˡˤäƵҤ줿ʸ᤹롣
    token ݻ롣


=== scan_file( filename )

    줿ʸˡˤäƵҤ줿եɤ߹ࡣ
    token ݻ롣


=== next_token

    ݻ token ҤȤĤļФ
    Ǹ nil ֤


== 

  ܻͤϻŪǤꡢͽʤѹ礬롣

