Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
try out calva's clojure lexer in a repl
$ git clone https://github.com/BetterThanTomorrow/calva
$ cd calva
$ npm install -D ts-node
$ cd src/cursor-doc
$ npx ts-node
> import { Scanner } from './clojure-lexer'
{}
> let s = new Scanner(32768)
undefined
> s.processLine("(def a 1)")
[
{ type: 'open', offset: 0, raw: '(', state: { inString: false } },
{ type: 'id', offset: 1, raw: 'def', state: { inString: false } },
{ type: 'ws', offset: 4, raw: ' ', state: { inString: false } },
{ type: 'id', offset: 5, raw: 'a', state: { inString: false } },
{ type: 'ws', offset: 6, raw: ' ', state: { inString: false } },
{ type: 'lit', offset: 7, raw: '1', state: { inString: false } },
{ type: 'close', offset: 8, raw: ')', state: { inString: false } },
{ type: 'eol', raw: '\n', offset: 9, state: { inString: false } }
]
> s.processLine("#_ :a")
[
{ type: 'ignore', offset: 0, raw: '#_', state: { inString: false } },
{ type: 'ws', offset: 2, raw: ' ', state: { inString: false } },
{ type: 'kw', offset: 3, raw: ':a', state: { inString: false } },
{ type: 'eol', raw: '\n', offset: 5, state: { inString: false } }
]
> s.processLine("2r01")
[
{ type: 'lit', offset: 0, raw: '2r01', state: { inString: false } },
{ type: 'eol', raw: '\n', offset: 4, state: { inString: false } }
]
> s.processLine("100.0")
[
{ type: 'lit', offset: 0, raw: '100.0', state: { inString: false } },
{ type: 'eol', raw: '\n', offset: 5, state: { inString: false } }
]
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.