Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

yaskhan/vpegu

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VPEGU

VPEGU is a Packrat PEG parser generator for the V programming language.

Features

  • Full PEG support (sequences, choices, repetitions, predicates)
  • Packrat parsing with memoization for O(n) time complexity
  • Generator that produces standalone V code for your parser
  • Support for semantic actions

Installation

git clone https://github.com/vpegu/vpegu
cd vpegu
v .

Usage

Define your grammar

Create a .peg file, for example arithmetic.peg:

Expression <- Term (('+' / '-') Term)*
Term <- Factor (('*' / '/') Factor)*
Factor <- Number / '(' Expression ')'
Number <- [0-9]+

Generate a parser

vpegu arithmetic.peg --output parser.v

Use the generated parser

import os

fn main() {
    input := "1+2*3"
    mut p := PackratParser{input: input}
    result := p.parse()
    if result.success {
        println("Parsed successfully!")
    } else {
        println("Parse failed")
    }
}

License

MIT

About

Peg, Parsing Expression Grammar, is an implementation of a Packrat parser generator.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.