Skip to content

Language Grammar Builder. All the grammars (html, css, etc.) are currently works in progress :)

Notifications You must be signed in to change notification settings

grammarjs/grammar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Parsing Expression Grammar

experimental Build Status

PEG-like expression builder for JavaScript. <1kb.

Installation

$ npm install grammarjs-grammar

browser:

$ component install grammarjs/grammar

Features

  • easily define a custom parsing expression grammar (PEG)
  • reuse and recombine PEGs with .use(grammar)
  • expressions can be referenced by name, so complex grammars are very readable

Overview

A grammar is a set of expressions that share a common namespace. This means you can define named expressions within a grammar, and access them from anywhere else within the grammar.

Expressions can't exist outside of a grammar. A grammar itself is just an expression, it is the start of the expression hierarchy.

You can nest grammars, and so build on top of them easily!

Examples

See the tests for examples. Basically, in building a grammar, you are just building a Concrete Syntax Tree. This can be used for syntax highlighting, linting, and lots of other things. The next goal is to then find a standard mapping of the CST to the AST (Abstract Syntax Tree). This way you can define a grammar once, use it in an editor if you want, and also convert it to executable code.

Test

make test

Selectors

punctuation
punctuation.whitespace
punctuation.definition
literal
literal.string
literal.string.quote
literal.string.quote.double
literal.string.quote.single
literal.string
literal.number.integer
literal.number.decimal
literal.boolean
literal.boolean
keyword.control
keyword.other.var
keyword.operator
keyword.operator.gte
keyword.operator.percent
comment
comment.line
comment.line.dash
comment.line.dash.double
comment.line.percent
comment.block
type.struct (or entity?)
type.function
type.object
type.array
type.tag
type.pointer
type.interface
type.class
type.channel
type.map
constant
character.source
character.unicode
expression
expression.assignment
statement
statement.if
statement.switch
statement.continue
statement.debugger
statement.for
statement.while
statement.return
operator
delimiter https://golang.org/ref/spec
declaration
declaration.variable
declaration.class
declaration.type
declaration.function
support

Notes

Licence

MIT

About

Language Grammar Builder. All the grammars (html, css, etc.) are currently works in progress :)

Resources

Stars

Watchers

Forks

Packages

No packages published