A PEG-based pattern matching library EXtended by back reference with regex-like notation in Scala
Scala
Latest commit b5df7fa Dec 26, 2016 @kmizu Remove obsolte features
Permalink
Failed to load latest commit information.
example
project
src
.gitignore
.travis.yml
License.txt
README.md
build.sbt
release.sbt
version.sbt

README.md

PEGEX: A PEG-based pattern matching library EXtended by back reference with regex-like notation in Scala Build Status

Join the chat at https://gitter.im/kmizu/pegex Build Status Maven Central Scaladoc Reference Status

PEGEX (Parsing Expression Grammar EXtended by back reference with regex-like notations) is a PEG-like pattern matching library for Scala.
PEGEX provides both power of PEG and light-weight syntax of regular expressions. It accepts a PEG-variant with regex-like notations.
Currently, PEGEXes seem stronger than CFGs and alike Boolean Grammars.

For sbt user

Include the following in your build.sbt to add pegex to your project libraryDependencies:

libraryDependency += "com.github.kmizu" %% "pegex" % "0.3"

Runtime Requirement

  • Scala 2.11.X or Scala 2.12.X
  • JDK 1.8.0 or later

Build Requirement

  • Sbt 0.13.X

Example

See tests.

Syntax of PEGEX

(name=e;)*, where name is name of this rule and e is an expression

Kind of Expressions (e)

Note that in PEGEX, space characters have meanings. Thus, A=; is different from A= ;

  • e1e2: sequence of expressions
    • "ab"
    • "ac"
  • e1|e2: unordered choice of expressions
    • "a|b"
    • "(ab|bc)"
  • e*: zero or more repetition
    • "a*"
  • e+: one or more repetition.
    • "a+"
  • e?: zero-or-one repetition.
    • "(a|b)?"
  • (?=e): positive lookahead.
    • "(?=a)"
  • (?!e): negative lookahead
    • "(?!a)"
  • (?<name>e): named capture
  • \g'E': (recursive) rule invocation of E
    • is identical to #{E}
  • \k<name>: back reference of the named capture of name
#{E}$; E=<(?<tag>#{I})>#{E}*</\k<tag>>; I=[a-z]+;
  • .: any character.
    • "(?!a)." matches one character except a
  • _: success certainly.
  • x: one character.
  • [f-t...xyz...]: character class. e.g. [a-zA-Z_]