ebnf | EBNF parser and generic parser generator for Ruby | Parser library

 by   dryruby Ruby Version: 2.3.1 License: Unlicense

kandi X-RAY | ebnf Summary

kandi X-RAY | ebnf Summary

ebnf is a Ruby library typically used in Utilities, Parser applications. ebnf has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.

This is a Ruby implementation of an EBNF and BNF parser and parser generator. In the primary mode, it supports a Parsing Expression Grammar (PEG) parser generator. This performs more minimal transformations on the parsed grammar to extract sub-productions, which allows each component of a rule to generate its own parsing event. The resulting {EBNF::PEG::Rule} objects then parse each associated rule according to the operator semantics and use a Packrat memoizer to reduce extra work when backtracking. These rules are driven using the {EBNF::PEG::Parser} module which calls invokes the starting rule and ensures that all input is consumed.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              ebnf has a low active ecosystem.
              It has 99 star(s) with 6 fork(s). There are 6 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 1 open issues and 8 have been closed. On average issues are closed in 424 days. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of ebnf is 2.3.1

            kandi-Quality Quality

              ebnf has 0 bugs and 0 code smells.

            kandi-Security Security

              ebnf has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              ebnf code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              ebnf is licensed under the Unlicense License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              ebnf releases are available to install and integrate.
              Installation instructions are not available. Examples and code snippets are available.
              ebnf saves you 10055 person hours of effort in developing the same functionality from scratch.
              It has 20550 lines of code, 220 functions and 69 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed ebnf and discovered the below as its top functions. This is intended to give you an instant insight into ebnf implemented functionality, and help decide if they suit your requirements.
            • Parses the input .
            • Gets the next rule for the first rule .
            • Formats the conditional expression .
            • Returns a string representation of the expression .
            • Processes a new rule .
            • Processes a new Producer .
            • Initializes a new handler .
            • Processes the result of the process .
            • Return the first token in the scanner .
            • Parses a matching string .
            Get all kandi verified functions for this library.

            ebnf Key Features

            No Key Features are available at this moment for ebnf.

            ebnf Examples and Code Snippets

            No Code Snippets are available at this moment for ebnf.

            Community Discussions

            QUESTION

            How many BNF-like grammar specifications does Python have?
            Asked 2022-Apr-08 at 15:29

            There are at least 3 grammar-like specifications within the Python 3.9.1 reference documents 'library-3.9.1.pdf' and 'reference-3.9.1.pdf' (aka https://docs.python.org/3.9/library/ast.html and https://docs.python.org/3.9/reference/grammar.html).

            There is the "abstract grammar" library-3.9.1.pdf, page 1895 that looks like this:

            ...

            ANSWER

            Answered 2022-Apr-08 at 15:29

            The grammar used to build Python isn't on your list at all. You can find it in the source bundle as Grammar/python.gram. Note that it has five different start symbols for different compilation contexts (complete files, interactive input, single expressions, etc.), although most of the grammar is shared. This grammar is actually used by the parser generator to produce the parser actually used by the CPython implementation, so it describes perfectly the inputs accepted by the concrete Python interpreter (of course, subject to change in future versions). As noted in the comments near the top of the file, the syntax of the grammar file itself are defined in a PEP.

            But it's not necessarily useful for documentary purposes, and it is not definitive in the sense that it defines the language, in the sense that one might expect from a language standard. Python is not really standardized, so it might be unreasonable to ask for a definitive reference grammar. But the grammar scattered through the Python reference manual is probably as close as you're going to get. Those productions are for expository purposes, though, and they need to be considered along with the accompanying narrative text. (That's generally true of reference grammars, even for standardized grammars, because a context-free grammar cannot capture all the syntactic aspects of any real-life programming language, possibly with a couple of exceptions. So it's usual that the reference grammar for a language will accept a superset of the set of valid programs, and the narrative in the standard provides additional constraints which cannot be expressed in a CFG.)

            The collected grammar at the end of the reference manual is supposedly a summary of the snippets, but as I understand it, it's generated mechanically from the python.gram file. So it's possible that there are divergences between it and the language described in the manual.

            The abstract grammar listed in the ast module documentation actually defines the structure of the abstract syntax tree, so it's not a grammar at all in the usual sense (i.e. a description of a linear sequence of symbols) but rather a collection of structure definitions, each one describing the nature of a typed node in the abstract syntax tree. It corresponds directly to the objects you'll find in an AST built with the ast module, but it doesn't attempt to constrain the syntax of a program being parsed. The text in the library reference is the contents of an actual source file, Parser/Python.asdl, which is mechanically processed into declarations and code used by the CPython parser to produce an AST.

            Source https://stackoverflow.com/questions/71788867

            QUESTION

            How to use EBNF grammar for a small language?
            Asked 2022-Apr-08 at 00:55

            I am working on an assignment that parses a file with EBNF grammar, I am a little confuse on the recursive function work.

            -first three functions:

            ...

            ANSWER

            Answered 2022-Apr-07 at 20:58

            DeclBlock should only be called once in this language. DeclStmt can be called multiple times. A DeclStmt is defined to be one or more Ident followed by :, followed by a type, then ending in a ;.

            After you read the ; at the end of a DeclStmt, you'd then read the next token to decide what to do next. If the next token is another Ident you know you're at the start of another DeclStmt, so you'd call that again. If it's anything else, you know you're at the start of ProgBody. (I'm assuming the last bit. Normally you'd look for the token that starts a ProgBody, but that's not shown.)

            Source https://stackoverflow.com/questions/71788682

            QUESTION

            EBNF or followed by statement
            Asked 2022-Jan-26 at 02:34

            I am looking at this line of EBNF:

            ...

            ANSWER

            Answered 2022-Jan-26 at 02:34

            The | would be the most-loosely bound thing. In other words:

            is equivalent to | ([])

            and NOT equivalent to ( | )[].

            So your first interpretation.

            Source https://stackoverflow.com/questions/70858027

            QUESTION

            Using Perl look-ahead assertion to find individual list
            Asked 2022-Jan-23 at 20:48

            Given a list like this:

            ...

            ANSWER

            Answered 2022-Jan-23 at 20:48

            With possible comments (/* ... */) that need be omitted:

            Source https://stackoverflow.com/questions/70702953

            QUESTION

            How are Scheme closures formally defined?
            Asked 2022-Jan-23 at 09:34

            I’ve recently ventured into the awesome land of writing a Scheme interpreter, and I’ve run into a roadblock: closures. From what I understand, they encapsulate a local environment with a procedure that gets restored every time the closure is called (this may not be exactly right). The issue that I can’t seem to find anywhere online is how a closure is formally defined i.e., in an EBNF grammar. Most examples I’ve seen say that a closure is a procedure with zero arguments that has a lambda expression nested inside a let expression. Is this the only way to define a Scheme closure? More importantly, if there’s no formal way to formally define a closure, how do you actually interpret it? What happens if you translate all let expressions to lambdas? For example, if I declare a closure as such

            ...

            ANSWER

            Answered 2022-Jan-20 at 15:13

            I don't think it's helpful, today, to think of closures as some special magic thing: long ago in languages in the prehistory of Scheme they were, but in modern languages they are not a special thing at all: they just follow from the semantics of the language in an obvious way.

            The two important things (these are both quotes from R7RS, both from section 1.1 are these:

            Scheme is a statically scoped programming language. Each use of a variable is associated with a lexically apparent binding of that variable.

            and

            All objects created in the course of a Scheme computation, including procedures and continuations, have unlimited extent.

            What this means is that Scheme is a language with lexical scope and indefinite extent: any variable binding exists for as long as there is possibility of reference. And, conveniently, you can always tell statically (ie by reading the code) what bindings a bit of code may refer to.

            And the important thing here is that these rules are absurdly simple: there are no weird special cases. If a reference to a variable binding is visible in a bit of code, which you can tell by looking at the code, then it is visible. It's not visible only sometimes, or only during some interval, or only if the Moon is gibbous: it's visible.

            But the implication of the rules is that procedures, somehow, need to remember all the bindings that they reference or may reference and which were in scope when they were created. Because scope is static it is always possible to determine which bindings are in scope (disclaimer: I'm not sure how this works formally for global bindings).

            So then the very old-fashioned definition of a closure would be a procedure defined in a scope in which bindings to which it refers exist. This would be a closure:

            Source https://stackoverflow.com/questions/70780407

            QUESTION

            Is there an official (complete) BNF or EBNF for the CLIPS language
            Asked 2022-Jan-21 at 17:41

            I am looking for an official BNF/EBNF for The CLIPS Programming Language, so that I can write a parser/interpreter that groks (understands) CLIPS rules.

            I have searched online, including the official CLIPS documentation, but I have only managed to find sections of the BNF (not the entire BNF).

            Does anyone have a source for the COMPLETE (E)BNF for the grammar?

            ...

            ANSWER

            Answered 2022-Jan-21 at 17:41

            The only BNF available is from Appendix G, CLIPS BNF, of the Basic Programming Guide. That covers all of the constructs and function calls that are not special forms. For special forms (functions that have non-standard syntax such as the fact query functions), the BNF is specified in the section describing that function.

            Source https://stackoverflow.com/questions/70801721

            QUESTION

            What is the meaning of `~` in python grammar
            Asked 2021-Dec-30 at 13:22

            I was going through the python grammer specification and find the following statement,

            ...

            ANSWER

            Answered 2021-Nov-19 at 12:30

            It's documented in PEP 617 under Grammar Expressions:

            ~

            Commit to the current alternative, even if it fails to parse.

            rule_name: '(' ~ some_rule ')' | some_alt

            In this example, if a left parenthesis is parsed, then the other alternative won’t be considered, even if some_rule or ‘)’ fail to be parsed.

            The ~ basically indicates that once you reach it, you're locked into the particular rule and cannot move onto the next rule if the parse fails. PEP 617 mentions earlier that | some_alt can be written in the next line.

            Source https://stackoverflow.com/questions/69097732

            QUESTION

            What are the hex ranges for Unicode categories?
            Asked 2021-Dec-12 at 01:07

            I am building a parser in c for the Cooklang language. It is described here in EBNF: https://github.com/cooklang/spec/blob/main/EBNF.md

            I am building the parser using flex/bison. I need to take input in the form of UTF-8 instead of just ASCII. Thing is, I am only taking in some UTF-8 characters, all the general categories except for C and N, and some new line characters. I also need to be able to tell which category the character is from so this is not just copying and pasting Unicode strings the same way one does with C strings.

            I found this: https://lists.gnu.org/archive/html/help-flex/2005-01/msg00043.html as a good script for making hex ranges into lexer expressions to capture those hex ranges. But the issue I still have is figuring out which hex ranges to use for the different categories.

            So, what hex ranges represent the different general categories of Unicode? If there is no single hex range that includes the entire category and only the code points in that category, where can I find a list of all the code points in it?

            Let me know if you need more information.

            ...

            ANSWER

            Answered 2021-Dec-12 at 01:07

            I don't know if Flex and Bison are the best tools for this particular problem. First, your grammar does not easily fit a model in which the input can be unambiguously divided into tokens, and then those tokens parsed with a limited lookahead context-free grammar.

            Perhaps you had in mind that flex would just categorise each incoming symbol and let the parser deal with assembling individual characters into grammatical structures. That can be done, although it's not a common approach. Usually, we would make a word a single token, for example. That will be difficult in this case, though, because there are contexts in which you want a word consisting only of digits to be considered to be a number, and other contexts in which it should be treated as a word (leaving aside for the moment the difficulty of handling text). That could possibly be accomplished, but it would require some tweaking of the grammar, and I'm not at all sure that all ambiguities could be resolved during a left-to-right parse.

            It's certainly possible to use Flex only to categorise UTF-8 sequences into individual characters, segregated by general major category (perhaps with some minor refinements). I guess that's what your question is asking about, and the bad news is that Flex really isn't designed for UTF-8 processing, and furthermore Unicode was not designed with the goal of coalescing codepoint ranges. Unicode tries to place codepoints so that characters which come from the same script are all placed in a few aligned blocks of codepoints, leaving some codepoints unused in order to avoid mixing characters from some other script. Moreover, the unused codes are not always at the end of the blocks, because sometimes codepoints are assigned according to some algorithm --like capital letters are at a fixed offset from the equivalent lower-case letter-- which doesn't produce all codepoints (perhaps because sometimes the upper-to-lower case mapping isn't one-to-one.) You can see this at play in the two main blocks of Greek characters, with commonly used characters mostly assigned to the range 0x0370-0x03FF, with accented and other less commonly-used characters in the code block 0x1F00-0x1FFF. Some other blocks are used for historical symbols, so you can spend quite a bit of time exploring that rabbit hole if you're interested enough.)

            Once that pattern is repeated over and over again, you find that there are something like a thousand small runs of unassigned characters (category Cn) which interrupt the runs of other character categories. So you could collect all the possible UTF-8 sequences for each character category, but you would end up with a lot of ranges, possibly exceeding Flex's limits on the size of a pattern [See Notes 1 and 2].

            Anyway, I think that idea is a dead-end, because you'll have immense problems writing a one-symbol lookahead grammar if the symbols are single characters. It's not even obvious to me how you might write a one-symbol lookahead grammar if you were to tokenise into words. Take, for example, the EBNF productions:

            Source https://stackoverflow.com/questions/70312231

            QUESTION

            Convert a dfa to rule for a asterisk case
            Asked 2021-Nov-17 at 06:30

            Here is a simple but very common grammar rule case in EBNF format, the Statements is a none terminal symbol and Statement is none terminal symbol:

            ...

            ANSWER

            Answered 2021-Nov-17 at 06:30

            I'm not really sure I understand your question.

            If you just have a single production for a non-terminal and that production just has a single repetition operator, either at the beginning or the end, you can apply a simple desugaring: (Here α and β are sequences of grammar symbols (but not EBNF symbols), and α might be empty.)

            Source https://stackoverflow.com/questions/69998471

            QUESTION

            EBNF or BNF of LINQ? Associativity of join? Other clauses?
            Asked 2021-Oct-16 at 21:08

            I am in search of BNF or EBNF of LINQ. It seems as if a grammar specification of C# is not readily available anywhere, but then, the LINQ fragment might be easy to infer, if not found.

            In particular, I cannot figure out the precedence/associativity of join. Note that join may include nested queries, for example:

            ...

            ANSWER

            Answered 2021-Oct-16 at 17:37

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install ebnf

            You can download it from GitHub.
            On a UNIX-like operating system, using your system’s package manager is easiest. However, the packaged Ruby version may not be the newest one. There is also an installer for Windows. Managers help you to switch between multiple Ruby versions on your system. Installers can be used to install a specific or multiple Ruby versions. Please refer ruby-lang.org for more information.

            Support

            Full documentation available on Rubydoc.info.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries

            Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Parser Libraries

            marked

            by markedjs

            swc

            by swc-project

            es6tutorial

            by ruanyf

            PHP-Parser

            by nikic

            Try Top Libraries by dryruby

            rack-throttle

            by dryrubyRuby

            openpgp.rb

            by dryrubyRuby

            tor.rb

            by dryrubyRuby

            php.rb

            by dryrubyRuby

            rsa.rb

            by dryrubyRuby