Project

jsgf

0.0
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
A parser and DSL for JSGF files
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.7
~> 10.0
 Project Readme

JSGF

Build Status Gem Version Yard Docs

For all of your Java Speech Grammar Format parsing needs.

Usage

Reading an existing JSGF file is as simple as...

require 'jsgf'

grammar = JSGF.read('example.gram')

Writing to a file is similarly simple.

grammar.write('my_grammar.gram')

You can also write to an IO stream.

File.open('my_grammar.gram', 'w') do |f|
    grammar.write(f)
end

Grammar DSL

The JSGF gem includes a simple DSL for generating new grammars. The syntax follows the the JSGF syntax, but with a few differences.

  • Rule names can be either Symbols or Strings (they're converted to Strings internally)
  • Rules can be referenced using symbols in addition to the angle-bracket syntax used by JSGF
  • Alternations are created using arrays
  • Rules are private by default, however the root rules are automatically made public
grammar = JSGF.grammar 'Turtle' do
    rule quit: 'quit'                       # 'quit' and 'move' are public because
    rule move: 'go :direction :distance'    #   they are the roots of the grammar tree

    rule direction: %w{forward backward}
    rule distance: %w{one two three four five six seven eight nine ten}
end

Atoms can be made optional using the JSGF square-bracket syntax...

grammar = JSGF.grammar 'PoliteTurtle' do
    rule move: '[please] go :direction :distance'
    ...
end

Installation

Add this line to your application's Gemfile:

gem 'jsgf'

And then execute:

$ bundle

Or install it yourself as:

$ gem install jsgf

License

Copyright 2015-2016 Brandon Fosdick bfoz@bfoz.net and released under the BSD license.