Skip to content

Commit ddd5b33

Browse files
authored
Typeformat refactor (#14)
Change definitions to be alist instead of positional list for extra flexibility Refactor internals to operate through records instead of alists Implement type information for syntax Minor visual touch ups
1 parent 889a8ff commit ddd5b33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+8530
-10059
lines changed

README.adoc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Scheme is a functional language and thus it'd be useful to specify taken / retur
3434

3535
Procedures can have more than one entry, even from same library. This occurs, if the procedures is has optional parameters and therefore can be called in multiple ways; or if the result type can be determined more precisely under more specific input parameters.
3636

37-
Structural macros that don't resemble functions are rendered in *green*. If macro is complex, some parts of it are grouped, and the syntax of those groups shown below the syntax of whole macro. Macro literals are also rendered in green. To make parenthesis more obvious, auxiliary parenthesis coloring is used, however this coloring doesn't signify any information.
37+
Macros are rendered in *green*. If macro is complex, some parts of it are grouped, and the syntax of those groups shown below the syntax of whole macro. Macro literals are also rendered in green. To make parenthesis more obvious, auxiliary parenthesis coloring is used, however this coloring doesn't signify any information.
3838

3939
=== Tags
4040

@@ -44,7 +44,6 @@ Result items might have one or more of following tags
4444
* predicate - this procedure that takes any object and returns a boolean. Such procedure may be used as a type;
4545
* parameterized - the behavior of the procedure depends on a dynamic parameter (ie, uses procedure created with "make-parameter");
4646
* parameter - this procedure was created with "make-parameter" and may be used in parameterize form;
47-
* syntax - this is actually a macro, although presented as a procedure (the justification is that combining ad-hoc type annotation with syntax specification might be confusing. Simple macros were subjectively chosen to be shown as if they were procedures if they superficially appear and are called as such. This might be changed in the future);
4847
* deprecated - not recommended to be used, exists only for backwards compatibility with older SRFIs.
4948

5049
=== Filtering logic
@@ -358,7 +357,7 @@ as defined in srfi 180. Otherwise, results are returned as json.
358357

359358
`/rest/params` returns array of types, which were used as a parameter type, found in index as strings;
360359

361-
`/rest/procedures` returns found procedures with faceting meta data. The endpoint accepts following query parameters:
360+
`/rest/procedures` returns found items with faceting meta data. The endpoint accepts following query parameters:
362361

363362

364363
* `query` text search parameter.

pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
<groupId>org.apache.logging.log4j</groupId>
5252
<artifactId>log4j-slf4j-impl</artifactId>
5353
</exclusion>
54+
<exclusion>
55+
<groupId>org.apache.logging.log4j</groupId>
56+
<artifactId>log4j-core</artifactId>
57+
</exclusion>
5458
</exclusions>
5559
</dependency>
5660

@@ -64,9 +68,20 @@
6468
<groupId>org.apache.logging.log4j</groupId>
6569
<artifactId>log4j-slf4j-impl</artifactId>
6670
</exclusion>
71+
<exclusion>
72+
<groupId>org.apache.logging.log4j</groupId>
73+
<artifactId>log4j-core</artifactId>
74+
</exclusion>
6775
</exclusions>
6876
</dependency>
6977

78+
<!-- https://mvnrepository.com/artifact/org.slf4j/log4j-over-slf4j -->
79+
<dependency>
80+
<groupId>org.slf4j</groupId>
81+
<artifactId>log4j-over-slf4j</artifactId>
82+
<version>1.7.36</version>
83+
</dependency>
84+
7085
<dependency>
7186
<groupId>com.github.arvyy.kawa-web-collection</groupId>
7287
<artifactId>spark</artifactId>

solrhome/scmindex/conf/schema.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<field name="param_names" type="text_general" indexed="true" stored="true" multiValued="true"/>
2929
<field name="tags" type="strings" indexed="true" stored="true" />
3030
<field name="param_signatures" type="string" indexed="false" stored="true" />
31+
<field name="syntax_param_signatures" type="string" indexed="false" stored="true" />
3132
<field name="param_types" type="strings" indexed="true" stored="true" />
3233
<field name="param_subtypes" type="strings" indexed="true" stored="true" />
3334
<field name="param_subtypes_loose" type="strings" indexed="true" stored="true" />

src/main/resources/logback.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
<configuration>
2+
23
<property name="LOG_ROOT" value="logs" />
34
<property name="LOG_FILE_NAME" value="scmindex" />
45

6+
7+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
8+
<encoder>
9+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
10+
</encoder>
11+
</appender>
12+
513
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
614
<file>${LOG_ROOT}/${LOG_FILE_NAME}.log</file>
715
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
@@ -16,6 +24,8 @@
1624
</appender>
1725

1826
<root level="INFO">
27+
<appender-ref ref="STDOUT" />"
1928
<appender-ref ref="FILE" />
2029
</root>
30+
2131
</configuration>

src/main/scheme/scmindex/domain.scm

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
(define-library
2+
(scmindex domain)
3+
(import (scheme base)
4+
(scheme read)
5+
(scheme write))
6+
(export
7+
8+
make-search-result
9+
search-result?
10+
search-result-items
11+
search-result-total
12+
search-result-libs
13+
search-result-params
14+
search-result-tags
15+
search-result-returns
16+
17+
make-search-result-facet
18+
search-result-facet?
19+
search-result-facet-value
20+
search-result-facet-count
21+
22+
make-func
23+
func?
24+
func-lib
25+
func-name
26+
func-param-names
27+
func-signature
28+
func-param-signatures
29+
func-syntax-param-signatures
30+
func-tags
31+
func-param-types
32+
func-return-types
33+
func-supertypes
34+
35+
func->json
36+
json->func
37+
search-result->json
38+
)
39+
(begin
40+
41+
(define-record-type <scmindex-function>
42+
(make-func
43+
lib
44+
name
45+
param-names
46+
signature
47+
param-signatures
48+
syntax-param-signatures
49+
tags
50+
param-types
51+
return-types
52+
supertypes)
53+
54+
func?
55+
56+
(lib func-lib)
57+
(name func-name)
58+
(param-names func-param-names)
59+
(signature func-signature)
60+
(param-signatures func-param-signatures)
61+
(syntax-param-signatures func-syntax-param-signatures)
62+
(tags func-tags)
63+
(param-types func-param-types)
64+
(return-types func-return-types)
65+
(supertypes func-supertypes))
66+
67+
;;TODO move to util?
68+
(define (->string obj)
69+
(define port (open-output-string))
70+
(write obj port)
71+
(get-output-string port))
72+
73+
(define (read* str)
74+
(define port (open-input-string str))
75+
(read port))
76+
77+
(define (func->json func)
78+
`((lib . ,(->string (func-lib func)))
79+
(name . ,(symbol->string (func-name func)))
80+
(param_names . ,(list->vector (map ->string (func-param-names func))))
81+
(signature . ,(->string (func-signature func)))
82+
(param_signatures . ,(->string (func-param-signatures func)))
83+
(syntax_param_signatures . ,(->string (func-syntax-param-signatures func)))
84+
(tags . ,(list->vector (map ->string (func-tags func))))
85+
(param_types . ,(list->vector (map ->string (func-param-types func))))
86+
(return_types . ,(list->vector (map ->string (func-return-types func))))
87+
(super_types . ,(list->vector (map ->string (func-supertypes func))))))
88+
89+
(define (json->func json)
90+
(define (get field type default)
91+
(cond
92+
((assoc field json) =>
93+
(lambda (value)
94+
(case type
95+
((sexpr) (read* (cdr value)))
96+
((symbol) (string->symbol (cdr value)))
97+
((symbol-lst) (map string->symbol (vector->list (cdr value))))
98+
(else (cdr value)))))
99+
(else default)))
100+
(make-func
101+
(get 'lib 'sexpr #f)
102+
(get 'name 'symbol #f)
103+
(get 'param_names 'symbol-lst '())
104+
(get 'signature 'sexpr #f)
105+
(get 'param_signatures 'sexpr '())
106+
(get 'syntax_param_signatures 'sexpr '())
107+
(get 'tags 'symbol-lst '())
108+
(get 'param_types 'symbol-lst '())
109+
(get 'return_types 'symbol-lst '())
110+
(get 'supertypes 'symbol-lst '())))
111+
112+
(define-record-type <search-result>
113+
(make-search-result items total libs params tags returns)
114+
search-result?
115+
(items search-result-items)
116+
(total search-result-total)
117+
(libs search-result-libs)
118+
(params search-result-params)
119+
(tags search-result-tags)
120+
(returns search-result-returns))
121+
122+
(define-record-type <search-result-facet>
123+
(make-search-result-facet value count)
124+
search-result-facet?
125+
(value search-result-facet-value)
126+
(count search-result-facet-count))
127+
128+
(define (search-result->json sr)
129+
`((items . ,(list->vector (map func->json (search-result-items sr))))
130+
(total . ,(search-result-total sr))
131+
(libs . ,(list->vector (map search-result-facet->json (search-result-libs sr))))
132+
(params . ,(list->vector (map search-result-facet->json (search-result-params sr))))
133+
(returns . ,(list->vector (map search-result-facet->json (search-result-returns sr))))
134+
(tags . ,(list->vector (map search-result-facet->json (search-result-tags sr))))))
135+
136+
(define (search-result-facet->json f)
137+
`((value . ,(->string (search-result-facet-value f)))
138+
(count . ,(search-result-facet-count f))))
139+
140+
))

0 commit comments

Comments
 (0)