Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AST should generated something like sourcemap #15

Open
AkimotoAkari opened this issue Sep 3, 2017 · 12 comments
Open

AST should generated something like sourcemap #15

AkimotoAkari opened this issue Sep 3, 2017 · 12 comments
Assignees

Comments

@AkimotoAkari
Copy link
Collaborator

便于debug啊还有toJS什么的

@ice1000
Copy link
Contributor

ice1000 commented Sep 3, 2017

Cmc.Ast.Dump

@ice1000
Copy link
Contributor

ice1000 commented Sep 3, 2017

statement list:
  variable declaration [recurFunc]:
    type:
      lambda type [(i8)->i8]
    initialize expression:
      lambda:
        type:                                               
          lambda type [(i8)->i8]     
        parameters:                   
          variable declaration [a]:   
            type:                  
              primary type [i8]         
            initialize expression:  
              null expression           
        body:                             
          statement list:                     
            return statement:                                       
              function call expression:                    
                receiver:                  
                  variable expression [recur]:    
                    type:                   
                      lambda type [(i8)->i8]  
                parameters:                     
                  variable expression [a]:              
                    type:
                      primary type [i8] 
                type:
                  i8 
  variable declaration [gg]:    
    type:                               
      primary type [i8]             
    initialize expression:                   
      null expression                    
  assignment statemnt:        
    lhs:  
      variable expression [gg]:   
        type:                
          primary type [i8]   
    rhs:                      
      function call expression:      
        receiver:                     
          variable expression [recurFunc]:    
            type:            
              lambda type [(i8)->i8]     
        parameters:            
          literal expression [233]:   
            primary type [i8]         
        type:                  
          primary type [i8]  

  assignment statemnt:        
    lhs:  
      variable expression [gg]:   
        type:                
          primary type [i8]   
    rhs:                      
      function call expression:      
        receiver:                     
          variable expression [recurFunc]:    
            type:            
              lambda type [(i8)->i8]     
        parameters:            
          literal expression [233]:   
            primary type [i8]         
        type:                  
          primary type [i8]  

@ice1000
Copy link
Contributor

ice1000 commented Sep 3, 2017

debug 我都是直接上调试器的,用的很爽

@AkimotoAkari
Copy link
Collaborator Author

不是啊,字符位置什么的,参考sourcemap的实例

@ice1000
Copy link
Contributor

ice1000 commented Sep 10, 2017

字符位置啥意思?行号什么的都有好好保留的

@AkimotoAkari
Copy link
Collaborator Author

/- -/不仅仅行号啊,例如说
(stacktrace from Node.js REPL)
> global.resfjdorgjdiojdjrgnklsdjghuisdhdofer() TypeError: global.resfjdorgjdiojdjrgnklsdjghuisdhdofer is not a function at repl:1:8 /- HERE !-/ at ContextifyScript.Script.runInThisContext (vm.js:44:33)

@ice1000
Copy link
Contributor

ice1000 commented Sep 10, 2017

哦,我刚刚在吃火锅的时候在廖雪峰的博客里面看了下source map是啥。这个可能得做一会去了,我最近写代码的时间比较少。

可以考虑 @thautwarm

@thautwarm
Copy link
Contributor

thautwarm commented Sep 12, 2017

字符位置也需要确定?token那步可能直接丢弃一些字符的。
我个人觉得metainfo就足够了。toJS是指toJSON吗?if so, 并不困难,Parser那步就能完成,比如我这边这个

Stmt[Expr[BinOp[Factor[Atom[Literal[Name [' f ']]
             LP [' ( '] Expr[BinOp[Factor[Atom[Literal[Name [' a ']]
                     LP [' ( '] Expr[BinOp[Factor[Atom[Literal[Name [' b ']]
                            ]
                          ]
                        ]
                      ]
                     RP [' ) ']]
                  ]
                ]
              ]
             RP [' ) ']]
          ]
        ]
      ]
    ]

转JSON就是

{"stmt":{"expr":
            "<以下省略...字>"
           }
}

然后debug我也是直接用这个,加上parser步骤的一些过程信息,例如解析上述代码的部分过程信息:

Name <= Name [' a ']
RET

RET

Literal <= Literal[Name [' a ']]
  
RET

RET

(Closure | Literal) <= (Closure | Literal)[Literal[Name [' a ']]
    ]
  
(Closure | Literal) <= (Closure | Literal)[Literal[Name [' a ']]
    ]
  
Trailer WITH [(0, 'AWAIT'), (0, 'LINESPLIT'), (0, 'Expr'), (0, 'BinOp'), (0, 'Factor'), (0, '(Op)*'), (0, 'Atom'), (0, '(Closure | Literal)'), (0, 'Literal'), (0, 'Name'), (1, 'Trailer'), (1, 'LP'), (2, '(Expr)*'), (2, 'Expr'), (2, 'BinOp'), (2, 'Factor'), (2, '(Op)*'), (2, 'Atom'), (2, '(Closure | Literal)'), (2, 'Literal'), (2, 'Name'), (3, 'Trailer')]
Trailer WITH [(0, 'AWAIT'), (0, 'LINESPLIT'), (0, 'Expr'), (0, 'BinOp'), (0, 'Factor'), (0, '(Op)*'), (0, 'Atom'), (0, '(Closure | Literal)'), (0, 'Literal'), (0, 'Name'), (1, 'Trailer'), (1, 'LP'), (2, '(Expr)*'), (2, 'Expr'), (2, 'BinOp'), (2, 'Factor'), (2, '(Op)*'), (2, 'Atom'), (2, '(Closure | Literal)'), (2, 'Literal'), (2, 'Name'), (3, 'Trailer')]
LP <= LP [' ( ']

@AkimotoAkari

@ice1000
Copy link
Contributor

ice1000 commented Sep 12, 2017

但是你这个是Python血的 :trollface:

@thautwarm
Copy link
Contributor

@ice1000 马上就有C#版本了。只要一个语言有列表就好了(逃

@AkimotoAkari
Copy link
Collaborator Author

/- -/都是大大啊
是咋样丢弃的- -总之出现错误时对了就好

@ice1000
Copy link
Contributor

ice1000 commented Sep 12, 2017

在tokenize那一步就把字符位置存下来就是了,tan$π/2

@ice1000 ice1000 changed the title AST应包含可以生成类似于sourcemap的东西 AST should generated something like sourcemap Sep 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants