-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Create a PoC for syntax extension that injects line number #308
Labels
Comments
The Lexer already have metadata information like number of columns or line number. There is only a need to expose this to the user. This will also allow adding line number to stack trace. |
jcubic
added a commit
that referenced
this issue
Mar 25, 2024
This a working example: (set-special! "#:num" 'line-num lips.specials.SYMBOL)
(define (line-num)
(let ((token (lips.__parser__.__lexer__.peek true)))
(+ token.line 1)))
(print #:num) ;; ==> 7
(print #:num) ;; ==> 8 |
With this, there will be a way to add full string interpolation #321 This is example dumb raw string syntax: (set-special! "#raw" 'frob lips.specials.SYMBOL)
(define (frob)
(let ((lexer lips.__parser__.__lexer__))
(if (char=? (lexer.peek_char) #\`)
(begin
(lexer.skip_char)
(let loop ((result (vector)) (char (lexer.peek_char)))
(lexer.skip_char)
(if (char=? char #\`)
(result.join "")
(loop (result.concat char) (lexer.peek_char))))))))
(print #raw`foo \ bar`) |
jcubic
added a commit
that referenced
this issue
Mar 27, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be cool if that would be possible. It will only work when the source code is the text file and not the binary.
The Lexer would need to be modified to count new lines.
Think about the possibility of adding a function that will return line number.
The text was updated successfully, but these errors were encountered: