MCPcopy Create free account
hub / github.com/CashScript/cashscript / parseCode

Function parseCode

packages/cashc/src/compiler.ts:111–135  ·  view source on GitHub ↗
(
  code: string,
  errorListener: CashScriptErrorListener = ThrowingErrorListener.INSTANCE,
)

Source from the content-addressed store, hash-verified

109}
110
111export function parseCode(
112 code: string,
113 errorListener: CashScriptErrorListener = ThrowingErrorListener.INSTANCE,
114): Ast {
115 const syntaxErrorListener = new ForwardingErrorListener(errorListener);
116
117 // Lexing (throwing on errors)
118 const inputStream = new CharStream(code);
119 const lexer = new CashScriptLexer(inputStream);
120 lexer.removeErrorListeners();
121 lexer.addErrorListener(syntaxErrorListener);
122 const tokenStream = new CommonTokenStream(lexer);
123
124 // Parsing (throwing on errors)
125 const parser = new CashScriptParser(tokenStream);
126 parser.removeErrorListeners();
127 parser.addErrorListener(syntaxErrorListener);
128 const parseTree = parser.sourceFile();
129 syntaxErrorListener.throwFirstError();
130
131 // AST building
132 const ast = new AstBuilder(parseTree).build() as Ast;
133
134 return ast;
135}

Callers 4

AST.test.tsFile · 0.85
setupFunction · 0.85
Location.test.tsFile · 0.85
compileStringFunction · 0.85

Calls 3

sourceFileMethod · 0.95
throwFirstErrorMethod · 0.95
buildMethod · 0.45

Tested by 1

setupFunction · 0.68