Comments (4)
Hello and welcome!
It sounds like that should be possible already using the Grammar interface (note that the Grammar module already exposes its internals if you import Text.Earley.Grammar). What is the problem with that approach?
Exposing the internals is sometimes a good idea, but note that the internals exposed in Parser are only used while parsing and are very implementation-specific, why I'd like to get some more information about your use-case before I merge your changes. :)
Thanks!
from earley.
My use case is to transform a free alternative into an Earley Prod
. So I'm wrapping the types in this package. The sharing is observed by a function that caches another function by reference (via StableName, like https://hackage.haskell.org/package/vault or like http://packdeps.haskellers.com/reverse/data-reify ). See https://github.com/sboosali/commands-core/blob/observed-sharing/sources/Data/RefCache.hs#L117 if interested.
it would replace Earley's grammar
, looking maybe like this (probably doesn't typecheck, and still learning about Rank2 types and stuff, but):
observeSharing :: (forall x. f x -> g x) -> Alter f a -> IO (Alter g a)
shareEarleyProduction :: Symbol a -> ST z (E.Prod z e t a)
shareEarleyProduction = \case
NonTerminal rhs -> do
let p = getEarleyProduction rhs
c <- newSTRef =<< newSTRef mempty
nr <- newSTRef Nothing
return$ NonTerminal (Rule p nr c) (Pure id)
Terminal t -> _
induceEarleyParser :: ListLike i t => (Alter Symbol a) -> i -> ST z (E.Result z e i a)
induceEarleyParser ps xs = do
qs <- observeSharing shareEarleyProduction ps
s <- initialState (runAlter id qs)
parse [s] [] [] (return ()) [] 0 xs
where Alter
is the free alternative, and Symbol
holds some grammatical primitives like terminals or wildcards, as well as a right-hand side that should be shared; observeSharing
calls cacheByRef
.
e.g. in the grammar:
root :: Alter Symbol Root
root = ReplaceWith <$> t"replace" <*> phrase <*> t"with" <*> phrase
<|> Phrase <$> phrase
<|> ...
phrase = _
with this (non-monadic) flavor of observed sharing, each phrase
(rather, the Earley Prod
induced by it) shares the same STRef
s, after calling induceEarleyParser
on root
.
I tried a simpler API with a MonadFix
that observes sharing (like Earley's Grammar
), but I couldn't convert it to an Earley Grammar
.
I hope that made sense, I'm still figuring this all out.
p.s. here's some exposing-internals-on-general-principles propaganda https://www.reddit.com/r/haskell/comments/2uoton/edward_kmett_encapsulation_vs_code_reuse/ :-)
from earley.
OK. I still think that should be possible just with Grammar
but either way it won't hurt to expose the internals.
I'd be interested to see what you come up with later. :)
from earley.
thanks!
On Thursday, July 2, 2015, Olle Fredriksson [email protected]
wrote:
โ
Reply to this email directly or view it on GitHub
#8 (comment).
(this message was composed with dictation: charitably interpret typos)Sam
Boosalis
from earley.
Related Issues (20)
- list = listLike? HOT 3
- Q: How to do error recovery? HOT 1
- Wrong(?) result on some grammars with infinite results HOT 10
- Is Earleyโs implementation related to Marpa? HOT 3
- Add a `eof` terminal HOT 5
- Behavior of Semigroup/Monoid instances for Prod? HOT 5
- Capture result as well as matched tokens HOT 2
- Generate ABNF/EBNF from Earley grammar HOT 1
- Suggestion: Make it so that `<$` rules return at most one result. HOT 3
- Parsing into a list delimited by a token HOT 5
- INDENT and DEDENT HOT 5
- feature: constraint validation of production parse result HOT 7
- Please add tags "test ambiguity" etc HOT 2
- Crashes if grammar is infinitely ambiguous on given input HOT 11
- Is it okey to use "many" and heavily use Applicative parsing techniques? HOT 2
- Diverges with sepEndBy from parser-combinator HOT 1
- Report doesn't include enough information HOT 2
- Is there any possible optimization for getting non-exhaustive outputs for ambiguous grammars HOT 1
- Disambiguate/Filter productions HOT 1
- Missing case for Constraint for fmap and <*> HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from earley.