Changes how strings are serialized to JSON by grouping non-escaped characters in a single call to write. So if a string has no escape characters, it is written as is. This replaces the old behavior where there was a call to write for each character.
This PR addresses the same issue as #2367 and #2371 but it targets JSON string writing only. The best results are obtained when this PR is merged with #2371. On my machine, parsing and writing `magic.json` takes the following wall clock time depending on the branch:
* master: 14s
* #2367 (char cache): 6.2s
* #2371 (buffer): 4.0s
* this PR: 4.8s
* this PR + #2371: 3.6s
Pull-Request: #2372
end
add "# Lexer generated by nitcc for the grammar {name}\n"
- add "module {name}_lexer is no_warning \"missing-doc\"\n"
+ add "module {name}_lexer is generated, no_warning \"missing-doc\"\n"
add("import nitcc_runtime\n")
var p = parser
var gram = autom.grammar
add "# Parser generated by nitcc for the grammar {name}"
- add "module {name}_parser is no_warning(\"missing-doc\",\"old-init\")"
+ add "module {name}_parser is generated, no_warning(\"missing-doc\",\"old-init\")"
add "import nitcc_runtime"
add "class Parser_{name}"
f.write """# Generated by nitcc for the language {{{name}}}
# Standalone parser tester for the language {{{name}}}
-module {{{name}}}_test_parser
+module {{{name}}}_test_parser is generated
import nitcc_runtime
import {{{name}}}_lexer
import {{{name}}}_parser
# Lexer and its tokens.
# This file was generated by SableCC (http://www.sablecc.org/).
-module lexer is no_warning("missing-doc", "old-init")
+module lexer is generated, no_warning("missing-doc", "old-init")
intrude import parser_nodes
private import tables
# Parser.
# This file was generated by SableCC (http://www.sablecc.org/).
-module parser is no_warning("missing-doc", "old-init")
+module parser is generated, no_warning("missing-doc", "old-init")
intrude import parser_prod
import tables
# Raw AST node hierarchy.
# This file was generated by SableCC (http://www.sablecc.org/).
-package parser_abs
+package parser_abs is generated
import location
# ~~~
fun simplify_path: String
do
- var a = self.split_with("/")
+ var path_sep = if is_windows then "\\" else "/"
+ var a = self.split_with(path_sep)
var a2 = new Array[String]
for x in a do
if x == "." and not a2.is_empty then continue # skip `././`
class StringWriter
super Writer
- private var content = new Array[String]
- redef fun to_s do return content.plain_to_s
+ private var content = new Buffer
+ redef fun to_s do return content.to_s
redef fun is_writable do return not closed
redef fun write_bytes(b) do
- content.add(b.to_s)
+ content.append(b.to_s)
end
redef fun write(str)
do
assert not closed
- content.add(str.to_s)
+ content.append(str)
+ end
+
+ redef fun write_char(c)
+ do
+ assert not closed
+ content.add(c)
end
# Is the stream closed?
# Lexer generated by nitcc for the grammar json
-module json_lexer is no_warning "missing-doc"
+module json_lexer is generated, no_warning "missing-doc"
import nitcc_runtime
import json_parser
class Lexer_json
# Parser generated by nitcc for the grammar json
-module json_parser is no_warning("missing-doc","old-init")
+module json_parser is generated, no_warning("missing-doc","old-init")
import nitcc_runtime
class Parser_json
super Parser
LDLIBS := $(filter-out -lrt,$(LDLIBS))
endif
+# Special configuration for Windows under mingw64
+ifeq ($(uname_S),MINGW64_NT-10.0)
+ # Use the pcreposix regex library
+ LDLIBS += -lpcreposix
+
+ # Remove POSIX flag -lrt
+ LDLIBS := $(filter-out -lrt,$(LDLIBS))
+
+ # Silence warnings when storing Int, Char and Bool as pointer address
+ CFLAGS += -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast
+endif
+
"""
makefile.write("all: {outpath}\n")
self.toolcontext.info(command, 2)
var res
- if self.toolcontext.verbose_level >= 3 or is_windows then
+ if self.toolcontext.verbose_level >= 3 then
res = sys.system("{command} 2>&1")
+ else if is_windows then
+ res = sys.system("{command} 2>&1 >nul")
else
res = sys.system("{command} 2>&1 >/dev/null")
end
intern
extern
no_warning
+generated
auto_inspect
end
# Is the module a test suite?
mmodule.is_test_suite = not decl.get_annotations("test_suite").is_empty
+ # Is the module generated?
+ mmodule.is_generated = not decl.get_annotations("generated").is_empty
end
end
# Is `self` a unit test module used by `nitunit`?
var is_test_suite: Bool = false is writable
+ # Is `self` a module generated by a tool?
+ #
+ # This flag has no effect on the semantic.
+ # It is only intended on software engineering software to discriminate computer-generated modules from human-written ones.
+ var is_generated: Bool = false is writable
+
# Get the non-`is_fictive` module on which `self` is based on.
#
# On non-fictive module, this returns `self`.
end
var nit_module = new NitModule(module_name)
+nit_module.annotations.add """generated"""
nit_module.annotations.add """no_warning("parentheses")"""
nit_module.header = """
# This file is generated by nitrestful
if importations == null then importations = target_modules
var nit_module = new NitModule(module_name)
+ nit_module.annotations.add """generated"""
nit_module.annotations.add """no_warning("property-conflict")"""
nit_module.header = """
# This file is generated by nitserial
# Lexer and its tokens.
# This file was generated by SableCC (http://www.sablecc.org/).
-module lexer is no_warning("missing-doc")
+module lexer is generated, no_warning("missing-doc")
intrude import parser_nodes
intrude import lexer_work
# Parser.
# This file was generated by SableCC (http://www.sablecc.org/).
-module parser is no_warning("missing-doc", "unread-variable")
+module parser is generated, no_warning("missing-doc", "unread-variable")
intrude import parser_prod
intrude import parser_work
# Raw AST node hierarchy.
# This file was generated by SableCC (http://www.sablecc.org/).
-module parser_abs is no_warning("missing-doc")
+module parser_abs is generated, no_warning("missing-doc")
import location
# Production AST nodes full definition.
# This file was generated by SableCC (http://www.sablecc.org/).
-module parser_prod is no_warning("missing-doc")
+module parser_prod is generated, no_warning("missing-doc")
import lexer
intrude import parser_nodes
$ output 'parser_abs.nit'
# Raw AST node hierarchy.
# This file was generated by SableCC (http://www.sablecc.org/).
-module parser_abs is no_warning("missing-doc")
+module parser_abs is generated, no_warning("missing-doc")
import location
$ output 'lexer.nit'
# Lexer and its tokens.
# This file was generated by SableCC (http://www.sablecc.org/).
-module lexer is no_warning("missing-doc")
+module lexer is generated, no_warning("missing-doc")
$ if $usermodule
intrude import $usermodule
$ output 'parser_prod.nit'
# Production AST nodes full definition.
# This file was generated by SableCC (http://www.sablecc.org/).
-module parser_prod is no_warning("missing-doc")
+module parser_prod is generated, no_warning("missing-doc")
import lexer
$ if $usermodule
$ output 'parser.nit'
# Parser.
# This file was generated by SableCC (http://www.sablecc.org/).
-module parser is no_warning("missing-doc", "unread-variable")
+module parser is generated, no_warning("missing-doc", "unread-variable")
intrude import parser_prod
intrude import parser_work
#
# It uses, in order:
#
- # * the option `opt_no_color`
+ # * the option `opt_nit_dir`
# * the environment variable `NIT_DIR`
# * the runpath of the program from argv[0]
# * the runpath of the process from /proc
end
# search in the PATH
- var ps = "PATH".environ.split(":")
+ var path_sep = if is_windows then ";" else ":"
+ var ps = "PATH".environ.split(path_sep)
for p in ps do
res = p/".."
if check_nit_dir(res) then return res.simplify_path
# This file is generated by nitrestful
# Do not modify, instead refine the generated services.
module restful_annot_rest is
+ generated
no_warning("parentheses")
end
# This file is generated by nitserial
# Do not modify, but you can redef
module test_serialization_serial is
+ generated
no_warning("property-conflict")
end