Class: LLIP::RegexpParser

Inherits:
AbstractParser show all
Defined in:
lib/llip/regexp_parser.rb

Overview

It’s a parser for regular expression. It correctly builds a RegexpSpecification given a valid regular expression string.

Grammar

VN = { EXP , ELEMENT , META}

char = every charachter

symb = { ( , ) , . , * , + , \ , | , [ , ] }

VT = char U symb

In every production it has been used “or” instead of “|” to not make confusion.

P =

EXP -> META EXP
EXP -> META or EXP
EXP -> META
META -> ELEMENT*
META -> ELEMENT+
META -> ELEMENT
ELEMENT -> char or . or \symb
ELEMENT -> [CLASS]
ELEMENT -> (EXP)
CLASS -> char
CLASS -> char CLASS
CLASS -> char - char
CLASS -> char - char CLASS

or in EBNF format

P’ =

EXP ::= META{[|]EXP
META ::= ELEMENT[* or  +]
ELEMENT ::= char or . or \symb or (EXP) or [CLASS]
CLASS ::= char{ - char or - char char or char}

}

Defined Under Namespace

Classes: MetaAccessor

Constant Summary collapse

SPECIALS_TABLE =
{
  "n" => "\n",
  "r" => "\r",
  "t" => "\t"
}

Instance Method Summary collapse

Methods inherited from AbstractParser

#[], #[]=, inherited, #initialize, #parse, #productions, #raise

Constructor Details

This class inherits a constructor from LLIP::AbstractParser

Instance Method Details

#add_char(parser, scanner, char = scanner.current.value) ⇒ Object



235
236
237
238
239
240
241
242
# File 'lib/llip/regexp_parser.rb', line 235

def add_char(parser, scanner, char=scanner.current.value)
  r = parser[:regexp].add_state
  parser[:last].each { |s| s[char] = r }
  parser[:regexp].add_state(r)
  parser[:last] = [r]
  scanner.next
  char
end