| 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 |