pax_global_header 0000666 0000000 0000000 00000000064 14256061462 0014520 g ustar 00root root 0000000 0000000 52 comment=83d06d779c05e259bf1e020aca9b850d3c6f010b
Serpent-serpent-1.41/ 0000775 0000000 0000000 00000000000 14256061462 0014543 5 ustar 00root root 0000000 0000000 Serpent-serpent-1.41/.github/ 0000775 0000000 0000000 00000000000 14256061462 0016103 5 ustar 00root root 0000000 0000000 Serpent-serpent-1.41/.github/workflows/ 0000775 0000000 0000000 00000000000 14256061462 0020140 5 ustar 00root root 0000000 0000000 Serpent-serpent-1.41/.github/workflows/main-ci.yml 0000664 0000000 0000000 00000003667 14256061462 0022214 0 ustar 00root root 0000000 0000000 # This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Run CI Tests
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
# allow manual trigger
workflow_dispatch:
jobs:
test-python:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- name: Checkout source
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytz attrs pytest
- name: build and install
run:
pip install .
- name: Test with pytest
run: |
pytest -v tests
test-dotnet:
name: build, pack, test .Net
runs-on: ubuntu-latest
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
steps:
- uses: actions/checkout@v2
- name: Install .Net
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
- name: Restore, Build, test, and pack
uses: Elskom/build-dotnet@main
with:
SOLUTION_FILE_PATH: 'dotnet/Serpent'
TEST: true
PACK: true
PUSH: false
test-java:
name: build, test Java
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
- name: Build with Maven
run: mvn --batch-mode --update-snapshots -f java/pom.xml verify
Serpent-serpent-1.41/.gitignore 0000664 0000000 0000000 00000001514 14256061462 0016534 0 ustar 00root root 0000000 0000000 *.py[cod]
# C extensions
*.so
# Packages
*.egg[s]
*.egg-info
dist
build
eggs
parts
bin
target
var
sdist
develop-eggs
.installed.cfg
lib
lib64
.idea/
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
[Bb]in/
[Oo]bj/
build
target
# mstest test results
TestResults
TEST-*.xml
TestResult.xml
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.log
*.vspscc
*.vssscc
.builds
*.nupkg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# java
*.class
Serpent-serpent-1.41/.pylintrc 0000664 0000000 0000000 00000000200 14256061462 0016400 0 ustar 00root root 0000000 0000000 [MESSAGES CONTROL]
disable=missing-docstring
[BASIC]
include-naming-hint=yes
max-line-length=120
good-names=i,j,k,x,y,z,t,ex,_
Serpent-serpent-1.41/LICENSE 0000664 0000000 0000000 00000002054 14256061462 0015551 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) by Irmen de Jong
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Serpent-serpent-1.41/MANIFEST.in 0000664 0000000 0000000 00000000465 14256061462 0016306 0 ustar 00root root 0000000 0000000 include LICENSE
include README.md
include tox.ini
recursive-include tests *
global-exclude */.svn/*
global-exclude */.idea/*
global-exclude *.class
global-exclude *.pyc
global-exclude *.pyo
global-exclude *.coverage
global-exclude .git
global-exclude .gitignore
global-exclude .tox
global-exclude __pycache__
Serpent-serpent-1.41/Makefile 0000664 0000000 0000000 00000002073 14256061462 0016205 0 ustar 00root root 0000000 0000000 .PHONY: all dist install upload clean test check lint
all:
@echo "targets include dist, upload, install, clean, test, lint"
dist:
python setup.py sdist bdist_wheel
@echo "Look in the dist/ directory"
upload: dist
@echo "Uploading to Pypi using twine...."
twine upload dist/*
install:
python setup.py install
test:
pytest -v tests
lint:
pycodestyle
clean:
@echo "Cleaning up..."
find . -name __pycache__ -print0 | xargs -0 rm -rf
find . -name \*_log -print0 | xargs -0 rm -f
find . -name \*.log -print0 | xargs -0 rm -f
find . -name \*.pyo -print0 | xargs -0 rm -f
find . -name \*.pyc -print0 | xargs -0 rm -f
find . -name \*.class -print0 | xargs -0 rm -f
find . -name \*.DS_Store -print0 | xargs -0 rm -f
find . -name TEST-*.xml -print0 | xargs -0 rm -f
find . -name TestResult.xml -print0 | xargs -0 rm -f
rm -f MANIFEST
rm -rf build
rm -rf dotnet/Serpent/obj dotnet/Serpent.Test/obj
rm -rf dotnet/Serpent/bin dotnet/Serpent.Test/bin
find . -name '.#*' -print0 | xargs -0 rm -f
find . -name '#*#' -print0 | xargs -0 rm -f
@echo "clean!"
Serpent-serpent-1.41/README.md 0000664 0000000 0000000 00000007242 14256061462 0016027 0 ustar 00root root 0000000 0000000 Serpent serialization library (Python/.NET/Java)
================================================
[](https://pypi.python.org/pypi/Serpent/)
[](http://search.maven.org/#search|ga|1|g%3A%22net.razorvine%22%20AND%20a%3A%22serpent%22)
[](https://www.nuget.org/packages/Razorvine.Serpent/)
[](https://anaconda.org/conda-forge/serpent)
Serpent provides ast.literal_eval() compatible object tree serialization.
It serializes an object tree into bytes (utf-8 encoded string) that can be decoded and then
passed as-is to ast.literal_eval() to rebuild it as the original object tree.
As such it is safe to send serpent data to other machines over the network for instance
(because only 'safe' literals are encoded).
More info on Pypi: https://pypi.python.org/pypi/serpent
Source code is on Github: https://github.com/irmen/Serpent
Copyright by Irmen de Jong (irmen@razorvine.net)
This software is released under the MIT software license.
This license, including disclaimer, is available in the 'LICENSE' file.
PYTHON
------
Compatible with Python 3.7+ (use a serpent version before 1.30 for Python 2.7 support)
It can be found on Pypi as 'serpent': https://pypi.python.org/pypi/serpent
Example usage can be found in ./tests/example.py
C#/.NET
-------
Package is available on www.nuget.org as 'Razorvine.Serpent'.
Full source code can be found in ./dotnet/ directory.
Example usage can be found in ./dotnet/Serpent.Test/Example.cs
The project is a dotnet core project targeting NetStandard 2.0.
JAVA
----
Maven-artefact is available on maven central, groupid 'net.razorvine' artifactid 'serpent'.
Full source code can be found in ./java/ directory.
Example usage can be found in ./java/test/SerpentExample.java
Versions before 1.23 require Java 7 or Java 8 (JDK 1.7 or 1.8) to compile and run.
Version 1.23 and later require Java 8 (JDK 1.8) at a minimum to compile and run.
SOME MORE DETAILS
-----------------
Serpent handles several special Python types to make life easier:
- bytes, bytearrays, memoryview --> string, base-64 (or bytes-literal if selected)
(you'll have to manually un-base64. Can use serpent.tobytes function for that.)
- uuid.UUID, datetime.{datetime, date, time, timespan} --> appropriate string/number
- decimal.Decimal --> string (to not lose precision)
- array.array typecode 'u' --> string
- array.array other typecode --> list
- Exception --> dict with some fields of the exception (message, args)
- collections module types --> mostly equivalent primitive types or dict
- enums --> the value of the enum
- namedtuple --> treated as just a tuple
- attr dataclasses and python 3.7 native dataclasses: treated as just a class, so will become a dict
- all other types --> dict with the ``__getstate__`` or ``vars()`` of the object, and a ``__class__`` element with the name of the class
Notes:
The serializer is not thread-safe. Make sure you're not making changes
to the object tree that is being serialized, and don't use the same
serializer in different threads.
Because the serialized format is just valid Python source code, it can
contain comments. Serpent does not add comments by itself apart from the
single header line.
Floats +inf and -inf are handled via a trick, Float 'nan' cannot be handled
and is represented by the special value: ``{'__class__':'float','value':'nan'}``
We chose not to encode it as just the string 'NaN' because that could cause
memory issues when used in multiplications.
Serpent-serpent-1.41/dotnet/ 0000775 0000000 0000000 00000000000 14256061462 0016040 5 ustar 00root root 0000000 0000000 Serpent-serpent-1.41/dotnet/Serpent/ 0000775 0000000 0000000 00000000000 14256061462 0017460 5 ustar 00root root 0000000 0000000 Serpent-serpent-1.41/dotnet/Serpent/Razorvine.Serpent/ 0000775 0000000 0000000 00000000000 14256061462 0023056 5 ustar 00root root 0000000 0000000 Serpent-serpent-1.41/dotnet/Serpent/Razorvine.Serpent/Ast.cs 0000664 0000000 0000000 00000022602 14256061462 0024136 0 ustar 00root root 0000000 0000000 using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
using System.Linq;
// ReSharper disable MemberCanBeProtected.Global
// ReSharper disable UnusedParameter.Global
namespace Razorvine.Serpent
{
///
/// Abstract syntax tree for the literal expression. This is what the parser returns.
///
public class Ast
{
public INode Root;
public override string ToString()
{
return "# serpent utf-8 .net\n" + Root.ToString();
}
///
/// Get the actual parsed data as C# object(s).
///
public object GetData()
{
var visitor = new ObjectifyVisitor();
Root.Accept(visitor);
return visitor.GetObject();
}
///
/// Get the actual parsed data as C# object(s).
///
/// functin to convert dicts to actual instances for a class,
/// instead of leaving them as dictionaries. Requires the __class__ key to be present
/// in the dict node. If it returns null, the normal processing is done.
public object GetData(Func dictToInstance)
{
var visitor = new ObjectifyVisitor(dictToInstance);
Root.Accept(visitor);
return visitor.GetObject();
}
public interface INodeVisitor
{
void Visit(ComplexNumberNode complex);
void Visit(DictNode dict);
void Visit(ListNode list);
void Visit(NoneNode none);
void Visit(IntegerNode value);
void Visit(LongNode value);
void Visit(DoubleNode value);
void Visit(BooleanNode value);
void Visit(StringNode value);
void Visit(BytesNode value);
void Visit(DecimalNode value);
void Visit(SetNode setnode);
void Visit(TupleNode tuple);
}
///
/// Visitor pattern: visit all nodes in the Ast with the given visitor.
///
public void Accept(INodeVisitor visitor)
{
Root.Accept(visitor);
}
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public interface INode
{
string ToString();
bool Equals(object obj);
void Accept(INodeVisitor visitor);
}
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public abstract class PrimitiveNode : INode, IComparable>
{
public readonly T Value;
protected PrimitiveNode(T value)
{
Value=value;
}
public override int GetHashCode()
{
return Value!=null? Value.GetHashCode() : 0;
}
public override bool Equals(object obj)
{
var node = obj as PrimitiveNode;
return node != null && Equals(Value, node.Value);
}
public bool Equals(PrimitiveNode other)
{
return Equals(Value, other.Value);
}
public int CompareTo(PrimitiveNode other)
{
var cv = Value as IComparable;
var otherCv = other.Value as IComparable;
if (cv != null && otherCv != null)
return cv.CompareTo(otherCv);
return 0;
}
public override string ToString()
{
var s = Value as string;
if(s != null)
{
var sb=new StringBuilder();
sb.Append("'");
foreach(var c in s)
{
switch(c)
{
case '\\':
sb.Append("\\\\");
break;
case '\'':
sb.Append("\\'");
break;
case '\a':
sb.Append("\\a");
break;
case '\b':
sb.Append("\\b");
break;
case '\f':
sb.Append("\\f");
break;
case '\n':
sb.Append("\\n");
break;
case '\r':
sb.Append("\\r");
break;
case '\t':
sb.Append("\\t");
break;
case '\v':
sb.Append("\\v");
break;
default:
sb.Append(c);
break;
}
}
sb.Append("'");
return sb.ToString();
}
if (!(Value is double) && !(Value is float))
return Value.ToString();
var d = Convert.ToString(Value, CultureInfo.InvariantCulture);
if (d == null)
throw new ParseException("ast value is null");
if(d.IndexOfAny(new [] {'.', 'e', 'E'})<=0)
d+=".0";
return d;
}
public abstract void Accept(INodeVisitor visitor);
}
public class IntegerNode: PrimitiveNode
{
public IntegerNode(int value) : base(value)
{
}
public override void Accept(INodeVisitor visitor)
{
visitor.Visit(this);
}
}
public class LongNode: PrimitiveNode
{
public LongNode(long value) : base(value)
{
}
public override void Accept(INodeVisitor visitor)
{
visitor.Visit(this);
}
}
public class DoubleNode: PrimitiveNode
{
public DoubleNode(double value) : base(value)
{
}
public override void Accept(INodeVisitor visitor)
{
visitor.Visit(this);
}
}
public class StringNode: PrimitiveNode
{
public StringNode(string value) : base(value)
{
}
public override void Accept(INodeVisitor visitor)
{
visitor.Visit(this);
}
}
public class BytesNode: PrimitiveNode
{
public BytesNode(byte[] value) : base(value)
{
}
public override void Accept(INodeVisitor visitor)
{
visitor.Visit(this);
}
}
public class DecimalNode: PrimitiveNode
{
public DecimalNode(decimal value) : base(value)
{
}
public override void Accept(INodeVisitor visitor)
{
visitor.Visit(this);
}
}
public class BooleanNode: PrimitiveNode
{
public BooleanNode(bool value) : base(value)
{
}
public override void Accept(INodeVisitor visitor)
{
visitor.Visit(this);
}
}
public struct ComplexNumberNode: INode
{
public double Real;
public double Imaginary;
public void Accept(INodeVisitor visitor)
{
visitor.Visit(this);
}
public override string ToString()
{
string strReal = Real.ToString(CultureInfo.InvariantCulture);
string strImag = Imaginary.ToString(CultureInfo.InvariantCulture);
return string.Format(Imaginary>=0 ? "({0}+{1}j)" : "({0}{1}j)", strReal, strImag);
}
}
public class NoneNode: INode
{
public static readonly NoneNode Instance = new NoneNode();
private NoneNode()
{
}
public override string ToString()
{
return "None";
}
public void Accept(INodeVisitor visitor)
{
visitor.Visit(this);
}
}
public abstract class SequenceNode: INode
{
public List Elements = new List();
public virtual char OpenChar => '?';
public virtual char CloseChar => '?';
public override int GetHashCode()
{
int hashCode = 0;
unchecked {
// ReSharper disable once NonReadonlyMemberInGetHashCode
foreach(var elt in Elements)
hashCode += 1000000007 * elt.GetHashCode();
}
return hashCode;
}
public override bool Equals(object obj)
{
var other = obj as SequenceNode;
return other != null && Elements.SequenceEqual(other.Elements);
}
public override string ToString()
{
var sb=new StringBuilder();
sb.Append(OpenChar);
if(Elements != null)
{
foreach(var elt in Elements)
{
sb.Append(elt.ToString());
sb.Append(',');
}
}
// ReSharper disable once PossibleNullReferenceException
if(Elements.Count>0)
sb.Remove(sb.Length-1, 1); // remove last comma
sb.Append(CloseChar);
return sb.ToString();
}
public abstract void Accept(INodeVisitor visitor);
}
public class TupleNode : SequenceNode
{
public override string ToString()
{
var sb=new StringBuilder();
sb.Append('(');
if(Elements != null)
{
foreach(var elt in Elements)
{
sb.Append(elt.ToString());
sb.Append(",");
}
if(Elements.Count>1)
sb.Remove(sb.Length-1, 1);
}
sb.Append(')');
return sb.ToString();
}
public override void Accept(INodeVisitor visitor)
{
visitor.Visit(this);
}
}
public class ListNode : SequenceNode
{
public override char OpenChar => '[';
public override char CloseChar => ']';
public override void Accept(INodeVisitor visitor)
{
visitor.Visit(this);
}
}
public abstract class UnorderedSequenceNode : SequenceNode
{
public override bool Equals(object obj)
{
if(!(obj is UnorderedSequenceNode))
return false;
var set1 = ElementsAsSet();
var set2 = ((UnorderedSequenceNode) obj).ElementsAsSet();
return set1.SetEquals(set2);
}
public override int GetHashCode()
{
return ElementsAsSet().GetHashCode();
}
public HashSet ElementsAsSet()
{
var set = new HashSet();
foreach(var kv in Elements)
set.Add(kv);
return set;
}
}
public class SetNode : UnorderedSequenceNode
{
public override char OpenChar => '{';
public override char CloseChar => '}';
public override void Accept(INodeVisitor visitor)
{
visitor.Visit(this);
}
}
public class DictNode : UnorderedSequenceNode
{
public override char OpenChar => '{';
public override char CloseChar => '}';
public override void Accept(INodeVisitor visitor)
{
visitor.Visit(this);
}
}
public struct KeyValueNode : INode
{
public INode Key;
public INode Value;
public KeyValueNode(INode key, INode value)
{
Key = key;
Value = value;
}
public override string ToString()
{
return $"{Key}:{Value}";
}
public void Accept(INodeVisitor visitor)
{
throw new NotSupportedException("don't visit a keyvaluenode");
}
}
}
}
Serpent-serpent-1.41/dotnet/Serpent/Razorvine.Serpent/ComplexNumber.cs 0000664 0000000 0000000 00000004240 14256061462 0026165 0 ustar 00root root 0000000 0000000 using System;
using System.Text;
// ReSharper disable UnusedMember.Global
namespace Razorvine.Serpent
{
///
/// A Complex Number class.
///
public class ComplexNumber {
public double Real {get; }
public double Imaginary {get; }
public ComplexNumber(double r, double i) {
Real=r;
Imaginary=i;
}
public override string ToString()
{
StringBuilder sb=new StringBuilder();
sb.Append(Real);
if(Imaginary>0)
sb.Append('+');
return sb.Append(Imaginary).Append('i').ToString();
}
public double Magnitude() {
return Math.Sqrt(Real * Real + Imaginary * Imaginary);
}
public static ComplexNumber operator +(ComplexNumber c1, ComplexNumber c2) {
return new ComplexNumber(c1.Real + c2.Real, c1.Imaginary + c2.Imaginary);
}
public static ComplexNumber operator -(ComplexNumber c1, ComplexNumber c2) {
return new ComplexNumber(c1.Real - c2.Real, c1.Imaginary - c2.Imaginary);
}
public static ComplexNumber operator *(ComplexNumber c1, ComplexNumber c2) {
return new ComplexNumber(c1.Real * c2.Real - c1.Imaginary * c2.Imaginary, c1.Real * c2.Imaginary + c1.Imaginary * c2.Real);
}
public static ComplexNumber operator /(ComplexNumber c1, ComplexNumber c2) {
return new ComplexNumber((c1.Real * c2.Real + c1.Imaginary * c2.Imaginary) / (c2.Real * c2.Real + c2.Imaginary * c2.Imaginary), (c1.Imaginary * c2.Real - c1.Real * c2.Imaginary)
/ (c2.Real * c2.Real + c2.Imaginary * c2.Imaginary));
}
#region Equals and GetHashCode implementation
public override bool Equals(object obj)
{
if(!(obj is ComplexNumber))
return false;
ComplexNumber other = (ComplexNumber) obj;
// ReSharper disable CompareOfFloatsByEqualityOperator
return Real==other.Real && Imaginary==other.Imaginary;
}
public override int GetHashCode()
{
return Real.GetHashCode() ^ Imaginary.GetHashCode();
}
public static bool operator ==(ComplexNumber lhs, ComplexNumber rhs)
{
if (ReferenceEquals(lhs, rhs))
return true;
if (ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null))
return false;
return lhs.Equals(rhs);
}
public static bool operator !=(ComplexNumber lhs, ComplexNumber rhs)
{
return !(lhs == rhs);
}
#endregion
}
} Serpent-serpent-1.41/dotnet/Serpent/Razorvine.Serpent/DebugVisitor.cs 0000664 0000000 0000000 00000005337 14256061462 0026023 0 ustar 00root root 0000000 0000000 using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace Razorvine.Serpent
{
///
/// Ast nodevisitor that prints out the Ast as a string for debugging purposes
///
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public class DebugVisitor: Ast.INodeVisitor
{
private readonly StringBuilder _result = new StringBuilder();
private int _indent;
///
/// Get the debug string representation result.
///
public override string ToString()
{
return _result.ToString();
}
protected void Indent()
{
for(int i=0; i<_indent; ++i)
_result.Append(" ");
}
public void Visit(Ast.ComplexNumberNode complex)
{
_result.AppendFormat("complexnumber ({0}r,{1}i)", complex.Real, complex.Imaginary);
}
public void Visit(Ast.DictNode dict)
{
_result.AppendLine("(dict");
_indent++;
foreach(var node in dict.Elements)
{
var kv = (Ast.KeyValueNode) node;
Indent();
kv.Key.Accept(this);
_result.Append(" = ");
kv.Value.Accept(this);
_result.AppendLine(",");
}
_indent--;
Indent();
_result.Append(")");
}
public void Visit(Ast.ListNode list)
{
_result.AppendLine("(list");
_indent++;
foreach(Ast.INode node in list.Elements)
{
Indent();
node.Accept(this);
_result.AppendLine(",");
}
_indent--;
Indent();
_result.Append(")");
}
public void Visit(Ast.NoneNode none)
{
_result.Append("None");
}
public void Visit(Ast.IntegerNode value)
{
_result.AppendFormat("int {0}", value.Value);
}
public void Visit(Ast.LongNode value)
{
_result.AppendFormat("long {0}", value.Value);
}
public void Visit(Ast.DoubleNode value)
{
_result.AppendFormat("double {0}", value.Value);
}
public void Visit(Ast.BooleanNode value)
{
_result.AppendFormat("bool {0}", value.Value);
}
public void Visit(Ast.StringNode value)
{
_result.AppendFormat("string '{0}'", value.Value);
}
public void Visit(Ast.BytesNode value)
{
_result.AppendFormat("bytes {0}", value.Value);
}
public void Visit(Ast.DecimalNode value)
{
_result.AppendFormat("decimal {0}", value.Value);
}
public void Visit(Ast.SetNode setnode)
{
_result.AppendLine("(set");
_indent++;
foreach(Ast.INode node in setnode.Elements)
{
Indent();
node.Accept(this);
_result.AppendLine(",");
}
_indent--;
Indent();
_result.Append(")");
}
public void Visit(Ast.TupleNode tuple)
{
_result.AppendLine("(tuple");
_indent++;
foreach(Ast.INode node in tuple.Elements)
{
Indent();
node.Accept(this);
_result.AppendLine(",");
}
_indent--;
Indent();
_result.Append(")");
}
}
}
Serpent-serpent-1.41/dotnet/Serpent/Razorvine.Serpent/ObjectifyVisitor.cs 0000664 0000000 0000000 00000006300 14256061462 0026702 0 ustar 00root root 0000000 0000000 using System;
using System.Collections.Generic;
using System.Collections;
namespace Razorvine.Serpent
{
///
/// Ast nodevisitor that turns the AST into actual .NET objects (array, int, IDictionary, string, etc...)
///
public class ObjectifyVisitor: Ast.INodeVisitor
{
private readonly Stack