Skip to content

Commit

Permalink
HOPEG is now Macro PEG
Browse files Browse the repository at this point in the history
  • Loading branch information
Kota Mizushima committed Mar 8, 2016
1 parent d013760 commit 8bd5129
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 55 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
## HOPEG: Higher Order Parsing Expression Grammar
## Macro PEG: PEG with macro-like rules

[![Build Status](https://travis-ci.org/kmizu/hopeg.png?branch=master)](https://travis-ci.org/kmizu/hopeg)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.kmizu/hopeg_2.11/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.kmizu/hopeg_2.11)
[![Scaladoc](http://javadoc-badge.appspot.com/com.github.kmizu/hopeg_2.11.svg?label=scaladoc)](http://javadoc-badge.appspot.com/com.github.kmizu/hopeg_2.11/index.html#com.github.kmizu.hopeg.package)
[![Reference Status](https://www.versioneye.com/java/com.github.kmizu:hopeg_2.11/reference_badge.svg?style=flat)](https://www.versioneye.com/java/com.github.kmizu:hopeg_2.11/references)
[![Build Status](https://travis-ci.org/kmizu/macro_peg.png?branch=master)](https://travis-ci.org/kmizu/macro_peg)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.kmizu/macro_peg_2.11/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.kmizu/macro_peg_2.11)
[![Scaladoc](http://javadoc-badge.appspot.com/com.github.kmizu/macro_peg_2.11.svg?label=scaladoc)](http://javadoc-badge.appspot.com/com.github.kmizu/macro_peg_2.11/index.html#com.github.kmizu.macro_peg.package)
[![Reference Status](https://www.versioneye.com/java/com.github.kmizu:macro_peg_2.11/reference_badge.svg?style=flat)](https://www.versioneye.com/java/com.github.kmizu:macro_peg_2.11/references)

HOPEG is an extension of PEG by parametric rule (rule constructor). It seems that expressiveness of HOPEG
is greather than (traditional) PEG since HOPEG can express palindromes. This repository implements a HOPEG
Macro PEG is an extended PEG by macro-like rules. It seems that expressiveness of Macro PEG
is greather than traditional PEG since Macro PEG can express palindromes. This repository implements a Macro PEG
interpreter (or matcher).

### Grammar of HOPEG in Pseudo PEG
### Grammar of Macro PEG in Pseudo PEG

Note that spacing is eliminated.

Expand Down Expand Up @@ -42,13 +42,13 @@ Note that spacing is eliminated.
### Release Note

#### 0.0.3
* [Fix bug of HOPEGEvaluator](https://github.com/kmizu/hopeg/commit/86b7c43ef52b9a6d2e81fcb541aca93e89b276ae)
* [Modifier HOPEG example](https://github.com/kmizu/hopeg/commit/00221379bec06ddf3392e50803f6bf5d1316b579)
* [Fix bug of MacroPEGEvaluator](https://github.com/kmizu/macro_peg/commit/86b7c43ef52b9a6d2e81fcb541aca93e89b276ae)
* [Modifier HOPEG example](https://github.com/kmizu/macro_peg/commit/00221379bec06ddf3392e50803f6bf5d1316b579)

#### 0.0.2

* [Fix bug of HOPEGParser](https://github.com/kmizu/hopeg/commit/a7a72bcffd22401b9fec7a71ff2a5992e6fe7448)
* [Arithmetic HOPEG example](https://github.com/kmizu/hopeg/commit/1aadc5585490a13e6eb7cdbf60547eea1b424052)
* [Fix bug of HOPEGParser](https://github.com/kmizu/macro_peg/commit/a7a72bcffd22401b9fec7a71ff2a5992e6fe7448)
* [Arithmetic HOPEG example](https://github.com/kmizu/macro_peg/commit/1aadc5585490a13e6eb7cdbf60547eea1b424052)

### Usage

Expand All @@ -57,19 +57,19 @@ Note that the behaviour could change.
Add the following lines to your build.sbt file:

```scala
libraryDependencies += ("com.github.kmizu" %% "hopeg" % "0.0.3")
libraryDependencies += ("com.github.kmizu" %% "macro_peg" % "0.0.3")
```

Then, you can use `HOPEGParser` and `HOPEGEvaluator` as the followings:
Then, you can use `MacroPEGParser` and `MacroPEGEvaluator` as the followings:

```scala
import com.github.kmizu.hopeg._
val grammar = HOPEGParser.parse(
import com.github.kmizu.macro_peg._
val grammar = MacroPEGParser.parse(
"""
|S = P("") !.; P(r) = "a" P("a" r) / "b" P("b" r) / r;
""".stripMargin
)
val evaluator = HOPEGEvaluator(grammar)
val evaluator = MacroPEGEvaluator(grammar)
```

```scala
Expand Down
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
organization := "com.github.kmizu"

name := "hopeg"
name := "macro_peg"

version := "0.0.4-SNAPSHOT"

Expand All @@ -20,7 +20,7 @@ scaladocBranch := "master"

scalacOptions in (Compile, doc) ++= { Seq(
"-sourcepath", baseDirectory.value.getAbsolutePath,
"-doc-source-url", s"https://github.com/kmizu/hopeg/tree/${scaladocBranch.value}€{FILE_PATH}.scala"
"-doc-source-url", s"https://github.com/kmizu/macro_peg/tree/${scaladocBranch.value}€{FILE_PATH}.scala"
)}

testOptions in Test += Tests.Argument("-u", "target/scalatest-reports")
Expand All @@ -42,7 +42,7 @@ initialCommands in console += {
}

pomExtra := (
<url>https://github.com/kmizu/hopeg</url>
<url>https://github.com/kmizu/macro_peg</url>
<licenses>
<license>
<name>The MIT License</name>
Expand All @@ -51,8 +51,8 @@ pomExtra := (
</license>
</licenses>
<scm>
<url>git@github.com:kmizu/hopeg.git</url>
<connection>scm:git:git@github.com:kmizu/hopeg.git</connection>
<url>git@github.com:kmizu/macro_peg.git</url>
<connection>scm:git:git@github.com:kmizu/macro_peg.git</connection>
</scm>
<developers>
<developer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com
package github
package kmizu
package hopeg
package macro_peg

/** This object provides types representing ASTs of extended PEG.
* It is used as namespace.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com
package github
package kmizu
package hopeg
package macro_peg

import com.github.kmizu.hopeg.Ast.Exp
import com.github.kmizu.macro_peg.Ast.Exp

case class HOPEGEvaluator(grammar: Ast.Grammar) {
case class MacroPEGEvaluator(grammar: Ast.Grammar) {
private val FUNS: Map[Symbol, Ast.Exp] = {
grammar.rules.map{r => r.name -> (if(r.args.isEmpty) r.body else Ast.Fun(r.body.pos, r.args, r.body))}.toMap
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com
package github
package kmizu
package hopeg
package macro_peg

import scala.util.parsing.combinator._
import scala.util.parsing.input.{CharSequenceReader, StreamReader}
import scala.util.parsing.input.Position
import java.io._
import Ast._
/**
* This object provides a parser that parses strings in HOPEG and translates
* them into ASTs of HOPEG (which is like PEGs).
* This object provides a parser that parses strings in Macro PEG and translates
* them into ASTs of Macro PEG (which is like PEGs).
* @author Kota Mizushima
*
*/
object HOPEGParser {
object MacroPEGParser {

/**
* This exception is thrown in the case of a parsing failure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package com
package github
package kmizu
package hopeg
package macro_peg

object HOPEGRunner {
object MacroPEGRunner {
def main(args: Array[String]): Unit = {
tryGrammar(
"palindrome",
HOPEGParser.parse("""
MacroPEGParser.parse("""
|S = P("") !.; P(r) = "a" P("a" r) / "b" P("b" r) / r;
""".stripMargin), "a", "b", "aa", "bb", "ab", "abba", "abbb"
)

tryGrammar(
"a / b",
HOPEGParser.parse("""
MacroPEGParser.parse("""
|S = APPLY2(ALTER, "a", "b") !.; ALTER(x, y) = x / y; APPLY2(F, x, y) = F(F(x)) ;
""".stripMargin), "a", "b", "c"
)

tryGrammar(
"u rule",
HOPEGParser.parse("""
MacroPEGParser.parse("""
|S = u((x -> x), "x"); u(f, x) = f(!x .) (u(f, x))?;
""".stripMargin), "yy", "x"
)
tryGrammar(
"arithmetic",
HOPEGParser.parse(
MacroPEGParser.parse(
"""
|S = Plus0("");
|// '1'を並べた数で自然数を表すとする。
Expand Down Expand Up @@ -70,7 +70,7 @@ object HOPEGRunner {
""".stripMargin), "1+1=11$", "111+11=11111$", "111+1=11111$")
tryGrammar(
"modifiers",
HOPEGParser.parse(
MacroPEGParser.parse(
"""
|S = Modifiers(!"") !.;
|Modifiers(AlreadyLooked) = (!AlreadyLooked) (
Expand All @@ -85,7 +85,7 @@ object HOPEGRunner {
}

def tryGrammar(name: String, grammar: Ast.Grammar, inputs: String*): Unit = {
val evaluator = HOPEGEvaluator(grammar)
val evaluator = MacroPEGEvaluator(grammar)
println("grammar: " + name)
println()
for(input <- inputs) {
Expand Down
34 changes: 17 additions & 17 deletions src/tut/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
## HOPEG: Higher Order Parsing Expression Grammar
## Macro PEG: PEG with macro-like rules

[![Build Status](https://travis-ci.org/kmizu/hopeg.png?branch=master)](https://travis-ci.org/kmizu/hopeg)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.kmizu/hopeg_2.11/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.kmizu/hopeg_2.11)
[![Scaladoc](http://javadoc-badge.appspot.com/com.github.kmizu/hopeg_2.11.svg?label=scaladoc)](http://javadoc-badge.appspot.com/com.github.kmizu/hopeg_2.11/index.html#com.github.kmizu.hopeg.package)
[![Reference Status](https://www.versioneye.com/java/com.github.kmizu:hopeg_2.11/reference_badge.svg?style=flat)](https://www.versioneye.com/java/com.github.kmizu:hopeg_2.11/references)
[![Build Status](https://travis-ci.org/kmizu/macro_peg.png?branch=master)](https://travis-ci.org/kmizu/macro_peg)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.kmizu/macro_peg_2.11/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.kmizu/macro_peg_2.11)
[![Scaladoc](http://javadoc-badge.appspot.com/com.github.kmizu/macro_peg_2.11.svg?label=scaladoc)](http://javadoc-badge.appspot.com/com.github.kmizu/macro_peg_2.11/index.html#com.github.kmizu.macro_peg.package)
[![Reference Status](https://www.versioneye.com/java/com.github.kmizu:macro_peg_2.11/reference_badge.svg?style=flat)](https://www.versioneye.com/java/com.github.kmizu:macro_peg_2.11/references)

HOPEG is an extension of PEG by parametric rule (rule constructor). It seems that expressiveness of HOPEG
is greather than (traditional) PEG since HOPEG can express palindromes. This repository implements a HOPEG
Macro PEG is an extended PEG by macro-like rules. It seems that expressiveness of Macro PEG
is greather than traditional PEG since Macro PEG can express palindromes. This repository implements a Macro PEG
interpreter (or matcher).

### Grammar of HOPEG in Pseudo PEG
### Grammar of Macro PEG in Pseudo PEG

Note that spacing is eliminated.

Expand Down Expand Up @@ -42,13 +42,13 @@ Note that spacing is eliminated.
### Release Note

#### 0.0.3
* [Fix bug of HOPEGEvaluator](https://github.com/kmizu/hopeg/commit/86b7c43ef52b9a6d2e81fcb541aca93e89b276ae)
* [Modifier HOPEG example](https://github.com/kmizu/hopeg/commit/00221379bec06ddf3392e50803f6bf5d1316b579)
* [Fix bug of MacroPEGEvaluator](https://github.com/kmizu/macro_peg/commit/86b7c43ef52b9a6d2e81fcb541aca93e89b276ae)
* [Modifier HOPEG example](https://github.com/kmizu/macro_peg/commit/00221379bec06ddf3392e50803f6bf5d1316b579)

#### 0.0.2

* [Fix bug of HOPEGParser](https://github.com/kmizu/hopeg/commit/a7a72bcffd22401b9fec7a71ff2a5992e6fe7448)
* [Arithmetic HOPEG example](https://github.com/kmizu/hopeg/commit/1aadc5585490a13e6eb7cdbf60547eea1b424052)
* [Fix bug of HOPEGParser](https://github.com/kmizu/macro_peg/commit/a7a72bcffd22401b9fec7a71ff2a5992e6fe7448)
* [Arithmetic HOPEG example](https://github.com/kmizu/macro_peg/commit/1aadc5585490a13e6eb7cdbf60547eea1b424052)

### Usage

Expand All @@ -57,19 +57,19 @@ Note that the behaviour could change.
Add the following lines to your build.sbt file:

```scala
libraryDependencies += ("com.github.kmizu" %% "hopeg" % "0.0.3")
libraryDependencies += ("com.github.kmizu" %% "macro_peg" % "0.0.3")
```

Then, you can use `HOPEGParser` and `HOPEGEvaluator` as the followings:
Then, you can use `MacroPEGParser` and `MacroPEGEvaluator` as the followings:

```tut:silent
import com.github.kmizu.hopeg._
val grammar = HOPEGParser.parse(
import com.github.kmizu.macro_peg._
val grammar = MacroPEGParser.parse(
"""
|S = P("") !.; P(r) = "a" P("a" r) / "b" P("b" r) / r;
""".stripMargin
)
val evaluator = HOPEGEvaluator(grammar)
val evaluator = MacroPEGEvaluator(grammar)
```

```tut
Expand Down

0 comments on commit 8bd5129

Please sign in to comment.