/cpp/src/main/java/com/google/test/metric/cpp/Parser.java
Java | 49 lines | 28 code | 6 blank | 15 comment | 0 complexity | 5152da20ee16532606657b76cd37d488 MD5 | raw file
1/* 2 * Copyright 2008 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16package com.google.test.metric.cpp; 17 18import com.google.test.metric.cpp.dom.TranslationUnit; 19 20import java.io.CharArrayReader; 21import java.io.InputStream; 22import java.io.InputStreamReader; 23import java.io.Reader; 24 25public class Parser { 26 27 public TranslationUnit parse(InputStream in) throws Exception { 28 RootBuilder builder = new RootBuilder(); 29 Reader reader = new InputStreamReader(in); 30 InternalLexer lexer = new InternalLexer(reader); 31 InternalParser parser = new InternalParser(lexer); 32 parser.translation_unit(builder); 33 return builder.getNode(); 34 } 35 36 public TranslationUnit parse(String source) throws Exception { 37 return this.parse(source, new NodeDictionary()); 38 } 39 40 public TranslationUnit parse(String source, NodeDictionary dict) 41 throws Exception { 42 RootBuilder builder = new RootBuilder(dict); 43 Reader reader = new CharArrayReader(source.toCharArray()); 44 InternalLexer lexer = new InternalLexer(reader); 45 InternalParser parser = new InternalParser(lexer); 46 parser.translation_unit(builder); 47 return builder.getNode(); 48 } 49}