Skip to content

rameshvarun/galaxy-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StarCraft 2 Galaxy Parser

Node.js CI npm

Usage

const parse = require("sc2-galaxy-parser");
const ast = parse(`void Main(int argc, string[100] argv) {
  ConsoleLog("Galaxy Test...");
}`);
console.log(ast);

Notes

Extended Backus–Naur Form Grammar

<program> ::= {<toplevel-declaration>}
<toplevel-declaration> ::= <struct-declaration>
  | <global-declaration>
  | <type-def>
  | <function-declaration>
  | <function-prototype>
  | <native-declaration>

<global-declaration> ::= ["static"] ["const"] <variable-declaration> ";"
<variable-declaration> ::= <type-specifier> <identifier> []

<struct-declaration> ::= "struct" "{" {<struct-field>} "}"
<struct-field> ::= <type-specifier> <identifier>  ";"

<function-prototype> ::= ["static"] <type-specifier> <identifier> "(" ")" ";"

<function-declaration> ::= ["static"] <type-specifier> <identifier> "(" ")" "{" <function-body> "}"

<type-specifier> ::= <identifier>
  | <type-specifier> "[" <integer-literal> "]"
  | <identifier> "<" <identifier> ">"

<type-def> ::= "typedef" <type-specifier> <identifier> ";"
<include-path> ::= "import" <string-literal> [";"]

<function-body> ::= {<variable-declaration> ";"}

<statement> ::= <expression>
  | <identifier> <assign-op> <expression> // TODO: Determine if assignment is a statement or expression.
  | "return" <expression>
  | "continue"
  | "break"

<expression> ::= <expression> <bin-op> <expression> // Binary operator.
  | <unary-op> <expression> // Unary operator.
  | <identifier> "[" "]" // Array indexing.
  | <identifier> "(" [<expresion_list>] ")" // Function call.
  | <identifier> // Scope lookup.
  | <string-literal> // String literal.

<expresion_list> ::= {<expresion> ","} <expresion>

<bin-op> ::= "+" | "-" | "*" | "/" | "%" | "&"
  | "|" | "^" | "<<" | ">>" | "&&" | "||" | "=="
  | "!=" | "<" | "<=" | ">=" | ">"

<unary-op> ::= "+" | "-" | "~" | "!"

<assign-op> ::= "=" | "+=" | "-=" | "*=" | "/="
  | "%=" | "&=" | "|=" | "^=" | "<<=" | ">>="

Links

About

A parser for StarCraft 2's Galaxy scripting language, written in JavaScript using parser combinators.

Topics

Resources

License

Stars

Watchers

Forks