Permalink
Browse files

Fix some minification problems and format the metagrammar.

  • Loading branch information...
1 parent e9cc8bc commit 660fbed56fe370174e42be4c63cb7d77034fce33 @jcoglan committed May 1, 2010
Showing with 52 additions and 35 deletions.
  1. +1 −1 bin/compile.js
  2. +1 −1 jake.yml
  3. +4 −4 source/stake/compiler/grammar.js
  4. +45 −28 source/stake/meta_grammar.peg
  5. +1 −1 spec/runner.js
View
@@ -5,7 +5,7 @@ importPackage(java.io);
importPackage(java.lang);
load('vendor/js.class/build/min/core.js');
-load('build/stake.js');
+load('build/stake-min.js');
function readFile(file) {
var f = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
View
@@ -9,7 +9,7 @@ builds:
suffix: false
min:
shrink_vars: true
- private: true
+ private: false
packages:
stake:
@@ -25,12 +25,12 @@ Stake.Compiler.extend({
builder.class_(this.grammarName() + 'Parser', function(builder) {
builder.include_(this.grammarName());
builder.method_('initialize', ['input'], function(builder) {
- builder.ivar_('input', 'input')
- builder.ivar_('offset', '0')
- builder.ivar_('nodeCache', '{}')
+ builder.ivar_('input', 'input');
+ builder.ivar_('offset', '0');
+ builder.ivar_('nodeCache', '{}');
});
builder.method_('parse', [], function(builder) {
- builder.var_('result', 'this["__consume__" + this.root]()')
+ builder.var_('result', 'this["__consume__" + this.root]()');
builder.return_(builder.offset_() + ' === ' + builder.input_() + '.length ? result : null');
});
builder.classMethods_(function(builder) {
@@ -1,49 +1,66 @@
grammar Stake.MetaGrammar
- grammar <- space* grammar_name rules:(space* grammar_rule)+ space* <Stake.Compiler.Grammar>
- grammar_name <- "grammar " object_identifier
- grammar_rule <- identifier assignment parsing_expression <Stake.Compiler.GrammarRule>
- assignment <- space+ "<-" space+
- parsing_expression <- choice_expression / choice_part
+
+ grammar <- space* grammar_name
+ rules:(space* grammar_rule)+ space*
+ <Stake.Compiler.Grammar>
+
+ grammar_name <- "grammar " object_identifier
+
+ grammar_rule <- identifier assignment parsing_expression
+ <Stake.Compiler.GrammarRule>
+
+ assignment <- space+ "<-" space+
+
+ parsing_expression <- choice_expression / choice_part
+
parenthesised_expression <- "(" space* parsing_expression space* ")"
- choice_expression <- first_expression:choice_part
- rest_expressions:(space+ "/" space+ expression:choice_part)+
- <Stake.Compiler.Choice>
+ choice_expression <- first_expression:choice_part
+ rest_expressions:(space+ "/" space+ expression:choice_part)+
+ <Stake.Compiler.Choice>
- choice_part <- (sequence_expression / sequence_part)
- (space+ type_expression)?
- <Stake.Compiler.ChoicePart>
+ choice_part <- (sequence_expression / sequence_part)
+ (space+ type_expression)?
+ <Stake.Compiler.ChoicePart>
- type_expression <- "<" object_identifier ">"
+ type_expression <- "<" object_identifier ">"
sequence_expression <- first_expression:sequence_part
rest_expressions:(space+ sequence_part)+
<Stake.Compiler.Sequence>
- sequence_part <- label? expression:(quantified_atom / atom) <Stake.Compiler.SequencePart>
- quantified_atom <- atom quantifier <Stake.Compiler.Repeat>
+ sequence_part <- label? expression:(quantified_atom / atom)
+ <Stake.Compiler.SequencePart>
- atom <- parenthesised_expression
- / predicated_atom
- / reference_expression
- / string_expression
- / any_char_expression
- / char_class_expression
+ quantified_atom <- atom quantifier <Stake.Compiler.Repeat>
+
+ atom <- parenthesised_expression
+ / predicated_atom
+ / reference_expression
+ / string_expression
+ / any_char_expression
+ / char_class_expression
+
+ predicated_atom <- predicate:("&" / "!") atom
+ <Stake.Compiler.PredicatedAtom>
- predicated_atom <- predicate:("&" / "!") atom <Stake.Compiler.PredicatedAtom>
reference_expression <- identifier !assignment <Stake.Compiler.Reference>
- string_expression <- "\"" ("\\" . / [^"])* "\""
- <Stake.Compiler.String>
+ string_expression <- "\"" ("\\" . / [^"])* "\""
+ <Stake.Compiler.String>
any_char_expression <- "." <Stake.Compiler.AnyChar>
char_class_expression <- "[" "^"? ("\\" . / [^\]])+ "]"
<Stake.Compiler.CharClass>
- label <- identifier ":"
- object_identifier <- identifier ("." identifier)*
- identifier <- [a-zA-Z_$] [a-zA-Z0-9_$]*
- quantifier <- "?" / "*" / "+"
- space <- [\s\n\r\t]
+ label <- identifier ":"
+
+ object_identifier <- identifier ("." identifier)*
+
+ identifier <- [a-zA-Z_$] [a-zA-Z0-9_$]*
+
+ quantifier <- "?" / "*" / "+"
+
+ space <- [\s\n\r\t]
View
@@ -2,7 +2,7 @@ JSCLASS_PATH = 'vendor/js.class/build/src'
load(JSCLASS_PATH + '/loader.js')
JS.Packages(function() { with(this) {
- file('build/stake.js').provides('Stake')
+ file('build/stake-min.js').provides('Stake')
autoload(/^(.*)Spec$/, {from: 'spec', require: '$1'})
}})

0 comments on commit 660fbed

Please sign in to comment.