Package ru.ispras.fortress.esexpr
Class EsExpr
- java.lang.Object
-
- ru.ispras.fortress.esexpr.EsExpr
-
public final class EsExpr extends java.lang.Object
TheEsExpr
class represents Lisp-like S-expressions using tuple notation. EsExpr can be atom, i.e. string literal, or expression of form (a . b . c ...) which is equivalent for traditional dotted-pair sequence (a . (b . (c . ...))). This kind of expressions is called tuples. Tuples with special atom NIL at the last position are called lists. NIL is a predefined atom which is considered as an empty tuple or list.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static EsExpr
cons(EsExpr lhs, EsExpr rhs)
Create dotted pair for given S-expressions.static EsExpr
createAtom(java.lang.String literal)
Create atom for given string literal.static EsExpr
createList(java.util.List<EsExpr> items)
Create list of given S-expressions.static EsExpr
createTuple(java.util.List<EsExpr> items)
Create tuple of given S-expressions.boolean
equals(java.lang.Object obj)
java.util.List<EsExpr>
getItems()
Returns list of S-expressions contained in this expression.java.util.List<EsExpr>
getListItems()
Returns list of S-expressions contained in this list excluding lastNIL
.java.lang.String
getLiteral()
Returns string literal for given expression.boolean
isAtom()
Returnstrue
if this expression is atom.boolean
isList()
Returnstrue
if this expression is list.boolean
isNil()
Returnstrue
if this expression isNIL
atom.boolean
isTuple()
Returnstrue
if this expression is tuple.EsExpr
normalizePairs()
Returns deepest equivalent of this expression.EsExpr
normalizeTuples()
Returns shallowest equivalent of this expression.java.lang.String
toString()
-
-
-
Field Detail
-
NIL
public static final EsExpr NIL
-
-
Method Detail
-
isAtom
public boolean isAtom()
Returnstrue
if this expression is atom.- Returns:
true
if this expression is atom
-
isNil
public boolean isNil()
Returnstrue
if this expression isNIL
atom.- Returns:
true
if this expression isNIL
atom
-
isList
public boolean isList()
Returnstrue
if this expression is list. List expression isNIL
atom or tuple containingNIL
at last position.- Returns:
true
if this expression is list
-
isTuple
public boolean isTuple()
Returnstrue
if this expression is tuple.- Returns:
true
if this expression is tuple
-
getLiteral
public java.lang.String getLiteral()
Returns string literal for given expression. Atom string literal evaluates to itself, list and tuple literals are predefined strings denoting how expression has been created. If correct string representation required for S-expression, usetoString()
instead.- Returns:
- string literal for this expression
-
getItems
public java.util.List<EsExpr> getItems()
Returns list of S-expressions contained in this expression.- Returns:
- list of contained expressions, empty list for atoms
-
getListItems
public java.util.List<EsExpr> getListItems()
Returns list of S-expressions contained in this list excluding lastNIL
.- Returns:
- list of contained expressions excluding last
NIL
- Throws:
java.lang.UnsupportedOperationException
- if this expression is not list
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
normalizeTuples
public EsExpr normalizeTuples()
Returns shallowest equivalent of this expression. I.e. transforms recursively tuples like (a . b . (c . d)) into (a . b . c . d) form.- Returns:
- shallowest equivalent of this expression.
-
normalizePairs
public EsExpr normalizePairs()
Returns deepest equivalent of this expression. I.e. returns expression consisting only of dotted pairs and atoms.- Returns:
- deepest equivalent of this expression.
-
createAtom
public static EsExpr createAtom(java.lang.String literal)
Create atom for given string literal.- Parameters:
literal
- string literal for atom being created- Returns:
- atom for given string literal
- Throws:
java.lang.IllegalArgumentException
- ifliteral
isnull
-
createList
public static EsExpr createList(java.util.List<EsExpr> items)
Create list of given S-expressions. AddsNIL
atom at the end of list.- Parameters:
items
- list of S-expressions- Returns:
- list containing all expressions from
items
list - Throws:
java.lang.IllegalArgumentException
- ifitems
list isnull
-
createTuple
public static EsExpr createTuple(java.util.List<EsExpr> items)
Create tuple of given S-expressions.- Parameters:
items
- list of S-expressions- Returns:
- tuple containing all expressions from
items
list - Throws:
java.lang.IllegalArgumentException
- ifitems
list isnull
-
cons
public static EsExpr cons(EsExpr lhs, EsExpr rhs)
Create dotted pair for given S-expressions.- Parameters:
lhs
- left expression in dotted pairrhs
- right expression in dotted pair- Returns:
- tuple containing
lhs
andrhs
expressions - Throws:
java.lang.IllegalArgumentException
- if any of given expressions isnull
-
-