How to parse sources in different languages

We can parse multiple languages out of the box. Parsing generates an abstract syntax tree that can be both visualized and queried.

Consider this example in which we get a JavaScript file from a GitHub repository (go ahead and inspect the result):

js := ZnClient new 
	url: 'https://raw.githubusercontent.com/zooniverse/mobile/a0a7fe122790fc47d8d2c5931a084bcc52518e4e/src/utils/workflow-utils.js';
	get.
  

To parse it, we simply invoke the JSParser SmaCCGLRParser subclass: #JSParser instanceVariableNames: '' classVariableNames: '' package: 'SmaCC_Javascript_Parser' .

JSParser parse: js
  

There is a significant library of parsers already available as subclasses of SmaCCParser Object subclass: #SmaCCParser instanceVariableNames: 'scanner currentToken errorToken stateStack nodeStack errorHandler' classVariableNames: '' package: 'SmaCC_Runtime' . Browse the hierarchy below to form an idea.

Other examples

JSX

js := ZnClient new 
	url: 'https://raw.githubusercontent.com/zooniverse/mobile/a0a7fe122790fc47d8d2c5931a084bcc52518e4e/src/components/Button.js';
	get.
JSXParser parse: js
  

Python

python := ZnClient new
	url: 'https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/python/platform/app.py';
	get.
PythonParser parse: python.
  

Rust

rust := ZnClient new
	url: 'https://raw.githubusercontent.com/feenkcom/gtoolkit-vm/main/vm-runtime/src/event_loop.rs';
	get.
RustParser parse: rust
  

Clojure

clojure := ZnClient new 
	url: 'https://raw.githubusercontent.com/clojure/clojure/master/src/clj/clojure/main.clj';
	get.
ClojureParser parse: clojure.
  

Java

java := ZnClient new 
	url: 'https://raw.githubusercontent.com/spring-projects/spring-framework/b2bcb0f93ad04a6ddc729a487f9346defa6c39d6/spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java';
	get.
JavaParser parse: java
  

C#

csharp := ZnClient new 
	url: 'https://raw.githubusercontent.com/microsoft/calculator/66ad328d0018c360c1a0dc766f994c7fdb7d4a3f/src/CalculatorUITestFramework/MemoryPanel.cs';
	get.
CSharpParser parse: csharp