Skip to content

Commit

Permalink
[lang] Exhibit a SARL expression interpreter.
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 Jun 17, 2020
1 parent 3972b03 commit b9af9a5
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 16 deletions.
2 changes: 1 addition & 1 deletion formatting-styles/gtk/sarl.lang
Expand Up @@ -24,7 +24,7 @@
limitations under the License.
-->
<!-- Style for SARL 0.11 -->
<!-- Style for SARL 0.12 -->

<language id="sarl" _name="SARL" version="2.0" _section="Source">
<metadata>
Expand Down
4 changes: 2 additions & 2 deletions formatting-styles/latex/sarl-beamer-listing.sty
Expand Up @@ -22,7 +22,7 @@
% limitations under the License.
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{sarl-beamer-listing}[2020/02/18]
\ProvidesPackage{sarl-beamer-listing}[2020/06/16]
\newif\ifusesarlcolors\usesarlcolorstrue
\DeclareOption{sarlcolors}{\global\usesarlcolorstrue}
\DeclareOption{nosarlcolors}{\global\usesarlcolorsfalse}
Expand Down Expand Up @@ -76,7 +76,7 @@
}
\newcommand{\code}[1]{\ifmmode\text{\lstinline[basicstyle=\usebeamertemplate{code inline style}]{#1}}\else\lstinline[basicstyle=\usebeamertemplate{code inline style}]{#1}\fi}
\newcommand{\sarl}{\mbox{SARL}\xspace}
\newcommand{\sarlversion}{0.11}
\newcommand{\sarlversion}{0.12}
\ifusesarlcolors
\setbeamercolor*{code keyword}{fg=SARLkeyword}
\setbeamercolor*{code string}{fg=SARLstring}
Expand Down
4 changes: 2 additions & 2 deletions formatting-styles/latex/sarl-colorized-listing.sty
Expand Up @@ -22,7 +22,7 @@
% limitations under the License.
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{sarl-colorized-listing}[2020/02/18]
\ProvidesPackage{sarl-colorized-listing}[2020/06/16]
\newif\ifusesarlcolors\usesarlcolorstrue
\DeclareOption{sarlcolors}{\global\usesarlcolorstrue}
\DeclareOption{nosarlcolors}{\global\usesarlcolorsfalse}
Expand Down Expand Up @@ -81,5 +81,5 @@
}
\newcommand{\code}[1]{\ifmmode\text{\lstinline[basicstyle=\normalcolor]{#1}}\else\lstinline[basicstyle=\normalcolor]{#1}\fi}
\newcommand{\sarl}{\mbox{SARL}\xspace}
\newcommand{\sarlversion}{0.11}
\newcommand{\sarlversion}{0.12}
\endinput
4 changes: 2 additions & 2 deletions formatting-styles/latex/sarl-listing.sty
Expand Up @@ -22,7 +22,7 @@
% limitations under the License.
%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{sarl-listing}[2020/02/18]
\ProvidesPackage{sarl-listing}[2020/06/16]
\RequirePackage{algpseudocode}
\RequirePackage{listings}
\RequirePackage{xspace}
Expand Down Expand Up @@ -63,5 +63,5 @@
}
\newcommand{\code}[1]{\ifmmode\text{\lstinline[basicstyle={}]{#1}}\else\lstinline[basicstyle={}]{#1}\fi}
\newcommand{\sarl}{\mbox{SARL}\xspace}
\newcommand{\sarlversion}{0.11}
\newcommand{\sarlversion}{0.12}
\endinput
2 changes: 1 addition & 1 deletion formatting-styles/prettify/lang-sarl.js
Expand Up @@ -23,7 +23,7 @@
* limitations under the License.
*
*/
/* Style for SARL 0.11 */
/* Style for SARL 0.12 */

PR['registerLangHandler'](
PR['createSimpleLexer'](
Expand Down
2 changes: 1 addition & 1 deletion formatting-styles/pygments/sarllexer/__init__.py
Expand Up @@ -22,7 +22,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Style for SARL 0.11
# Style for SARL 0.12


__all__ = [ ]
4 changes: 2 additions & 2 deletions formatting-styles/pygments/sarllexer/sarl.py
Expand Up @@ -22,7 +22,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Style for SARL 0.11
# Style for SARL 0.12


import re
Expand All @@ -34,7 +34,7 @@ class SarlLexer(RegexLexer):
"""
For `SARL <http://www.sarl.io>`_ source code.
.. versionadded:: 0.11
.. versionadded:: 0.12
"""

name = 'SARL'
Expand Down
4 changes: 2 additions & 2 deletions formatting-styles/pygments/setup.py
Expand Up @@ -22,14 +22,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Style for SARL 0.11
# Style for SARL 0.12


from setuptools import setup

setup (
name='sarl.pylexer',
version='0.11',
version='0.12',
packages=['sarl.pylexer'],
entry_points =
"""
Expand Down
2 changes: 1 addition & 1 deletion formatting-styles/source-highlight/sarl.lang
Expand Up @@ -21,7 +21,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Style for SARL 0.11
# Style for SARL 0.12

preproc = "import","package"

Expand Down
2 changes: 1 addition & 1 deletion formatting-styles/vim/ftdetect/sarl.vim
@@ -1,5 +1,5 @@
" Vim filetype-detection file
" Language: SARL
" Version: 0.11
" Version: 0.12

au BufRead,BufNewFile *.sarl set filetype=sarl
2 changes: 1 addition & 1 deletion formatting-styles/vim/syntax/sarl.vim
@@ -1,6 +1,6 @@
" Vim syntax file
" Language: SARL
" Version: 0.11
" Version: 0.12
"
" $Id$
"
Expand Down
Expand Up @@ -627,6 +627,10 @@ Workflow {
singleton = true
eager = true
}
runtime = {
bind = "org.eclipse.xtext.xbase.interpreter.IExpressionInterpreter"
to = "io.sarl.lang.interpreter.SarlExpressionInterpreter"
}

ui = {
bind = "io.sarl.lang.extralanguage.IExtraLanguageContributions"
Expand Down
1 change: 1 addition & 0 deletions main/coreplugins/io.sarl.lang/META-INF/MANIFEST.MF
Expand Up @@ -37,6 +37,7 @@ Export-Package: io.sarl.lang,
io.sarl.lang.extralanguage.compiler,
io.sarl.lang.extralanguage.validator,
io.sarl.lang.formatting2,
io.sarl.lang.interpreter,
io.sarl.lang.jvmmodel,
io.sarl.lang.macro,
io.sarl.lang.parser.antlr,
Expand Down
Expand Up @@ -93,6 +93,7 @@
import io.sarl.lang.extralanguage.validator.IExtraLanguageValidatorProvider;
import io.sarl.lang.formatting2.SARLFormatter;
import io.sarl.lang.formatting2.SARLFormatterPreferenceKeys;
import io.sarl.lang.interpreter.SarlExpressionInterpreter;
import io.sarl.lang.jvmmodel.SARLJvmModelInferrer;
import io.sarl.lang.jvmmodel.SARLReadAndWriteTracking;
import io.sarl.lang.jvmmodel.SarlJvmModelAssociations;
Expand Down Expand Up @@ -233,6 +234,7 @@
import org.eclipse.xtext.xbase.imports.IImportsConfiguration;
import org.eclipse.xtext.xbase.imports.ImportedTypesCollector;
import org.eclipse.xtext.xbase.imports.TypeUsageCollector;
import org.eclipse.xtext.xbase.interpreter.IExpressionInterpreter;
import org.eclipse.xtext.xbase.jvmmodel.IJvmModelInferrer;
import org.eclipse.xtext.xbase.jvmmodel.JvmModelAssociator;
import org.eclipse.xtext.xbase.jvmmodel.JvmModelTargetURICollector;
Expand Down Expand Up @@ -673,6 +675,11 @@ public Class<? extends ImplicitlyImportedFeatures> bindImplicitlyImportedFeature
return SARLImplicitlyImportedFeatures.class;
}

// contributed by io.sarl.lang.mwe2.binding.InjectionFragment2 [Bindings provided by SARL API]
public Class<? extends IExpressionInterpreter> bindIExpressionInterpreter() {
return SarlExpressionInterpreter.class;
}

// contributed by io.sarl.lang.mwe2.binding.InjectionFragment2 [Bindings provided by SARL API]
@SingletonBinding
public Class<? extends SyntaxErrorMessageProvider> bindSyntaxErrorMessageProvider() {
Expand Down
@@ -0,0 +1,75 @@
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2020 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.interpreter;

import java.util.function.UnaryOperator;

import com.google.inject.Provider;
import org.eclipse.xtext.common.types.util.JavaReflectAccess;
import org.eclipse.xtext.xbase.interpreter.IEvaluationContext;
import org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter;

/** Interpreter of SARL expressions (not SARL declaration types).
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.12
*/
public class SarlExpressionInterpreter extends XbaseInterpreter {

private ClassLoader classLoader;

/** Injection constructor.
*/
public SarlExpressionInterpreter() {
//
}

/** Constructor.
*
* @param contextProvider the provider of evaluation context.
* @param javaReflectAccess the accessor to the Java types.
* @param loader the class loader to be used.
*/
public SarlExpressionInterpreter(Provider<IEvaluationContext> contextProvider, JavaReflectAccess javaReflectAccess,
ClassLoader loader) {
super(contextProvider, javaReflectAccess, loader);
}

@Override
public void setClassLoader(ClassLoader classLoader) {
super.setClassLoader(classLoader);
this.classLoader = classLoader;
}

/** Expand the current class loader with the class loader that is build with the given operator.
* The interpreter's class loader is the result of the given builder to which the current class loader is provided.
*
* @param builder the class loader builder.
*/
public void expandClassLoader(UnaryOperator<ClassLoader> builder) {
super.setClassLoader(builder.apply(this.classLoader));
}

}

0 comments on commit b9af9a5

Please sign in to comment.