@Test public void test2() { String file = "contract Coin {\n" + " " " address public minter;\n" + " mapping (address => uint) public balances;\n" + "\n" + " " " event Sent(address from, address to, uint amount);}"; SolidityParsingPhase parser = new SolidityParsingPhase(); SourceUnitContext suc = parser.parse(file); ContractDefinitionContext cdc = suc.contractDefinition().get(0); assertThat(cdc).isNotNull(); List<ContractPartContext> cpcList = cdc.contractPart(); assertThat(cpcList).hasSize(3); assertThat(cpcList.get(0).stateVariableDeclaration()).isNotNull(); assertThat(cpcList.get(1).stateVariableDeclaration()).isNotNull(); assertThat(cpcList.get(2).eventDefinition()).isNotNull(); }
public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); }
SolidityParsingPhase { public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); } }
SolidityParsingPhase { public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); } SolidityParsingPhase(); }
SolidityParsingPhase { public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); } SolidityParsingPhase(); SourceUnitContext parse(String fileContents); SourceUnitContext parse(CharStream cs); void addCommentsToSet(List<? extends Token> tokens); Integer getEmptyLines(); void setEmptyLines(Integer emptyLines); Integer getLinesOfComments(); TokenStream getTokens(); }
SolidityParsingPhase { public SourceUnitContext parse(String fileContents) { CharStream cs = CharStreams.fromString(fileContents); SolidityLexer sl = new SolidityLexer(cs); CommonTokenStream tokenStream = new CommonTokenStream(sl); tokenStream.fill(); SolidityParser parser = new SolidityParser(tokenStream); parser.setErrorHandler(new ErrorStrategy()); addCommentsToSet(tokenStream.getTokens()); this.tokens = parser.getTokenStream(); return parser.sourceUnit(); } SolidityParsingPhase(); SourceUnitContext parse(String fileContents); SourceUnitContext parse(CharStream cs); void addCommentsToSet(List<? extends Token> tokens); Integer getEmptyLines(); void setEmptyLines(Integer emptyLines); Integer getLinesOfComments(); TokenStream getTokens(); final Set<Token> comments; }