Giter VIP home page Giter VIP logo

pegasus's Introduction

Pegasus

Pegasus is a PEG parser for Odin, it's meant to be very efficient for parsing DSLs or prototyping a language.

If you want to make use of it I recommend getting aquainted with PEG small grammar language here.

Here is a simple example that you can find in lib/main.odin:

import "shared:pegasus" // I usually have a hardlink to the library in Odin's `shared` folder

main :: proc() {
	grammar := `
Expr   		<- Space SubOp 

SubOp			<- AddOp (Sub AddOp)* { Numeral }
AddOp			<- DivOp (Add DivOp)*
DivOp			<- MulOp (Div MulOp)*
MulOp			<- PowOp (Mul PowOp)*
PowOp			<- Term (Pow Term)*
Term   		<- Atom / OParen Expr CParen

Pow				<- '^' Space
Mul				<- '*' Space
Div				<- '/' Space
Add				<- '+' Space
Sub				<- '-' Space

OParen 		<- '(' Space
CParen 		<- ')' Space

Atom			<- Numeral

Numeral 	<- Number Space
Number  	<- [0-9]+
Space   	<- (' ' / '\t' / EndOfLine)*
EndOfLine <- '\r\n' / '\n' / '\r'
EndOfFile <- !.
	`
	subject := "23 + 2 +(1* 2) ^ 2"
	is_match, pos, captures, _ := match(grammar, subject)
	if is_match {
		log.success("matched til position", pos, "|", subject[:pos])
		log.info(captures)
	} else {
		log.error("matched til position", pos, "|", subject[:pos])
	}
}

In Progress

TODO:

  • Implement Pattern logic
  • Implement Memoization Tree
  • Implement Input abstraction
  • Implement Charset abstraction
  • Implement VM
  • Fix encoding issues
  • Get regex based syntax for parsing .peg
  • Improve Charset abstraction using Odin bit_set
  • Fix issue with re not compiling string grammars
  • Create examples for the library
  • Add API to parse specific grammars
  • Add a CLI to interface with the grammars to parse
  • Figure out captures

pegasus's People

Contributors

dvrd avatar

Stargazers

Any avatar Justin Snyder avatar

Watchers

 avatar

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.