diff options
author | Arne H Juul <arnej@yahooinc.com> | 2022-02-22 11:41:28 +0000 |
---|---|---|
committer | Arne H Juul <arnej@yahooinc.com> | 2022-02-22 15:01:15 +0000 |
commit | bc5be7a8f3b9d707cc035c6f30bdc245b8b8e31f (patch) | |
tree | faef4629c5c14bf5a4849b29356e6aed52365de3 /config-model | |
parent | 6d0dc2a9001fea925fe11ae5a4351bb980525fc1 (diff) |
convert some top-level parsing
Diffstat (limited to 'config-model')
3 files changed, 112 insertions, 32 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedDocument.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedDocument.java new file mode 100644 index 00000000000..29dd36c1d25 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedDocument.java @@ -0,0 +1,26 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.parser; + +import java.util.ArrayList; +import java.util.List; + +public class ParsedDocument { + private final String name; + private final List<String> inherited = new ArrayList<>(); + + public ParsedDocument(String name) { + this.name = name; + } + + String getName() { return name; } + void inherit(String other) { inherited.add(other); } + + /* + private final List<ParsedField> fields = new ArrayList<>(); + List<ParsedField> getFields() { return fields; } + void addField(ParsedField field) { fields.add(field); } + void addStruct(ParsedStruct type) {} + void addAnnotation(ParsedAnnotation type) {} + */ +} + diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java new file mode 100644 index 00000000000..032194f248d --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ParsedSchema.java @@ -0,0 +1,36 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.parser; + +import java.util.ArrayList; +import java.util.List; + +public class ParsedSchema { + private final String name; + private final List<String> inherited = new ArrayList<>(); + + public ParsedSchema(String name) { + this.name = name; + } + + String getName() { return name; } + void inherit(String other) { inherited.add(other); } + void addDocument(ParsedDocument document) {} + + /* + private final List<ParsedField> fields = new ArrayList<>(); + List<ParsedField> getFields() { return fields; } + void addField(ParsedField field) { fields.add(field); } + void addOnnxModel(Object model) {} + void addImportedField(String asFieldName, String refFieldName, String foregnFieldName) {} + void addAnnotation(ParsedAnnotation annotation) {} + void addIndex(ParsedIndex index) {} + void enableRawAsBase64(boolean value) {} + void addStruct(ParsedStruct struct) {} + void setStemming(String value) {} + void addRankingConstant(Object constant) {} + void addFieldSet(ParsedFieldSet fieldSet) {} + void addDocumentSummary(ParsedDocumentSummary docsum) {} + void addRankProfile(ParsedRankProfile profile) {} + */ +} + diff --git a/config-model/src/main/javacc/IntermediateParser.jj b/config-model/src/main/javacc/IntermediateParser.jj index f4608361571..c6d04e283a8 100644 --- a/config-model/src/main/javacc/IntermediateParser.jj +++ b/config-model/src/main/javacc/IntermediateParser.jj @@ -397,10 +397,9 @@ SPECIAL_TOKEN : * * @return the schema object */ -Schema schema(DocumentTypeManager docMan) : +ParsedSchema schema() : { - this.docMan = docMan; - Schema schema; + ParsedSchema schema; } { (<NL>)* (schema = rootSchema() | schema = rootDocument()) @@ -413,17 +412,17 @@ Schema schema(DocumentTypeManager docMan) : * * @return the schema definition object. */ -Schema rootSchema() : +ParsedSchema rootSchema() : { String name; String inherited = null; - Schema schema; + ParsedSchema schema; } { ( ( <SCHEMA> | <SEARCH> ) name = identifier() (<INHERITS> inherited = identifier() )? { - schema = new Schema(name, applicationPackage, Optional.ofNullable(inherited), fileRegistry, deployLogger, properties); - rankProfileRegistry.add(new DefaultRankProfile(schema, rankProfileRegistry, schema.rankingConstants())); - rankProfileRegistry.add(new UnrankedRankProfile(schema, rankProfileRegistry, schema.rankingConstants()));} + schema = new ParsedSchema(name); + if (inherited != null) schema.inherit(inherited); + } lbrace() (rootSchemaItem(schema) (<NL>)*)* <RBRACE> (<NL>)* <EOF>) { return schema; } } @@ -434,9 +433,10 @@ Schema rootSchema() : * * @param schema the schema object to modify. */ -void rootSchemaItem(Schema schema) : { } +void rootSchemaItem(ParsedSchema schema) : { } { ( document(schema) +/* | rawAsBase64(schema) | documentSummary(schema) | field(null, schema) @@ -449,7 +449,9 @@ void rootSchemaItem(Schema schema) : { } | annotationOutside(schema) | fieldSet(schema) | importField(schema) - | onnxModel(schema) ) + | onnxModel(schema) +*/ + ) } /** @@ -457,9 +459,9 @@ void rootSchemaItem(Schema schema) : { } * * @return the schema definition object. */ -Schema rootDocument() : +ParsedSchema rootDocument() : { - Schema schema = new DocumentOnlySchema(applicationPackage, fileRegistry, deployLogger, properties); + ParsedSchema schema = new ParsedSchema("<unnamed>"); } { ( (rootDocumentItem(schema) (<NL>)*)*<EOF> ) @@ -471,7 +473,7 @@ Schema rootDocument() : * * @param schema the schema object to modify. */ -void rootDocumentItem(Schema schema) : { } +void rootDocumentItem(ParsedSchema schema) : { } { ( namedDocument(schema) ) } @@ -492,15 +494,15 @@ void useDocument(Schema schema) : { } * * @param schema the schema object to add content to. */ -void document(Schema schema) : +void document(ParsedSchema schema) : { String name = schema.getName(); - SDDocumentType document; + ParsedDocument document; } { - ( <DOCUMENT> (name = identifier())? (<NL>)* { document = new SDDocumentType(name, schema); } + ( <DOCUMENT> (name = identifier())? (<NL>)* { document = new ParsedDocument(name); } [ inheritsDocument(document) (<NL>)* ] - <LBRACE> (<NL>)* (documentBody(document, schema) (<NL>)*)* <RBRACE> ) + <LBRACE> (<NL>)* (documentBody(document) (<NL>)*)* <RBRACE> ) { schema.addDocument(document); } @@ -511,15 +513,15 @@ void document(Schema schema) : * * @param schema the schema object to add content to */ -void namedDocument(Schema schema) : +void namedDocument(ParsedSchema schema) : { String name; - SDDocumentType document; + ParsedDocument document; } { - ( <DOCUMENT> name = identifier() (<NL>)* { document = new SDDocumentType(name, schema); } + ( <DOCUMENT> name = identifier() (<NL>)* { document = new ParsedDocument(name); } [ inheritsDocument(document) (<NL>)* ] - <LBRACE> (<NL>)* (documentBody(document, schema) (<NL>)*)* <RBRACE> ) + <LBRACE> (<NL>)* (documentBody(document) (<NL>)*)* <RBRACE> ) { schema.addDocument(document); } @@ -529,18 +531,18 @@ void namedDocument(Schema schema) : * Consumes a document body block * * @param document the document type to modify. - * @param schema the schema object to add content to */ -void documentBody(SDDocumentType document, Schema schema) : +void documentBody(ParsedDocument document) : { } { - ( annotation(schema, document) - | compression(document) - | headercfg(document) - | bodycfg(document) + ( compression(null) + | headercfg(null) + | bodycfg(null) + /* | annotation(schema, document) | structInside(document, schema) - | field(document, schema) ) + | field(document, schema) */ + ) } void rawAsBase64(Schema schema) : @@ -605,11 +607,11 @@ void compressionItem() : } /** - * Consumes a document inheritance statement. + * Consumes a struct inheritance statement. * - * @param document The document type to modify. + * @param document The struct type to modify. */ -void inheritsDocument(SDDocumentType document) : +void inheritsStruct(SDDocumentType document) : { String name; } @@ -618,6 +620,22 @@ void inheritsDocument(SDDocumentType document) : ( <COMMA> name = identifier() { document.inherit(new DataTypeName(name)); } )* } + +/** + * Consumes a document inheritance statement. + * + * @param document The document type to modify. + */ +void inheritsDocument(ParsedDocument document) : +{ + String name; +} +{ + <INHERITS> name = identifier() { document.inherit(name); } + ( <COMMA> name = identifier() { document.inherit(name); } )* +} + + /** * Consumes a field block from within a document element. * @@ -807,7 +825,7 @@ SDDocumentType structDefinition(Schema schema, SDDocumentType repo) : } { ( <STRUCT> name = identifier() (<NL>)* { struct = new SDDocumentType(name, schema); } - [ inheritsDocument(struct) (<NL>)* ] + [ inheritsStruct(struct) (<NL>)* ] lbrace() (structFieldDefinition(struct) (<NL>)*)* <RBRACE> ) { try { |