Skip to content

Commit

Permalink
Merge: json: remove the old nitcc parser
Browse files Browse the repository at this point in the history
Improve performances of the `json` package by removing the old nitcc parser to use only the custom string parser. It is faster at runtime and the nitcc parser classes were included with the JSON serialization services, slowing down compilation time even when not used.

The nitcc parser was still used only by a few clients, the only differences for the clients should be the error message, conflicts on the `Location` class, and improved performances.

It may be hard to see in the diff but the only differences in the `json` package are: the removal of the nitcc parser, move the string_parser in `static` (they are highly coupled), and make a few services private.

Note that the JSON nitcc grammar is still available in the nitcc project folder.

Warning: Until there's a service like `full_class_name`, deserializing classes with a name conflict is broken. I don't think that the 2-3 cases in the PR deserialize the generated JSON, so it should be OK for now.

Pull-Request: nitlang#2540
  • Loading branch information
privat committed Aug 31, 2017
2 parents 9fc571b + e014f10 commit afa60dd
Show file tree
Hide file tree
Showing 22 changed files with 378 additions and 1,889 deletions.
10 changes: 5 additions & 5 deletions contrib/neo_doxygen/src/doxml/entitydef.nit
Expand Up @@ -40,7 +40,7 @@ abstract class EntityDefListener
# The current entity.
protected fun entity: Entity is abstract

redef fun start_dox_element(local_name: String, atts: Attributes) do
redef fun start_dox_element(local_name, atts) do
if ["briefdescription", "detaileddescription", "inbodydescription"].has(local_name) then
doc.doc = entity.doc
doc.listen_until(dox_uri, local_name)
Expand All @@ -57,8 +57,8 @@ abstract class EntityDefListener
end

# Parse the attributes of a `location` element.
protected fun get_location(atts: Attributes): Location do
var location = new Location
protected fun get_location(atts: Attributes): neo_doxygen::Location do
var location = new neo_doxygen::Location

location.path = atts.value_ns("", "bodyfile") or else atts.value_ns("", "file")
# Doxygen may indicate `[generated]`.
Expand Down Expand Up @@ -100,7 +100,7 @@ abstract class ParamListener[T: Parameter]
# Create a new parameter.
protected fun create_parameter: T is abstract

redef fun start_dox_element(local_name: String, atts: Attributes) do
redef fun start_dox_element(local_name, atts) do
if "declname" == local_name then
text.listen_until(dox_uri, local_name)
else if "type" == local_name then
Expand All @@ -110,7 +110,7 @@ abstract class ParamListener[T: Parameter]
end
end

redef fun end_dox_element(local_name: String) do
redef fun end_dox_element(local_name) do
if "declname" == local_name then
parameter.name = text.to_s
else if "type" == local_name then
Expand Down
8 changes: 4 additions & 4 deletions contrib/neo_doxygen/src/model/class_compound.nit
Expand Up @@ -44,13 +44,13 @@ class ClassCompound
# Return the number of type parameters.
fun arity: Int do return class_type.arity

redef fun name=(name: String) do
redef fun name=(name) do
super
class_type.name = name
class_def.name = name
end

redef fun location=(location: nullable Location) do
redef fun location=(location) do
super
class_def.location = location
end
Expand All @@ -60,11 +60,11 @@ class ClassCompound
class_def["mdoc"] = doc
end

redef fun declare_super(id: String, full_name: String, prot: String, virt: String) do
redef fun declare_super(id, full_name, prot, virt) do
class_def.declare_super(id, full_name, prot, virt)
end

redef fun declare_member(member: Member) do
redef fun declare_member(member) do
class_def.declare_member(member)
end

Expand Down
12 changes: 6 additions & 6 deletions contrib/neo_doxygen/src/model/graph.nit
Expand Up @@ -167,13 +167,13 @@ abstract class Entity
fun ns_separator: String do return "::"

# Set the location of the entity in the source code.
fun location=(location: nullable Location) do
fun location=(location: nullable neo_doxygen::Location) do
self["location"] = location
end

# Get the location of the entity in the source code.
fun location: nullable Location do
return self["location"].as(nullable Location)
fun location: nullable neo_doxygen::Location do
return self["location"].as(nullable neo_doxygen::Location)
end

# Put the entity in the graph.
Expand Down Expand Up @@ -202,12 +202,12 @@ abstract class CodeBlock
super Entity

init do
self["location"] = new Location
self["location"] = new neo_doxygen::Location
end

redef fun location=(location: nullable Location) do
redef fun location=(location) do
if location == null then
super(new Location)
super(new neo_doxygen::Location)
else
super
end
Expand Down
1 change: 0 additions & 1 deletion contrib/neo_doxygen/src/model/location.nit
Expand Up @@ -15,7 +15,6 @@
# This module is used to model locations in source files.
module location

import json::static
import json

# A location inside a source file.
Expand Down
6 changes: 3 additions & 3 deletions contrib/neo_doxygen/src/model/module_compound.nit
Expand Up @@ -46,12 +46,12 @@ class FileCompound
super
end

redef fun location=(location: nullable Location) do
redef fun location=(location) do
super
for m in inner_namespaces do m.location = location
end

redef fun name=(name: String) do
redef fun name=(name) do
# Example: `MyClass.java`
super
var match = name.search_last(".")
Expand All @@ -65,7 +65,7 @@ class FileCompound
for m in inner_namespaces do m.update_name
end

redef fun declare_namespace(id: String, full_name: String) do
redef fun declare_namespace(id, full_name) do
var m: Module

assert not full_name.is_empty or id.is_empty else
Expand Down
10 changes: 5 additions & 5 deletions contrib/neo_doxygen/src/tests/neo_doxygen_file_compound.nit
Expand Up @@ -26,11 +26,11 @@ var c_ns = new Namespace(graph)
var d_ns = new Namespace(graph)
var buffer = new Buffer
var root_ns = graph.by_id[""].as(Namespace)
var location: Location
var location

file.name = "Bar.java"
file.model_id = "_Bar_8java"
location = new Location
location = new neo_doxygen::Location
location.path = "a/b/Bar.java"
file.location = location
file.declare_class("classa_b_bar", "a::b::Bar", "package")
Expand All @@ -41,7 +41,7 @@ file.put_in_graph

file_2.name = "Bar.java"
file_2.model_id = "_Bar_8java_2"
location = new Location
location = new neo_doxygen::Location
location.path = "Bar.java"
file_2.location = location
file_2.declare_namespace("namespacec", "c")
Expand All @@ -50,7 +50,7 @@ file_2.put_in_graph

bar_class.model_id = "classa_b_bar"
bar_class.name = "Bar"
location = new Location
location = new neo_doxygen::Location
location.path = "a/b/Bar.class"
location.line_start = 5
location.column_start = 1
Expand All @@ -61,7 +61,7 @@ bar_class.put_in_graph

baz_class.model_id = "classbaz"
baz_class.name = "Baz"
location = new Location
location = new neo_doxygen::Location
location.path = "Baz.jar"
baz_class.location = location
baz_class.put_in_graph
Expand Down
2 changes: 0 additions & 2 deletions lib/json/.gitattributes

This file was deleted.

7 changes: 0 additions & 7 deletions lib/json/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions lib/json/Makefile

This file was deleted.

21 changes: 6 additions & 15 deletions lib/json/error.nit
Expand Up @@ -8,25 +8,16 @@
# You are allowed to redistribute it and sell it, alone or is a part of
# another product.

# Errors related to JSON parsing.
module json::error
# Intro `JsonParseError` which is exposed by all JSON reading APIs
module error

import nitcc_runtime
import parser_base

# Ill-formed JSON.
# JSON format error at parsing
class JsonParseError
super Error
serialize

# The location of the error in the original text.
var position: nullable Position

redef fun to_s do
var p = position
if p isa Position then
return "Error Parsing JSON: [{p}] {super}"
else
return super
end
end
# Location of the error in source
var location: nullable Location = null
end

0 comments on commit afa60dd

Please sign in to comment.