# Empty program

==>

Program

# Identifier

foo

==>

Program(Identifier)

# Decimal integer

42

==>

Program(Integer)

# Binary integer

0b1010

==>

Program(Integer)

# Octal integer

0o77

==>

Program(Integer)

# Hex integer

0xff

==>

Program(Integer)

# Float with decimal

1.5

==>

Program(Float)

# Float with exponent

1e3

==>

Program(Float)

# Float with decimal and exponent

1.5e3

==>

Program(Float)

# Float starting with dot

.5

==>

Program(Float)

# Float starting with dot after an identifier

x.5

==>

Program(Application(Identifier, Float))

# Float with p exponent

1p32

==>

Program(Float)

# Standard string

"hello"

==>

Program(String)

# String with escape

"hello\nworld"

==>

Program(String)

# String spanning lines

"hello
world"

==>

Program(String)

# Unterminated string runs to the end

x = "abc
y = 1

==>

Program(BinaryExpr(Definition, AssignmentOp, String))

# Unterminated string ending in a backslash

x = "abc\

==>

Program(BinaryExpr(Definition, AssignmentOp, String))

# Line comment

-- this is a comment
42

==>

Program(LineComment, Integer)

# Block comment

-* this is a comment *-
42

==>

Program(BlockComment, Integer)

# Shebang on the first line

#!/usr/bin/env M2
x

==>

Program(ShebangComment, Identifier)

# Triple-slash string

///hello world///

==>

Program(TripleSlashString)

# Multiple statements via newline

42
"hello"

==>

Program(Integer, String)

# Multiple statements via semicolon

42; "hello"

==>

Program(Integer, String)

# Quote an identifier

symbol x

==>

Program(QuoteExpr(symbol, Identifier))

# Quote with global

global x

==>

Program(QuoteExpr(global, Identifier))

# Quote with local

local x

==>

Program(QuoteExpr(local, Identifier))

# Quote with threadLocal

threadLocal x

==>

Program(QuoteExpr(threadLocal, Identifier))

# Quote with threadVariable

threadVariable x

==>

Program(QuoteExpr(threadVariable, Identifier))

# Quote an operator

symbol *

==>

Program(QuoteExpr(symbol, QuotedOperator))

# Quote an operator with global

global <<

==>

Program(QuoteExpr(global, QuotedOperator))

# Quote an operator with local

local ==

==>

Program(QuoteExpr(local, QuotedOperator))

# Quote the adjacency operator

symbol SPACE

==>

Program(QuoteExpr(symbol, QuotedOperator))

# Quote the statement separator

symbol ;

==>

Program(QuoteExpr(symbol, QuotedOperator))

# Quoted operator method key

(symbol ==, A, B)

==>

Program(
  ParenExpr(
    Sequence(QuoteExpr(symbol, QuotedOperator), Identifier, Identifier)))

# Quoted operator in installMethod

installMethod(symbol _, A, B, f)

==>

Program(
  Application(
    BuiltinFunction,
    ParenExpr(
      Sequence(
        QuoteExpr(symbol, QuotedOperator),
        Identifier,
        Identifier,
        Identifier))))

# Quoted operator takes the longest match

symbol ..<

==>

Program(QuoteExpr(symbol, QuotedOperator))

# Quote the sum-of-twists operator

symbol (*)

==>

Program(QuoteExpr(symbol, QuotedOperator))

# Integer range without spaces

1..22

==>

Program(BinaryExpr(Integer, Operator, Integer))

# Half-open integer range without spaces

1..<22

==>

Program(BinaryExpr(Integer, Operator, Integer))

# Trailing-dot float is still a float

1.

==>

Program(Float)

# Float range

1.0..2.0

==>

Program(BinaryExpr(Float, Operator, Float))

# Hex literal followed by a range

0xff..3

==>

Program(BinaryExpr(Integer, Operator, Integer))

# Range binds looser than application

f 1..2

==>

Program(BinaryExpr(Application(Identifier, Integer), Operator, Integer))

# Subscripted variable range

ZZ/101[x_1..x_5]

==>

Program(
  Application(
    BinaryExpr(BuiltinType, ArithmeticOp, Integer),
    Array(
      BinaryExpr(
        BinaryExpr(Identifier, AccessOp, Integer),
        Operator,
        BinaryExpr(Identifier, AccessOp, Integer)))))

# Quote a word-shaped operator

symbol and

==>

Program(QuoteExpr(symbol, QuotedOperator))

# Quote a loop keyword

symbol for

==>

Program(QuoteExpr(symbol, QuotedOperator))

# Quote the not operator

symbol not

==>

Program(QuoteExpr(symbol, QuotedOperator))

# Quote a control keyword

symbol if

==>

Program(QuoteExpr(symbol, QuotedOperator))

# Quote the symbol keyword itself

symbol symbol

==>

Program(QuoteExpr(symbol, QuotedOperator))

# Quoted keyword needs a word boundary

symbol andrew

==>

Program(QuoteExpr(symbol, Identifier))
