removed latest version
This commit is contained in:
parent
a9f9f96065
commit
1a3a7cf757
2 changed files with 8 additions and 40 deletions
|
@ -1,7 +1,7 @@
|
||||||
name: sexpr
|
name: sexpr
|
||||||
description: |
|
description: |
|
||||||
A small s-expression parser based on fast-sexpr
|
A small s-expression parser based on fast-sexpr
|
||||||
version: 0.1.2
|
version: 0.1.1
|
||||||
|
|
||||||
authors:
|
authors:
|
||||||
- grimmigerFuchs <dominic.grimm@gmail.com>
|
- grimmigerFuchs <dominic.grimm@gmail.com>
|
||||||
|
|
46
src/sexpr.cr
46
src/sexpr.cr
|
@ -5,40 +5,8 @@ module Sexpr
|
||||||
|
|
||||||
VERSION = {{ `shards version`.stringify.chomp }}
|
VERSION = {{ `shards version`.stringify.chomp }}
|
||||||
|
|
||||||
module AST
|
alias Node = String | Body
|
||||||
abstract struct Node
|
alias Body = Array(String) | Array(Node)
|
||||||
property value
|
|
||||||
|
|
||||||
def initialize(@value)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
struct Body < Node
|
|
||||||
property value : Array(Node)
|
|
||||||
|
|
||||||
def initialize
|
|
||||||
@value = [] of Node
|
|
||||||
end
|
|
||||||
|
|
||||||
def <<(other : Node) : self
|
|
||||||
@value << other
|
|
||||||
|
|
||||||
self
|
|
||||||
end
|
|
||||||
|
|
||||||
def <<(other : self) : self
|
|
||||||
self << other.value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
struct SymNode < Node
|
|
||||||
property value : String
|
|
||||||
end
|
|
||||||
|
|
||||||
struct StringNode < Node
|
|
||||||
property value : String
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private class Wrapper
|
private class Wrapper
|
||||||
private property i = 0
|
private property i = 0
|
||||||
|
@ -76,8 +44,8 @@ module Sexpr
|
||||||
@i -= 1
|
@i -= 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse : AST::Body
|
def parse : Body
|
||||||
body = AST::Body.new
|
body = [] of Node
|
||||||
|
|
||||||
while char = get_char
|
while char = get_char
|
||||||
if char == ')'
|
if char == ')'
|
||||||
|
@ -85,10 +53,10 @@ module Sexpr
|
||||||
elsif char == '('
|
elsif char == '('
|
||||||
body << parse
|
body << parse
|
||||||
elsif char == '"'
|
elsif char == '"'
|
||||||
body << AST::StringNode.new(read_value(Terms::STRING))
|
body << read_value(Terms::STRING)
|
||||||
elsif !Terms::SPACE.matches?(char.to_s)
|
elsif !Terms::SPACE.matches?(char.to_s)
|
||||||
un_get_char
|
un_get_char
|
||||||
body.value << AST::SymNode.new(read_value(Terms::LIST))
|
body << read_value(Terms::LIST)
|
||||||
un_get_char
|
un_get_char
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -101,7 +69,7 @@ module Sexpr
|
||||||
source.gsub(/;;?.+/, nil)
|
source.gsub(/;;?.+/, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse(source : String) : AST::Body
|
def parse(source : String) : Body
|
||||||
Wrapper.new(remove_comments(source)).parse
|
Wrapper.new(remove_comments(source)).parse
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue