Skip to content
/ js2xml Public
forked from scrapinghub/js2xml

Convert Javascript code to an XML document

License

Notifications You must be signed in to change notification settings

dangra/js2xml

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js2xml

Build Status

Convert Javascript code to an XML document

Example:

>>> import js2xml
>>>
>>> jscode = """function factorial(n) {
...     if (n === 0) {
...         return 1;
...     }
...     return n * factorial(n - 1);
... }"""
>>> parsed = js2xml.parse(jscode)
>>>
>>> print js2xml.pretty_print(parsed)
<program>
  <funcdecl>
    <identifier>factorial</identifier>
    <parameters>
      <identifier>n</identifier>
    </parameters>
    <body>
      <if>
        <predicate>
          <binaryoperation>
            <left>
              <identifier>n</identifier>
            </left>
            <operator>===</operator>
            <right>
              <number>0</number>
            </right>
          </binaryoperation>
        </predicate>
        <then>
          <block>
            <return>
              <number>1</number>
            </return>
          </block>
        </then>
      </if>
      <return>
        <binaryoperation>
          <left>
            <identifier>n</identifier>
          </left>
          <operator>*</operator>
          <right>
            <functioncall>
              <identifier>
                <identifier>factorial</identifier>
              </identifier>
              <arguments>
                <binaryoperation>
                  <left>
                    <identifier>n</identifier>
                  </left>
                  <operator>-</operator>
                  <right>
                    <number>1</number>
                  </right>
                </binaryoperation>
              </arguments>
            </functioncall>
          </right>
        </binaryoperation>
      </return>
    </body>
  </funcdecl>
</program>

>>>

About

Convert Javascript code to an XML document

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published