Skip to content

Commit

Permalink
Merging preliminary results from the 'jnario_replacement' branch.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Apr 22, 2017
2 parents fc6abde + bf6b110 commit b1c406d
Show file tree
Hide file tree
Showing 15 changed files with 536 additions and 117 deletions.
5 changes: 5 additions & 0 deletions formatting-styles/pygments/.gitignore
@@ -0,0 +1,5 @@
# Ignore the Python binary files
*.egg-info
build
dist
**/*.pyc
28 changes: 28 additions & 0 deletions formatting-styles/pygments/sarllexer/__init__.py
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
#
# $Id$
#
# File is automatically generated by the Xtext language generator.
# Do not change it.
#
# SARL is an general-purpose agent programming language.
# More details on http://www.sarl.io
#
# Copyright (C) 2014-2017 the original authors or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Style for SARL 0.6


__all__ = [ ]
Expand Up @@ -27,10 +27,8 @@

import re

from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, this, combined, default, words
from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, this
from pygments.token import Text, Comment, Operator, Keyword, Name, String, Number, Punctuation
from pygments.util import shebang_matches
from pygments import unistring as uni

class SarlLexer(RegexLexer):
"""
Expand Down
39 changes: 39 additions & 0 deletions formatting-styles/pygments/setup.py
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
#
# $Id$
#
# File is automatically generated by the Xtext language generator.
# Do not change it.
#
# SARL is an general-purpose agent programming language.
# More details on http://www.sarl.io
#
# Copyright (C) 2014-2017 the original authors or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Style for SARL 0.6


from setuptools import setup

setup (
name='sarl.pylexer',
version='0.6',
packages=['sarl.pylexer'],
entry_points =
"""
[pygments.lexers]
sarllexer = sarl.pylexer.sarl.py:SarlLexer
""",
)
Expand Up @@ -86,3 +86,18 @@ interface SarlSpecificationChecker {
}

}


/** Check if a given agent class follows a specific version of the SARL specifications.
*
* <p>This implementation uses the default implementation given by the interface.
*
* @author $Author: ssgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.5
*/
final class StandardSarlSpecificationChecker implements SarlSpecificationChecker {
//
}
Expand Up @@ -148,6 +148,22 @@ public static <K, V> V operator_remove(Map<K, V> map, K key) {
return map.remove(key);
}

/** Remove the given pair into the map.
*
* <p>If the given key is inside the map, but is not mapped to the given value, the
* map will not be changed.
*
* @param <K> - type of the map keys.
* @param <V> - type of the map values.
* @param map - the map to update.
* @param entry - the entry (key, value) to remove from the map.
* @return {@code true} if the pair was removed.
*/
@Inline(value = "$1.remove($2.getKey(), $2.getValue())", statementExpression = true)
public static <K, V> boolean operator_remove(Map<K, V> map, Pair<? extends K, ? extends V> entry) {
return map.remove(entry.getKey(), entry.getValue());
}

/** Remove pairs with the given keys from the map.
*
*
Expand All @@ -162,6 +178,25 @@ public static <K, V> void operator_remove(Map<K, V> map, Iterable<? super K> key
}
}

/** Remove the given pair from a given map for obtaining a new map.
*
* <p>The replied map is a view on the given map. It means that any change
* in the original map is reflected to the result of this operation.
*
* @param <K> - type of the map keys.
* @param <V> - type of the map values.
* @param left - the map to consider.
* @param right - the entry (key, value) to remove from the map.
* @return an immutable map with the content of the map and with the given entry.
* @throws IllegalArgumentException - when the right operand key exists in the left operand.
*/
@Pure
@Inline(value = "SARLMapExtensions.operator_minus($1, $2.getKey())",
imported = { SARLMapExtensions.class, Collections.class })
public static <K, V> Map<K, V> operator_minus(Map<K, V> left, final Pair<? extends K, ? extends V> right) {
return operator_minus(left, right.getKey());
}

/** Replies the elements of the given map except the pair with the given key.
*
* <p>The replied map is a view on the given map. It means that any change
Expand Down Expand Up @@ -200,7 +235,7 @@ public boolean apply(K input) {
* @return the map with the content of the left map except the pairs of the right map.
*/
@Pure
@Inline(value = "SARLMapExtensions.operator_minus(left, right.keySet())", imported = SARLMapExtensions.class)
@Inline(value = "SARLMapExtensions.operator_minus($0, $1.keySet())", imported = SARLMapExtensions.class)
public static <K, V> Map<K, V> operator_minus(Map<K, V> left, Map<? extends K, ? extends V> right) {
return operator_minus(left, right.keySet());
}
Expand Down
2 changes: 1 addition & 1 deletion main/coreplugins/io.sarl.lang.mwe2/GenerateSARL2.mwe2
Expand Up @@ -60,8 +60,8 @@ var prettifyToolPath = "${externalToolPath}/prettify"
var latexToolPath = "${externalToolPath}/latex"
var gtkToolPath = "${externalToolPath}/gtk"
var srchighlightToolPath = "${externalToolPath}/source-highlight"
var pygmentsToolPath = "${externalToolPath}/pygments"
var webjsPath = "${overallRootPath}/main/externalmaven/io.sarl.maven.docs.generator/src/main/resources/org/jnario/doc/js"
var pygmentsToolPath = "${externalToolPath}/pygments/sarllexer"

var file.extensions = "sarl"
var languageWebsite = "http://www.sarl.io"
Expand Down
Expand Up @@ -51,6 +51,7 @@
import org.eclipse.xtext.common.types.access.impl.Primitives;
import org.eclipse.xtext.util.Strings;
import org.eclipse.xtext.xbase.compiler.AbstractStringBuilderBasedAppendable;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xtext.generator.AbstractXtextGeneratorFragment;
import org.eclipse.xtext.xtext.generator.CodeConfig;
Expand Down Expand Up @@ -416,6 +417,7 @@ protected final void generate(Set<String> literals, Set<String> expressionKeywor
final String language = getLanguageSimpleName().toLowerCase();
final String basename = getBasename(MessageFormat.format(getBasenameTemplate(), language));
writeFile(basename, appendable);
generateAdditionalFiles(basename);
}

/** Generate the external specification.
Expand All @@ -436,18 +438,39 @@ protected abstract void generate(T appendable,
Set<String> literals, Set<String> expressionKeywords, Set<String> modifiers, Set<String> primitiveTypes,
Set<String> punctuation, Set<String> ignored, Set<String> specialKeywords, Set<String> typeDeclarationKeywords);

/** Generate additional files.
*
* @param basename the basename for the language style.
*/
protected void generateAdditionalFiles(String basename) {
//
}

/** Write the given lines into the file.
*
* @param basename the basename of the file.
* @param content the content of the style file.
*/
protected void writeFile(String basename, T content) {
writeFile(basename, content, null);
}

/** Write the given lines into the file.
*
* @param basename the basename of the file.
* @param content the content of the style file.
* @param filter the output directory.
*/
protected void writeFile(String basename, T content, Function1<File, File> filter) {
// Create the file.
// Encode
final byte[] bytes = content.toString().getBytes(Charset.forName(getCodeConfig().getEncoding()));

for (final String output : getOutputs()) {
final File directory = new File(output).getAbsoluteFile();
File directory = new File(output).getAbsoluteFile();
if (filter != null) {
directory = filter.apply(directory);
}
try {
directory.mkdirs();
final File outputFile = new File(directory, basename);
Expand Down
Expand Up @@ -85,10 +85,8 @@ protected void generate(IStyleAppendable it, Set<String> literals, Set<String> e
it.newLine();
it.appendNl("import re"); //$NON-NLS-1$
it.newLine();
it.appendNl("from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, this, combined, default, words"); //$NON-NLS-1$
it.appendNl("from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, this"); //$NON-NLS-1$
it.appendNl("from pygments.token import Text, Comment, Operator, Keyword, Name, String, Number, Punctuation"); //$NON-NLS-1$
it.appendNl("from pygments.util import shebang_matches"); //$NON-NLS-1$
it.appendNl("from pygments import unistring as uni"); //$NON-NLS-1$
it.newLine();
it.appendNl("class SarlLexer(RegexLexer):"); //$NON-NLS-1$
it.appendNl("\t\"\"\""); //$NON-NLS-1$
Expand Down Expand Up @@ -235,5 +233,65 @@ protected void generate(IStyleAppendable it, Set<String> literals, Set<String> e
it.newLine();
}

@Override
protected void generateAdditionalFiles(String basename) {
IStyleAppendable appendable;

appendable = newStyleAppendable();
generatePythonPackage(appendable, basename);
writeFile("__init__.py", appendable); //$NON-NLS-1$

appendable = newStyleAppendable();
generatePythonSetup(appendable, basename);
writeFile("setup.py", appendable, (it) -> it.getParentFile()); //$NON-NLS-1$
}

/** Create the content of the "setup.py" file.
*
* @param it the content.
* @param basename the basename.
*/
protected void generatePythonSetup(IStyleAppendable it, String basename) {
it.appendNl("# -*- coding: {0} -*-", getCodeConfig().getEncoding().toLowerCase()); //$NON-NLS-1$
it.appendHeader();
it.newLine();
it.append("from setuptools import setup"); //$NON-NLS-1$
it.newLine().newLine();
it.append("setup ("); //$NON-NLS-1$
it.increaseIndentation().newLine();
it.append("name='").append(basename).append("lexer',"); //$NON-NLS-1$ //$NON-NLS-2$
it.newLine();
it.append("version='").append(getLanguageVersion()).append("',"); //$NON-NLS-1$ //$NON-NLS-2$
it.newLine();
it.append("packages=['").append(basename).append("lexer'],"); //$NON-NLS-1$ //$NON-NLS-2$
it.newLine();
it.append("entry_points ="); //$NON-NLS-1$
it.newLine();
it.append("\"\"\""); //$NON-NLS-1$
it.newLine();
it.append("[pygments.lexers]"); //$NON-NLS-1$
it.newLine();
it.append("sarllexer = ").append(basename).append("lexer.").append(basename); //$NON-NLS-1$ //$NON-NLS-2$
it.append(":SarlLexer"); //$NON-NLS-1$
it.newLine();
it.append("\"\"\","); //$NON-NLS-1$
it.decreaseIndentation().newLine();
it.append(")"); //$NON-NLS-1$
it.newLine();
}

/** Create the content of the "__init__.py" file.
*
* @param it the content.
* @param basename the basename.
*/
protected void generatePythonPackage(IStyleAppendable it, String basename) {
it.appendNl("# -*- coding: {0} -*-", getCodeConfig().getEncoding().toLowerCase()); //$NON-NLS-1$
it.appendHeader();
it.newLine();
it.append("__all__ = [ ]"); //$NON-NLS-1$
it.newLine();
}

}

@@ -0,0 +1,42 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2017 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sarl.lang.compiler.batch;

import org.eclipse.emf.ecore.resource.Resource;

/** An object that expects to receive the Ecore objects from the compiled resources.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.6
*/
public interface ICompilatedResourceReceiver {

/** The resource was successfully compiled.
*
* @param resource the compiled resource.
*/
void receiveCompiledResource(Resource resource);

}

0 comments on commit b1c406d

Please sign in to comment.