/** * newGrammarFromURL */ public static JSGFRuleGrammar NewGrammarFromJSGF(URL url, JSGFRuleGrammarFactory factory) { TextReader reader; BufferedStream stream = new BufferedStream(url.OpenStream(), 256); JSGFEncoding encoding = GetJSGFEncoding(stream); if ((encoding != null) && (encoding.Encoding != null)) { Console.WriteLine("Grammar Character Encoding \"" + encoding.Encoding + "\""); reader = new StreamReader(stream, encoding.GetEncoding); } else { if (encoding == null) { Console.WriteLine("WARNING: Grammar missing self identifying header"); } reader = new StreamReader(stream); } return(NewGrammarFromJSGF(reader, factory)); }
/** * newGrammarFromJSGF - Once JavaCC supports Readers we will change this */ public static JSGFRuleGrammar NewGrammarFromJSGF(Stream i, JSGFRuleGrammarFactory factory) { JSGFRuleGrammar grammar = null; if (_parser == null) { _parser = new JSGFParser(i); } else { _parser.ReInit(i); } try { grammar = _parser.GrammarUnit(factory); return(grammar); } catch (ParseException e) { Token etoken = e.CurrentToken; JSGFGrammarParseException ge = new JSGFGrammarParseException(etoken.BeginLine, etoken.BeginColumn, "Grammar Error", e.Message); throw ge; } }
public JSGFRuleGrammar GrammarDeclaration(JSGFRuleGrammarFactory factory) { String s; JSGFRuleGrammar grammar = null; Token t = null; t = jj_consume_token(Grammar); s = Name(); jj_consume_token(26); grammar = factory.NewGrammar(s); if (grammar != null && t != null && t.SpecialToken != null) { if (t.SpecialToken.Image != null && t.SpecialToken.Image.StartsWith("/**")) { JSGFRuleGrammar JG = grammar; JG.AddGrammarDocComment(t.SpecialToken.Image); } } { if (true) { return(grammar); } } }
public JSGFRuleGrammar GrammarUnit(JSGFRuleGrammarFactory factory) { JSGFRuleGrammar grammar = null; switch ((_jj_ntk == -1) ? jj_ntk() : _jj_ntk) { case Identifier: IdentHeader(); break; default: jj_la1[0] = jj_gen; break; } grammar = GrammarDeclaration(factory); //label_1: var label_1 = false; while (true) { switch ((_jj_ntk == -1) ? jj_ntk() : _jj_ntk) { case Import: break; default: jj_la1[1] = jj_gen; label_1 = true; break; } if (label_1) { break; } ImportDeclaration(grammar); } //label_2: var label_2 = false; while (true) { switch ((_jj_ntk == -1) ? jj_ntk() : _jj_ntk) { case Public: case 28: ; break; default: jj_la1[2] = jj_gen; label_2 = true; break; } if (label_2) { break; } RuleDeclaration(grammar); } jj_consume_token(0); { if (true) { return(grammar); } } }