Skip to content

Commit

Permalink
refactor(xml-parser): rename xmi-parser to xml-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
DerYeger committed Oct 30, 2024
1 parent a3f196f commit 7827c6d
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .changeset/thin-berries-camp.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'@cm2ml/plugin-adapter': major
'@cm2ml/rest': major
'@cm2ml/rest-adapter': major
'@cm2ml/xmi-parser': major
'@cm2ml/xml-parser': major
'kernighan-lin': major
'@cm2ml/uml': major
'prefixspan': major
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
- [@cm2ml/plugin-adapter](./packages/framework/plugin-adapter)
- [@cm2ml/rest](./packages/framework/rest)
- [@cm2ml/rest-adapter](./packages/framework/rest-adapter)
- [@cm2ml/xmi-parser](./packages/framework/xmi-parser)
- [@cm2ml/xml-parser](./packages/framework/xml-parser)

## Languages

Expand Down
2 changes: 1 addition & 1 deletion packages/framework/builtin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@cm2ml/tf-encoder": "workspace:*",
"@cm2ml/tree-encoder": "workspace:*",
"@cm2ml/uml": "workspace:*",
"@cm2ml/xmi-parser": "workspace:*",
"@cm2ml/xml-parser": "workspace:*",
"@yeger/streams": "1.2.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/builtin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export * from '@cm2ml/pattern-miner'
export * from '@cm2ml/tf-encoder'
export * from '@cm2ml/tree-encoder'
export * from '@cm2ml/uml'
export * from '@cm2ml/xmi-parser'
export * from '@cm2ml/xml-parser'

export type Parser = Plugin<string, GraphModel, any>

Expand Down
2 changes: 1 addition & 1 deletion packages/framework/cm2ml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@cm2ml/rest": "workspace:*",
"@cm2ml/rest-adapter": "workspace:*",
"@cm2ml/utils": "workspace:*",
"@cm2ml/xmi-parser": "workspace:*"
"@cm2ml/xml-parser": "workspace:*"
},
"devDependencies": {
"@cm2ml/tsconfig": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/metamodel/src/metamodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class MetamodelElement<
if (this.metamodel.isValidTag(tag)) {
return this.#assignableTags.has(tag)
}
// During the transformation, we replace the xmi tags with the UML types, so this additional check is necessary
// Some parsers might also treat the tag as a type
if (this.metamodel.isValidType(tag)) {
return this.#assignableTypes.has(tag)
}
Expand Down
1 change: 0 additions & 1 deletion packages/framework/xmi-parser/README.md

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions packages/framework/xml-parser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @cm2ml/xml-parser
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@cm2ml/xmi-parser",
"name": "@cm2ml/xml-parser",
"type": "module",
"version": "0.0.0",
"author": {
Expand All @@ -10,7 +10,7 @@
"repository": {
"type": "git",
"url": "git+https://github.com/borkdominik/CM2ML.git",
"directory": "packages/framework/xmi-parser"
"directory": "packages/framework/xml-parser"
},
"bugs": {
"url": "https://github.com/borkdominik/CM2ML/issues"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { parseDocument } from 'htmlparser2'

export type TextNodeHandler = (node: GraphNode, text: string) => void

export function createXmiParser(
export function createXMLParser(
metamodel: Metamodel<string, string, string>,
textNodeHandler: TextNodeHandler,
) {
return definePlugin({
name: 'xmi',
name: 'xml',
parameters: {
debug: {
type: 'boolean',
Expand All @@ -33,12 +33,12 @@ export function createXmiParser(
}

function parse(
xmi: string,
xml: string,
metamodel: Metamodel<string, string, string>,
settings: Settings,
textNodeHandler: TextNodeHandler,
): GraphModel {
const document = parseDocument(xmi, {
const document = parseDocument(xml, {
xmlMode: true,
})
return mapDocument(document, metamodel, settings, textNodeHandler)
Expand Down Expand Up @@ -103,18 +103,18 @@ function initNodeFromElement(
}

function mapAttribute([name, value]: [string, string]): Attribute {
const xmiValue = mapValue(value)
const xmlValue = mapValue(value)
const parsedName = parseNamespace(name)
if (typeof parsedName === 'object') {
return {
name,
simpleName: parsedName.name,
namespace: parsedName.namespace,
type: 'unknown',
value: xmiValue,
value: xmlValue,
}
}
return { name, type: 'unknown', value: xmiValue }
return { name, type: 'unknown', value: xmlValue }
}

function mapValue(value: string): Value {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`xmi-parser > should parse 1`] = `
exports[`xml-parser > should parse 1`] = `
"<xmi:XMI xmlns:mofext="http://www.omg.org/spec/MOF/20131001" xmlns:uml="http://www.omg.org/spec/UML/20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001">
<uml:Package URI="http://www.omg.org/spec/XMI/20131001" name="XMI" xmi:id="_XMI" xmi:type="Package">
<packagedElement name="Delete" xmi:id="_XMI-Delete" xmi:type="Class">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'node:fs'
import { Metamodel } from '@cm2ml/ir'
import { describe, expect, it } from 'vitest'

import { createXmiParser } from '../src/index'
import { createXMLParser } from '../src/index'

const metamodel = new Metamodel({
attributes: ['id', 'type'],
Expand All @@ -13,11 +13,11 @@ const metamodel = new Metamodel({
tags: [],
})

describe('xmi-parser', () => {
describe('xml-parser', () => {
it('should parse', () => {
const input = fs.readFileSync(`${import.meta.dirname}/../../../../models/xmi-model.xmi`, 'utf-8')
const xmiParser = createXmiParser(metamodel, () => { })
const output = xmiParser.validateAndInvoke(input, {
const xmlParser = createXMLParser(metamodel, () => { })
const output = xmlParser.validateAndInvoke(input, {
debug: false,
strict: true,
})
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/languages/archimate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@cm2ml/metamodel-refiner": "workspace:*",
"@cm2ml/plugin": "workspace:*",
"@cm2ml/utils": "workspace:*",
"@cm2ml/xmi-parser": "workspace:*"
"@cm2ml/xml-parser": "workspace:*"
},
"devDependencies": {
"@cm2ml/tsconfig": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/languages/archimate/src/archimate-parser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { GraphModel, GraphNode } from '@cm2ml/ir'
import { createRefiner } from '@cm2ml/metamodel-refiner'
import { compose, definePlugin } from '@cm2ml/plugin'
import { createXmiParser } from '@cm2ml/xmi-parser'
import { createXMLParser } from '@cm2ml/xml-parser'

import { isArchiFormat, restructureArchiXml } from './formats/archi-format'
import { isOpenGroupFormat, restructureOpenGroupXml } from './formats/opengroup-format'
Expand Down Expand Up @@ -118,7 +118,7 @@ function handleTextNode(node: GraphNode, textContent: string) {
}

export const ArchimateParser = compose(
createXmiParser(Archimate, handleTextNode),
createXMLParser(Archimate, handleTextNode),
ArchimateRefiner,
// compose(ArchimateRefiner, IrPostProcessor),
'archimate',
Expand Down
2 changes: 1 addition & 1 deletion packages/languages/ecore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@cm2ml/metamodel-refiner": "workspace:*",
"@cm2ml/plugin": "workspace:*",
"@cm2ml/utils": "workspace:*",
"@cm2ml/xmi-parser": "workspace:*",
"@cm2ml/xml-parser": "workspace:*",
"@yeger/streams": "1.2.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/languages/ecore/src/ecore-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { GraphModel } from '@cm2ml/ir'
import { IrPostProcessor } from '@cm2ml/ir-post-processor'
import { createRefiner } from '@cm2ml/metamodel-refiner'
import { compose, definePlugin } from '@cm2ml/plugin'
import { createXmiParser } from '@cm2ml/xmi-parser'
import { createXMLParser } from '@cm2ml/xml-parser'

import { Ecore } from './metamodel/ecore'
import { inferEcoreHandler } from './metamodel/ecore-handler-registry'
Expand All @@ -22,7 +22,7 @@ const EcoreRefiner = definePlugin({
})

export const EcoreParser = compose(
createXmiParser(Ecore, () => { }),
createXMLParser(Ecore, () => { }),
compose(EcoreRefiner, IrPostProcessor),
'ecore',
)
2 changes: 1 addition & 1 deletion packages/languages/uml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@cm2ml/metamodel-refiner": "workspace:*",
"@cm2ml/plugin": "workspace:*",
"@cm2ml/utils": "workspace:*",
"@cm2ml/xmi-parser": "workspace:*",
"@cm2ml/xml-parser": "workspace:*",
"@yeger/streams": "1.2.2",
"nanoid": "5.0.7"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/languages/uml/src/uml-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GraphNode } from '@cm2ml/ir'
import { IrPostProcessor } from '@cm2ml/ir-post-processor'
import { createRefiner } from '@cm2ml/metamodel-refiner'
import { compose, definePlugin } from '@cm2ml/plugin'
import { createXmiParser } from '@cm2ml/xmi-parser'
import { createXMLParser } from '@cm2ml/xml-parser'
import { nanoid } from 'nanoid'

import { resolveDeployedElements } from './metamodel/resolvers/deployedElements'
Expand Down Expand Up @@ -273,7 +273,7 @@ function handleTextNode(node: GraphNode, text: string) {
}

export const UmlParser = compose(
createXmiParser(Uml, handleTextNode),
createXMLParser(Uml, handleTextNode),
compose(UmlRefiner, IrPostProcessor),
'uml',
)
22 changes: 11 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7827c6d

Please sign in to comment.