Skip to content

Commit 520961d

Browse files
committed
move fmt stuff out of libjsonnet.h
1 parent 0e840bb commit 520961d

File tree

10 files changed

+112
-67
lines changed

10 files changed

+112
-67
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ ALL_HEADERS = \
8484
core/vm.h \
8585
core/std.jsonnet.h \
8686
include/libjsonnet.h \
87+
include/libjsonnet_fmt.h \
8788
include/libjsonnet++.h \
8889
third_party/md5/md5.h
8990

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,14 @@ bazel-bin/cmd/jsonnet
6363

6464
### Cmake
6565

66-
TODO: info about cmake
6766

67+
```
68+
cmake . -Bbuild
69+
```
70+
71+
```
72+
cmake --build build --target run_tests
73+
```
6874

6975
## Contributing
7076

cmd/jsonnet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ limitations under the License.
2929

3030
extern "C" {
3131
#include <libjsonnet.h>
32+
#include <libjsonnet_fmt.h>
3233
}
3334

3435
#ifdef _WIN32

core/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ cc_library(
3030
],
3131
deps = [
3232
"//include:libjsonnet",
33+
"//include:libjsonnet_fmt",
3334
"//stdlib:std",
3435
"//third_party/md5:libmd5",
3536
],

core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(LIBJSONNET_HEADERS
77
formatter.h
88
lexer.h
99
../include/libjsonnet.h
10+
../include/libjsonnet_fmt.h
1011
parser.h
1112
pass.h
1213
state.h

core/libjsonnet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ limitations under the License.
2626

2727
extern "C" {
2828
#include "libjsonnet.h"
29+
#include "libjsonnet_fmt.h"
2930
}
3031

3132
#include "desugarer.h"

include/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ cc_library(
66
includes = ["."],
77
)
88

9+
cc_library(
10+
name = "libjsonnet_fmt",
11+
hdrs = ["libjsonnet_fmt.h"],
12+
includes = ["."],
13+
)
14+
915
cc_library(
1016
name = "libjsonnet++",
1117
hdrs = ["libjsonnet++.h"],

include/libjsonnet.h

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -203,71 +203,6 @@ void jsonnet_tla_var(struct JsonnetVm *vm, const char *key, const char *val);
203203
*/
204204
void jsonnet_tla_code(struct JsonnetVm *vm, const char *key, const char *val);
205205

206-
/** Indentation level when reformatting (number of spaeces).
207-
*
208-
* \param n Number of spaces, must be > 0.
209-
*/
210-
void jsonnet_fmt_indent(struct JsonnetVm *vm, int n);
211-
212-
/** Indentation level when reformatting (number of spaeces).
213-
*
214-
* \param n Number of spaces, must be > 0.
215-
*/
216-
void jsonnet_fmt_max_blank_lines(struct JsonnetVm *vm, int n);
217-
218-
/** Preferred style for string literals ("" or '').
219-
*
220-
* \param c String style as a char ('d', 's', or 'l' (leave)).
221-
*/
222-
void jsonnet_fmt_string(struct JsonnetVm *vm, int c);
223-
224-
/** Preferred style for line comments (# or //).
225-
*
226-
* \param c Comment style as a char ('h', 's', or 'l' (leave)).
227-
*/
228-
void jsonnet_fmt_comment(struct JsonnetVm *vm, int c);
229-
230-
/** Whether to add an extra space on the inside of arrays.
231-
*/
232-
void jsonnet_fmt_pad_arrays(struct JsonnetVm *vm, int v);
233-
234-
/** Whether to add an extra space on the inside of objects.
235-
*/
236-
void jsonnet_fmt_pad_objects(struct JsonnetVm *vm, int v);
237-
238-
/** Use syntax sugar where possible with field names.
239-
*/
240-
void jsonnet_fmt_pretty_field_names(struct JsonnetVm *vm, int v);
241-
242-
/** Sort top-level imports in alphabetical order
243-
*/
244-
void jsonnet_fmt_sort_imports(struct JsonnetVm *vm, int v);
245-
246-
/** If set to 1, will reformat the Jsonnet input after desugaring. */
247-
void jsonnet_fmt_debug_desugaring(struct JsonnetVm *vm, int v);
248-
249-
/** Reformat a file containing Jsonnet code, return a Jsonnet string.
250-
*
251-
* The returned string should be cleaned up with jsonnet_realloc.
252-
*
253-
* \param filename Path to a file containing Jsonnet code.
254-
* \param error Return by reference whether or not there was an error.
255-
* \returns Either Jsonnet code or the error message.
256-
*/
257-
char *jsonnet_fmt_file(struct JsonnetVm *vm, const char *filename, int *error);
258-
259-
/** Reformat a string containing Jsonnet code, return a Jsonnet string.
260-
*
261-
* The returned string should be cleaned up with jsonnet_realloc.
262-
*
263-
* \param filename Path to a file (used in error messages).
264-
* \param snippet Jsonnet code to execute.
265-
* \param error Return by reference whether or not there was an error.
266-
* \returns Either Jsonnet code or the error message.
267-
*/
268-
char *jsonnet_fmt_snippet(struct JsonnetVm *vm, const char *filename, const char *snippet,
269-
int *error);
270-
271206
/** Set the number of lines of stack trace to display (0 for all of them). */
272207
void jsonnet_max_trace(struct JsonnetVm *vm, unsigned v);
273208

include/libjsonnet_fmt.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
Copyright 2018 Google Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#ifndef LIB_JSONNET_FMT_H
18+
#define LIB_JSONNET_FMT_H
19+
20+
#include <stddef.h>
21+
22+
/** \file This file is a library interface for formatting Jsonnet code.
23+
*/
24+
25+
/** Jsonnet virtual machine context. */
26+
struct JsonnetVm;
27+
28+
/** Indentation level when reformatting (number of spaeces).
29+
*
30+
* \param n Number of spaces, must be > 0.
31+
*/
32+
void jsonnet_fmt_indent(struct JsonnetVm *vm, int n);
33+
34+
/** Indentation level when reformatting (number of spaeces).
35+
*
36+
* \param n Number of spaces, must be > 0.
37+
*/
38+
void jsonnet_fmt_max_blank_lines(struct JsonnetVm *vm, int n);
39+
40+
/** Preferred style for string literals ("" or '').
41+
*
42+
* \param c String style as a char ('d', 's', or 'l' (leave)).
43+
*/
44+
void jsonnet_fmt_string(struct JsonnetVm *vm, int c);
45+
46+
/** Preferred style for line comments (# or //).
47+
*
48+
* \param c Comment style as a char ('h', 's', or 'l' (leave)).
49+
*/
50+
void jsonnet_fmt_comment(struct JsonnetVm *vm, int c);
51+
52+
/** Whether to add an extra space on the inside of arrays.
53+
*/
54+
void jsonnet_fmt_pad_arrays(struct JsonnetVm *vm, int v);
55+
56+
/** Whether to add an extra space on the inside of objects.
57+
*/
58+
void jsonnet_fmt_pad_objects(struct JsonnetVm *vm, int v);
59+
60+
/** Use syntax sugar where possible with field names.
61+
*/
62+
void jsonnet_fmt_pretty_field_names(struct JsonnetVm *vm, int v);
63+
64+
/** Sort top-level imports in alphabetical order
65+
*/
66+
void jsonnet_fmt_sort_imports(struct JsonnetVm *vm, int v);
67+
68+
/** If set to 1, will reformat the Jsonnet input after desugaring. */
69+
void jsonnet_fmt_debug_desugaring(struct JsonnetVm *vm, int v);
70+
71+
/** Reformat a file containing Jsonnet code, return a Jsonnet string.
72+
*
73+
* The returned string should be cleaned up with jsonnet_realloc.
74+
*
75+
* \param filename Path to a file containing Jsonnet code.
76+
* \param error Return by reference whether or not there was an error.
77+
* \returns Either Jsonnet code or the error message.
78+
*/
79+
char *jsonnet_fmt_file(struct JsonnetVm *vm, const char *filename, int *error);
80+
81+
/** Reformat a string containing Jsonnet code, return a Jsonnet string.
82+
*
83+
* The returned string should be cleaned up with jsonnet_realloc.
84+
*
85+
* \param filename Path to a file (used in error messages).
86+
* \param snippet Jsonnet code to execute.
87+
* \param error Return by reference whether or not there was an error.
88+
* \returns Either Jsonnet code or the error message.
89+
*/
90+
char *jsonnet_fmt_snippet(struct JsonnetVm *vm, const char *filename, const char *snippet,
91+
int *error);
92+
93+
#endif // LIB_JSONNET_FMT_H

tools/scripts/push_docs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
set -e
3131

32-
readonly JSONNET_REPO="[email protected]:google/jsonnet.git"
32+
readonly JSONNET_REPO="[email protected].:google/jsonnet.git"
3333

3434
function check {
3535
which $1 > /dev/null || (echo "$1 not installed. Please install $1."; exit 1)

0 commit comments

Comments
 (0)