Skip to content

Latest commit

 

History

History
489 lines (386 loc) · 6.45 KB

ast.md

File metadata and controls

489 lines (386 loc) · 6.45 KB

module

contains a module of code, corresponding to a single file/snippet

Module
  code: [Function / Class / Expression]
42
type: module
code:
  - type: int
    value: 42

literals

int

contains an int

Int
  value: int
42
type: int
value: 42

float

contains a float

Float
  value: float
4.2
type: float
value: 4.2

string

contains a string

String
  value: str
'eyes'
type: string
value: eyes

none

contains none value

None
None
type: none

list

contains a list literal

List
  elements: [Expression]
[42, None]
type: list
elements:
  - type: int
    value: 42
  - type: none

dict

contains a dictionary literal, the keys are supposed to be numbers or strings or booleans so most target languages can support them natively.

Dict
  pairs: [[Hashable, Expression]]
{v: v}
type: dict
pairs:
  -
    - type: local
      name: v
    - type: local
      name: v

idents

local

usually a local variable or an argument to the current function

Local
  name: str
e #python
e #ruby
type: local
name: e

typename

usually the name of a class or type

Typename
  name: str
Animal
type: typename
name: Animal

instance_variable

an instance variable accessed in a method of its class

InstanceVariable
  name: str
self.e #python
@e #ruby
type: instance_variable
name: e

attr

an attribute of an object

Attr
  object: Expression
  attr: str
type: attr
object:
  type: int
  value: 2
attr: size

assignments

assignment

local_assignments

an assignment to a local variable (the usual kind of assignment).

Assignment
  target: Local
  value: Expression
e = 'eyes' 
x, y = 2, 4

multi assignments is also supposed to be represented as series of assignment nodes

type: assignment
target:
  type: local
  name: e
  pseudo_type: String
value:
  type: string
  value: eyes
  pseudo_type: String

type: assignment
target:
  type: local
  name: x
  pseudo_type: Int
value:
  type: int
  value: 2
  pseudo_type: Int

type: assignment
target:
  type: local
  name: y
  pseudo_type: Int
value:
  type: int
  value: 2
  pseudo_type: Int

instance_assignment

an assignment of ivar

InstanceAssignment
  name: str
  value: Expression
self.e = e # python
@e = e # ruby
type: instance_assignment
name: e
value:
  type: local
  name: e

attr_assignment

an assignment to attr

AttrAssignment
  attribute: Attribute
  value: Expression
a.i = None # python
$a->i = NULL; # php
type: attr_assignment
attribute:
  type: Attribute
  object: 
    type: local
    name: a
  name: i
value:
  type: none

calls

call

a function call

Call
  function: Expression
  args: [Expression]
analyze(e, 2)
type: call
function:
  type: local
  name: analyze
args:
  - type: local
    name: e
  - type: int
    value: 2

method_call

a call to an object's method

MethodCall
  receiver: Expression
  message: str
  args: [Expression]
h.analyze()
type: method_call
receiver:
  type: local
  name: h
message: analyze
args: []

standard_call

a call to a standard pseudo function pseudo standard functions are divided in namespaces, they in a combination with standard methods (below) represent the pseudo standard library the standard library corresponds to the only pseudo-translateable native functions and methods(builtin in the input/target language or its standard library) if you want support for other functions/methods, please follow the extend pseudo guide

the namespaces currently are global(no namespace/top namespace) math, io, system you can read more in standard library reference

StandardCall
  namespace: None / str
  function: str
  args: [Expression]
print(2)
type: standard_call
namespace: io
function: display
args:
  - type: int
    value: 2

standard_method_call

a pseudo standard library method call the standard library corresponds to the only pseudo-translateable native functions and methods(builtin in the input/target language or its standard library) if you want support for other functions/methods, please follow the extend pseudo guide

you can read more in standard library reference

python
StandardMethodCall
  receiver: Expression
  message: str
  args: [Expression]
f()[1:] # f returns a list of int
type: standard_method_call
receiver:
  type: call
    function:
      type: local
      name: f
    args: []
    pseudo_type: List[Int]
message: slice_from
args:
  - type: int
    value: 1
pseudo_type: List[Int]