WolframResearch / codeparser

Parse Wolfram Language source code as abstract syntax trees (ASTs) or concrete syntax trees (CSTs)
MIT License
122 stars 14 forks source link

What are the allowed values for the "SourceConvention" option? #10

Closed arnoudbuzing closed 4 years ago

arnoudbuzing commented 4 years ago

I have tried "ColumnLine" as a RHS, but that does not seem to work:

In[3]:= Options[CodeParse, SourceConvention]

Out[3]= {"SourceConvention" -> "LineColumn"}

Are there option values here other that "LineColumn" ?

bostick commented 4 years ago

The allowed values are "LineColumn" or "SourceCharacterIndex". I do not see there being more.

"LineColumn" returns Source metadata in {{line1, col1}, {line2, col2}} format:

In[6]:= CodeConcreteParse["a+b", "SourceConvention" -> "LineColumn"]

Out[6]= ContainerNode[String, {InfixNode[
   Plus, {LeafNode[Symbol, "a", <|Source -> {{1, 1}, {1, 2}}|>], 
    LeafNode[Token`Plus, "+", <|Source -> {{1, 2}, {1, 3}}|>], 
    LeafNode[Symbol, 
     "b", <|Source -> {{1, 3}, {1, 4}}|>]}, <|Source -> {{1, 1}, {1, 
       4}}|>]}, <||>]

"SourceCharacterIndex" returns Source metadata in StringTake-spec format:

In[7]:= CodeConcreteParse["a+b", 
 "SourceConvention" -> "SourceCharacterIndex"]

Out[7]= ContainerNode[String, {InfixNode[
   Plus, {LeafNode[Symbol, "a", <|Source -> {1, 1}|>], 
    LeafNode[Token`Plus, "+", <|Source -> {2, 2}|>], 
    LeafNode[Symbol, 
     "b", <|Source -> {3, 3}|>]}, <|Source -> {1, 3}|>]}, <||>]