Skip to content
/ vpegu Public

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

License

Notifications You must be signed in to change notification settings

yaskhan/vpegu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

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

No packages published

Contributors 2

  •  
  •