Giter Club home page Giter Club logo

hera's People

Contributors

edemaine avatar strd6 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

edemaine

hera's Issues

The example code in README.md does not work

The example code in README.md does not work:

Hera = require("hera")
fs = require("fs")

source = fs.readFileSync("cool-grammar.hera")

rules = Hera.parse(source, {
  filename: path
})

// Generate parser.js source code
parserSource = Hera.generate(rules)
fs.writeFile("cool-parser.js", parserSource)
parser = require("./cool-parser")
// or generate parser object
parser = Hera.generate(rules, true)

parser.parse("text that my cool parser should parse")

The first problem is the first require. It should be Hera = require("@danielx/hera").
The second problem is that the hera API are outdated. The latest API are tested in https://github.com/DanielXMoore/Hera/blob/main/test/main.coffee.

Skipping empty strings

Here's a small idea for Hera optimization: skip matching the empty string literal "". We use this ~70 times in the Civet grammar, mostly for declarative rules, which I imagine get hit a lot (you probably know better).

Given that it always matches, we shouldn't need to build/call $L at all. I think this optimization could be in compileOp but I haven't understood this code yet to know how to try it.

Optional Assertion

I recently wanted to do something like:

HashThis
  LengthShorthand:id &( ( _+ ( ( Not __ In ) / In ) ) )?:beforeIn ->
    if (beforeIn) ...

but ended up needing to do:

LengthShorthand:id ( &( _+ ( ( Not __ In ) / In ) ) "" )?:beforeIn ->
  if (beforeIn != null) ...

This is because assertions always return undefined since they fail the parse if not met. This causes issue with ? because it returns undefined if the parse wasn't matched so there's not a simple way find out whether the optional assertion matched or not.

It would be nice if optional assertions translated to true/false for whether the assertion passes or fails.

Rule
  A &B?:b ->
    // b is `true` or `false`

Omitting from `$0`

  • -Foo omits Foo from $0, and doesn't assign it $i index.
  • &/! do this automatically (this would be a breaking change, potentially requiring all grammars to be rewritten, as it shifts numeric indexing, unless we still assign them $i indices)
  • Alternative: ^Foo selects Foo for $0 (omitting others not marked ^)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.