/cpp/src/main/java/com/google/test/metric/cpp/Parser.java

http://testability-explorer.googlecode.com/ · 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. */
  16. package com.google.test.metric.cpp;
  17. import com.google.test.metric.cpp.dom.TranslationUnit;
  18. import java.io.CharArrayReader;
  19. import java.io.InputStream;
  20. import java.io.InputStreamReader;
  21. import java.io.Reader;
  22. public class Parser {
  23. public TranslationUnit parse(InputStream in) throws Exception {
  24. RootBuilder builder = new RootBuilder();
  25. Reader reader = new InputStreamReader(in);
  26. InternalLexer lexer = new InternalLexer(reader);
  27. InternalParser parser = new InternalParser(lexer);
  28. parser.translation_unit(builder);
  29. return builder.getNode();
  30. }
  31. public TranslationUnit parse(String source) throws Exception {
  32. return this.parse(source, new NodeDictionary());
  33. }
  34. public TranslationUnit parse(String source, NodeDictionary dict)
  35. throws Exception {
  36. RootBuilder builder = new RootBuilder(dict);
  37. Reader reader = new CharArrayReader(source.toCharArray());
  38. InternalLexer lexer = new InternalLexer(reader);
  39. InternalParser parser = new InternalParser(lexer);
  40. parser.translation_unit(builder);
  41. return builder.getNode();
  42. }
  43. }